17a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt/* 27a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt* Copyright (C) 2015 The Android Open Source Project 37a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt* 47a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt* Licensed under the Apache License, Version 2.0 (the "License"); 57a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt* you may not use this file except in compliance with the License. 67a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt* You may obtain a copy of the License at 77a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt* 87a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt* http://www.apache.org/licenses/LICENSE-2.0 97a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt* 107a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt* Unless required by applicable law or agreed to in writing, software 117a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt* distributed under the License is distributed on an "AS IS" BASIS, 127a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 137a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt* See the License for the specific language governing permissions and 147a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt* limitations under the License. 157a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt*/ 167a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 177a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltpackage com.android.internal.telephony; 187a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 197a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport static android.telephony.SubscriptionManager.INVALID_PHONE_INDEX; 207a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID; 217a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 227a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport android.content.BroadcastReceiver; 237a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport android.content.Context; 247a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport android.content.Intent; 257a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport android.content.IntentFilter; 267a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport android.os.Handler; 277a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport android.os.Registrant; 287a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport android.os.RegistrantList; 297a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport android.os.RemoteException; 307a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport android.os.ServiceManager; 317a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport android.telephony.Rlog; 327a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport android.telephony.SubscriptionManager; 339521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwaltimport android.util.LocalLog; 347a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 35e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport com.android.internal.annotations.VisibleForTesting; 367a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport com.android.internal.telephony.ISub; 377a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport com.android.internal.telephony.IOnSubscriptionsChangedListener; 387a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport com.android.internal.telephony.ITelephonyRegistry; 397a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport com.android.internal.telephony.PhoneConstants; 407a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 419521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwaltimport java.io.FileDescriptor; 429521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwaltimport java.io.PrintWriter; 437a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport java.lang.IllegalArgumentException; 447a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 457a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt/** 467a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt * Utility singleton to monitor subscription changes and help people act on them. 477a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt * Uses Registrant model to post messages to handlers. 487a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt * 497a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt */ 507a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltpublic class SubscriptionMonitor { 517a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 527a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt private final RegistrantList mSubscriptionsChangedRegistrants[]; 537a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt private final RegistrantList mDefaultDataSubChangedRegistrants[]; 547a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 557a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt private final SubscriptionController mSubscriptionController; 567a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt private final Context mContext; 577a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 587a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt private final int mPhoneSubId[]; 597a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt private int mDefaultDataSubId; 607a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt private int mDefaultDataPhoneId; 617a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 627a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt private final Object mLock = new Object(); 637a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 647a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt private final static boolean VDBG = true; 657a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt private final static String LOG_TAG = "SubscriptionMonitor"; 667a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 679521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt private final static int MAX_LOGLINES = 100; 689521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt private final LocalLog mLocalLog = new LocalLog(MAX_LOGLINES); 699521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt 707a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt public SubscriptionMonitor(ITelephonyRegistry tr, Context context, 717a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt SubscriptionController subscriptionController, int numPhones) { 727a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt try { 737a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt tr.addOnSubscriptionsChangedListener("SubscriptionMonitor", 747a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt mSubscriptionsChangedListener); 757a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } catch (RemoteException e) { 767a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } 777a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 787a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt mSubscriptionController = subscriptionController; 797a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt mContext = context; 807a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 817a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt mSubscriptionsChangedRegistrants = new RegistrantList[numPhones]; 827a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt mDefaultDataSubChangedRegistrants = new RegistrantList[numPhones]; 837a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt mPhoneSubId = new int[numPhones]; 847a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 857a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt mDefaultDataSubId = mSubscriptionController.getDefaultDataSubId(); 867a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt mDefaultDataPhoneId = mSubscriptionController.getPhoneId(mDefaultDataSubId); 877a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 887a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt for (int phoneId = 0; phoneId < numPhones; phoneId++) { 897a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt mSubscriptionsChangedRegistrants[phoneId] = new RegistrantList(); 907a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt mDefaultDataSubChangedRegistrants[phoneId] = new RegistrantList(); 917a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt mPhoneSubId[phoneId] = mSubscriptionController.getSubIdUsingPhoneId(phoneId); 927a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } 937a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 947a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt mContext.registerReceiver(mDefaultDataSubscriptionChangedReceiver, 957a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt new IntentFilter(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)); 967a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } 977a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 98e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt @VisibleForTesting 99e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt public SubscriptionMonitor() { 100e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt mSubscriptionsChangedRegistrants = null; 101e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt mDefaultDataSubChangedRegistrants = null; 102e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt mSubscriptionController = null; 103e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt mContext = null; 104e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt mPhoneSubId = null; 105e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt } 106e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt 1077a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt private final IOnSubscriptionsChangedListener mSubscriptionsChangedListener = 1087a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt new IOnSubscriptionsChangedListener.Stub() { 1097a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt @Override 1107a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt public void onSubscriptionsChanged() { 1117a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt synchronized (mLock) { 1126899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt int newDefaultDataPhoneId = INVALID_PHONE_INDEX; 1137a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt for (int phoneId = 0; phoneId < mPhoneSubId.length; phoneId++) { 1147a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt final int newSubId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); 1157a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt final int oldSubId = mPhoneSubId[phoneId]; 1167a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt if (oldSubId != newSubId) { 1179521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt log("Phone[" + phoneId + "] subId changed " + oldSubId + "->" + 1189521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt newSubId + ", " + 1199521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt mSubscriptionsChangedRegistrants[phoneId].size() + " registrants"); 1207a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt mPhoneSubId[phoneId] = newSubId; 1217a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt mSubscriptionsChangedRegistrants[phoneId].notifyRegistrants(); 1227a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 1237a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt // if the default isn't set, just move along.. 1247a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt if (mDefaultDataSubId == INVALID_SUBSCRIPTION_ID) continue; 1257a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 1267a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt // check if this affects default data 1277a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt if (newSubId == mDefaultDataSubId || oldSubId == mDefaultDataSubId) { 1289521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt log("mDefaultDataSubId = " + mDefaultDataSubId + ", " + 1299521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt mDefaultDataSubChangedRegistrants[phoneId].size() + 1309521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt " registrants"); 1317a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt mDefaultDataSubChangedRegistrants[phoneId].notifyRegistrants(); 1327a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } 1337a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } 1346899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt if (newSubId == mDefaultDataSubId) { 1356899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt newDefaultDataPhoneId = phoneId; 1366899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt } 1377a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } 1386899928dded685d401dcd010132fb9fc30ce3745Robert Greenwalt mDefaultDataPhoneId = newDefaultDataPhoneId; 1397a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } 1407a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } 1417a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt }; 1427a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 1437a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt private final BroadcastReceiver mDefaultDataSubscriptionChangedReceiver = 1447a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt new BroadcastReceiver() { 1457a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt @Override 1467a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt public void onReceive(Context context, Intent intent) { 1477a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt final int newDefaultDataSubId = mSubscriptionController.getDefaultDataSubId(); 1487a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt synchronized (mLock) { 1497a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt if (mDefaultDataSubId != newDefaultDataSubId) { 1509521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt log("Default changed " + mDefaultDataSubId + "->" + newDefaultDataSubId); 1517a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt final int oldDefaultDataSubId = mDefaultDataSubId; 1527a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt final int oldDefaultDataPhoneId = mDefaultDataPhoneId; 1537a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt mDefaultDataSubId = newDefaultDataSubId; 1547a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 1557a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt int newDefaultDataPhoneId = 1567a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt mSubscriptionController.getPhoneId(INVALID_SUBSCRIPTION_ID); 1577a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt if (newDefaultDataSubId != INVALID_SUBSCRIPTION_ID) { 1587a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt for (int phoneId = 0; phoneId < mPhoneSubId.length; phoneId++) { 1597a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt if (mPhoneSubId[phoneId] == newDefaultDataSubId) { 1607a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt newDefaultDataPhoneId = phoneId; 1617a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt if (VDBG) log("newDefaultDataPhoneId=" + newDefaultDataPhoneId); 1627a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt break; 1637a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } 1647a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } 1657a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } 1667a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt if (newDefaultDataPhoneId != oldDefaultDataPhoneId) { 1679521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt log("Default phoneId changed " + oldDefaultDataPhoneId + "->" + 1689521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt newDefaultDataPhoneId + ", " + 1699521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt (invalidPhoneId(oldDefaultDataPhoneId) ? 1709521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt 0 : 1719521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt mDefaultDataSubChangedRegistrants[oldDefaultDataPhoneId].size()) + 1729521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt "," + (invalidPhoneId(newDefaultDataPhoneId) ? 1739521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt 0 : 1749521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt mDefaultDataSubChangedRegistrants[newDefaultDataPhoneId].size()) + 1759521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt " registrants"); 1767a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt mDefaultDataPhoneId = newDefaultDataPhoneId; 1777a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt if (!invalidPhoneId(oldDefaultDataPhoneId)) { 1787a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt mDefaultDataSubChangedRegistrants[oldDefaultDataPhoneId]. 1797a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt notifyRegistrants(); 1807a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } 1817a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt if (!invalidPhoneId(newDefaultDataPhoneId)) { 1827a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt mDefaultDataSubChangedRegistrants[newDefaultDataPhoneId]. 1837a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt notifyRegistrants(); 1847a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } 1857a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } 1867a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } 1877a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } 1887a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } 1897a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt }; 1907a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 1917a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt public void registerForSubscriptionChanged(int phoneId, Handler h, int what, Object o) { 1927a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt if (invalidPhoneId(phoneId)) { 1937a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt throw new IllegalArgumentException("Invalid PhoneId"); 1947a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } 1957a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt Registrant r = new Registrant(h, what, o); 1967a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt mSubscriptionsChangedRegistrants[phoneId].add(r); 1977a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt r.notifyRegistrant(); 1987a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } 1997a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 2007a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt public void unregisterForSubscriptionChanged(int phoneId, Handler h) { 2017a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt if (invalidPhoneId(phoneId)) { 2027a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt throw new IllegalArgumentException("Invalid PhoneId"); 2037a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } 2047a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt mSubscriptionsChangedRegistrants[phoneId].remove(h); 2057a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } 2067a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 2077a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt public void registerForDefaultDataSubscriptionChanged(int phoneId, Handler h, int what, 2087a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt Object o) { 2097a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt if (invalidPhoneId(phoneId)) { 2107a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt throw new IllegalArgumentException("Invalid PhoneId"); 2117a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } 2127a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt Registrant r = new Registrant(h, what, o); 2137a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt mDefaultDataSubChangedRegistrants[phoneId].add(r); 2147a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt r.notifyRegistrant(); 2157a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } 2167a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 2177a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt public void unregisterForDefaultDataSubscriptionChanged(int phoneId, Handler h) { 2187a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt if (invalidPhoneId(phoneId)) { 2197a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt throw new IllegalArgumentException("Invalid PhoneId"); 2207a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } 2217a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt mDefaultDataSubChangedRegistrants[phoneId].remove(h); 2227a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } 2237a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 2247a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt private boolean invalidPhoneId(int phoneId) { 2257a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt if (phoneId >= 0 && phoneId < mPhoneSubId.length) return false; 2267a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt return true; 2277a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } 2287a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt 2297a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt private void log(String s) { 2307a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt Rlog.d(LOG_TAG, s); 2319521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt mLocalLog.log(s); 2329521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt } 2339521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt 2349521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) { 2359521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt synchronized (mLock) { 2369521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt mLocalLog.dump(fd, printWriter, args); 2379521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt } 2387a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt } 2397a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt} 240