1c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville/*
2c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Copyright (C) 2006 The Android Open Source Project
3c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville *
4c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Licensed under the Apache License, Version 2.0 (the "License");
5c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * you may not use this file except in compliance with the License.
6c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * You may obtain a copy of the License at
7c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville *
8c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville *      http://www.apache.org/licenses/LICENSE-2.0
9c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville *
10c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * Unless required by applicable law or agreed to in writing, software
11c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * distributed under the License is distributed on an "AS IS" BASIS,
12c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * See the License for the specific language governing permissions and
14c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * limitations under the License.
15c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville */
16c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
17c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savillepackage com.android.internal.telephony;
18c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
19277a5a2aae73ef0233fffc350f3829aee779899fJeff Davidsonimport android.annotation.Nullable;
2033ab7bad1f2ccb5dea26d0def6e43a4f2d1b9cb9David Braunimport android.content.ComponentName;
21c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savilleimport android.content.Context;
227a9b640ed1ef153a9df46ba6959a49b6a85a643eshuoqimport android.content.SharedPreferences;
23277a5a2aae73ef0233fffc350f3829aee779899fJeff Davidsonimport android.content.pm.PackageManager;
24c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savilleimport android.net.LocalServerSocket;
256bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwaltimport android.os.Looper;
267a477263108748903cf5a4151a4e8b739f12264aRobert Greenwaltimport android.os.ServiceManager;
277a9b640ed1ef153a9df46ba6959a49b6a85a643eshuoqimport android.preference.PreferenceManager;
28c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savilleimport android.provider.Settings;
29a8467dd0c524787104b1ccdddc5e8af10ba729edWink Savilleimport android.provider.Settings.SettingNotFoundException;
3099c2e1d6749cfad2a8ca94a47857d8c3bfc09454Wink Savilleimport android.telephony.Rlog;
31a8467dd0c524787104b1ccdddc5e8af10ba729edWink Savilleimport android.telephony.SubscriptionManager;
32c67761d00a25bd095364e3ff4e4cb8e88b2e974cDavid Braunimport android.telephony.TelephonyManager;
33265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwaltimport android.util.LocalLog;
3433ab7bad1f2ccb5dea26d0def6e43a4f2d1b9cb9David Braun
35dce529f00c52bedf4377ee5f7ae1b284fe6452beJeff Davidsonimport com.android.internal.os.BackgroundThread;
36c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savilleimport com.android.internal.telephony.cdma.CdmaSubscriptionSourceManager;
37e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwaltimport com.android.internal.telephony.dataconnection.TelephonyNetworkFactory;
38277a5a2aae73ef0233fffc350f3829aee779899fJeff Davidsonimport com.android.internal.telephony.euicc.EuiccController;
395470a3b34b58cd7a5ce0bde9820b2f5f64bc5820Brad Ebingerimport com.android.internal.telephony.ims.ImsResolver;
40888c60a7fe1c8f3612ab8e8ec5f2f7ca8f24e766Etan Cohenimport com.android.internal.telephony.imsphone.ImsPhone;
416f5e6b5b4374d834734894d687dea58724b6c0b0Naveen Kallaimport com.android.internal.telephony.imsphone.ImsPhoneFactory;
42c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savilleimport com.android.internal.telephony.sip.SipPhone;
43c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savilleimport com.android.internal.telephony.sip.SipPhoneFactory;
44e97be3971cb6b55e019433c32524cc60ce0d037bWink Savilleimport com.android.internal.telephony.uicc.IccCardProxy;
45e287feac673ff68565b766e0e463d105fa9cef9dAlex Yakavenkaimport com.android.internal.telephony.uicc.UiccController;
467c29cabeb38ae8cb4f5764c2dc0a768de22d2f92fionaxuimport com.android.internal.telephony.util.NotificationChannelController;
47265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwaltimport com.android.internal.util.IndentingPrintWriter;
48c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
49e97be3971cb6b55e019433c32524cc60ce0d037bWink Savilleimport java.io.FileDescriptor;
50e97be3971cb6b55e019433c32524cc60ce0d037bWink Savilleimport java.io.PrintWriter;
51265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwaltimport java.util.HashMap;
527a9b640ed1ef153a9df46ba6959a49b6a85a643eshuoqimport java.util.Map;
53e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville
54c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville/**
55c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville * {@hide}
56c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville */
57c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Savillepublic class PhoneFactory {
58cbaa45bbf2cab852b6c9c3a887e9f803d4e857eaWink Saville    static final String LOG_TAG = "PhoneFactory";
59c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    static final int SOCKET_OPEN_RETRY_MILLIS = 2 * 1000;
60c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    static final int SOCKET_OPEN_MAX_RETRY = 3;
619232dafa7ea833fc0b3a6024d6c7e23fc8e961eaRobert Greenwalt    static final boolean DBG = false;
62c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
63c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    //***** Class Variables
64c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
651a87ab3d7170d618f048c4f5af8c7504a587aaa5Jack Yu    // lock sLockProxyPhones protects both sPhones and sPhone
666f5e6b5b4374d834734894d687dea58724b6c0b0Naveen Kalla    final static Object sLockProxyPhones = new Object();
671a87ab3d7170d618f048c4f5af8c7504a587aaa5Jack Yu    static private Phone[] sPhones = null;
681a87ab3d7170d618f048c4f5af8c7504a587aaa5Jack Yu    static private Phone sPhone = null;
696f5e6b5b4374d834734894d687dea58724b6c0b0Naveen Kalla
70a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    static private CommandsInterface[] sCommandsInterfaces = null;
71a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
72e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    static private ProxyController sProxyController;
73e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    static private UiccController sUiccController;
74d1d2aa157fa5047507393405b76dfb49fc9ffc0fAmit Mahajan    private static IntentBroadcaster sIntentBroadcaster;
75277a5a2aae73ef0233fffc350f3829aee779899fJeff Davidson    private static @Nullable EuiccController sEuiccController;
76a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
77c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    static private CommandsInterface sCommandsInterface = null;
78299dad50409e907993fa96c7401d4f10c58018b1Wink Saville    static private SubscriptionInfoUpdater sSubInfoRecordUpdater = null;
79c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
80c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    static private boolean sMadeDefaults = false;
81c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    static private PhoneNotifier sPhoneNotifier;
82c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    static private Context sContext;
83e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    static private PhoneSwitcher sPhoneSwitcher;
849521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt    static private SubscriptionMonitor sSubscriptionMonitor;
85e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt    static private TelephonyNetworkFactory[] sTelephonyNetworkFactories;
865470a3b34b58cd7a5ce0bde9820b2f5f64bc5820Brad Ebinger    static private ImsResolver sImsResolver;
877c29cabeb38ae8cb4f5764c2dc0a768de22d2f92fionaxu    static private NotificationChannelController sNotificationChannelController;
88c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
89265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt    static private final HashMap<String, LocalLog>sLocalLogs = new HashMap<String, LocalLog>();
90265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt
916bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt    // TODO - make this a dynamic property read from the modem
926bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt    public static final int MAX_ACTIVE_PHONES = 1;
936bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt
94c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    //***** Class Methods
95c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
96c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public static void makeDefaultPhones(Context context) {
97c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        makeDefaultPhone(context);
98c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
99c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
100c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
101c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * FIXME replace this with some other way of making these
102c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * instances
103c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
104c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public static void makeDefaultPhone(Context context) {
1056f5e6b5b4374d834734894d687dea58724b6c0b0Naveen Kalla        synchronized (sLockProxyPhones) {
106c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            if (!sMadeDefaults) {
107c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                sContext = context;
108a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville                // create the telephony device controller.
109a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville                TelephonyDevController.create();
110a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
111c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                int retryCount = 0;
112c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                for(;;) {
113c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    boolean hasException = false;
114c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    retryCount ++;
115c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
116c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    try {
117c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                        // use UNIX domain socket to
118c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                        // prevent subsequent initialization
119c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                        new LocalServerSocket("com.android.internal.telephony");
120c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    } catch (java.io.IOException ex) {
121c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                        hasException = true;
122c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    }
123c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
124c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    if ( !hasException ) {
125c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                        break;
126c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    } else if (retryCount > SOCKET_OPEN_MAX_RETRY) {
127c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                        throw new RuntimeException("PhoneFactory probably already running");
128c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    } else {
129c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                        try {
130c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                            Thread.sleep(SOCKET_OPEN_RETRY_MILLIS);
131c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                        } catch (InterruptedException er) {
132c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                        }
133c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    }
134c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                }
135c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
136c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                sPhoneNotifier = new DefaultPhoneNotifier();
137c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
1385ceae6074e0729fbbc422db2f263bf7cf453bf1aNaveen Kalla                int cdmaSubscription = CdmaSubscriptionSourceManager.getDefault(context);
13999c2e1d6749cfad2a8ca94a47857d8c3bfc09454Wink Saville                Rlog.i(LOG_TAG, "Cdma Subscription set to " + cdmaSubscription);
140c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
141277a5a2aae73ef0233fffc350f3829aee779899fJeff Davidson                if (context.getPackageManager().hasSystemFeature(
142277a5a2aae73ef0233fffc350f3829aee779899fJeff Davidson                        PackageManager.FEATURE_TELEPHONY_EUICC)) {
143277a5a2aae73ef0233fffc350f3829aee779899fJeff Davidson                    sEuiccController = EuiccController.init(context);
144277a5a2aae73ef0233fffc350f3829aee779899fJeff Davidson                }
145277a5a2aae73ef0233fffc350f3829aee779899fJeff Davidson
1461a87ab3d7170d618f048c4f5af8c7504a587aaa5Jack Yu                /* In case of multi SIM mode two instances of Phone, RIL are created,
147a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville                   where as in single SIM mode only instance. isMultiSimEnabled() function checks
148a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville                   whether it is single SIM or multi SIM mode */
149a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville                int numPhones = TelephonyManager.getDefault().getPhoneCount();
1507152d901c51e288759259ae3e482bb5fe1c23173Brad Ebinger                // Start ImsResolver and bind to ImsServices.
1517152d901c51e288759259ae3e482bb5fe1c23173Brad Ebinger                String defaultImsPackage = sContext.getResources().getString(
1527152d901c51e288759259ae3e482bb5fe1c23173Brad Ebinger                        com.android.internal.R.string.config_ims_package);
1537152d901c51e288759259ae3e482bb5fe1c23173Brad Ebinger                Rlog.i(LOG_TAG, "ImsResolver: defaultImsPackage: " + defaultImsPackage);
1547152d901c51e288759259ae3e482bb5fe1c23173Brad Ebinger                sImsResolver = new ImsResolver(sContext, defaultImsPackage, numPhones);
1557152d901c51e288759259ae3e482bb5fe1c23173Brad Ebinger                sImsResolver.populateCacheAndStartBind();
1567152d901c51e288759259ae3e482bb5fe1c23173Brad Ebinger
157a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville                int[] networkModes = new int[numPhones];
1581a87ab3d7170d618f048c4f5af8c7504a587aaa5Jack Yu                sPhones = new Phone[numPhones];
159a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville                sCommandsInterfaces = new RIL[numPhones];
160e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                sTelephonyNetworkFactories = new TelephonyNetworkFactory[numPhones];
161a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
162a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville                for (int i = 0; i < numPhones; i++) {
1633bc32aa4a3f533421f82a6d7991bb1971bf78191Amit Mahajan                    // reads the system properties and makes commandsinterface
1643bc32aa4a3f533421f82a6d7991bb1971bf78191Amit Mahajan                    // Get preferred network type.
1653bc32aa4a3f533421f82a6d7991bb1971bf78191Amit Mahajan                    networkModes[i] = RILConstants.PREFERRED_NETWORK_MODE;
166a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
167a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville                    Rlog.i(LOG_TAG, "Network Mode set to " + Integer.toString(networkModes[i]));
168a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville                    sCommandsInterfaces[i] = new RIL(context, networkModes[i],
169a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville                            cdmaSubscription, i);
170a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville                }
171a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville                Rlog.i(LOG_TAG, "Creating SubscriptionController");
172a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville                SubscriptionController.init(context, sCommandsInterfaces);
173a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
174a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville                // Instantiate UiccController so that all other classes can just
175a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville                // call getInstance()
176e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                sUiccController = UiccController.make(context, sCommandsInterfaces);
177a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
178a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville                for (int i = 0; i < numPhones; i++) {
1791a87ab3d7170d618f048c4f5af8c7504a587aaa5Jack Yu                    Phone phone = null;
180a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville                    int phoneType = TelephonyManager.getPhoneType(networkModes[i]);
181a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville                    if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
1820f7d1220e8584c7f227e6c6c0be0e26d1c6b7de1Amit Mahajan                        phone = new GsmCdmaPhone(context,
1831a87ab3d7170d618f048c4f5af8c7504a587aaa5Jack Yu                                sCommandsInterfaces[i], sPhoneNotifier, i,
1840a567c9ed954f295df83c753239646c6f6a04128Amit Mahajan                                PhoneConstants.PHONE_TYPE_GSM,
1850a567c9ed954f295df83c753239646c6f6a04128Amit Mahajan                                TelephonyComponentFactory.getInstance());
186a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville                    } else if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
1870f7d1220e8584c7f227e6c6c0be0e26d1c6b7de1Amit Mahajan                        phone = new GsmCdmaPhone(context,
1881a87ab3d7170d618f048c4f5af8c7504a587aaa5Jack Yu                                sCommandsInterfaces[i], sPhoneNotifier, i,
1890a567c9ed954f295df83c753239646c6f6a04128Amit Mahajan                                PhoneConstants.PHONE_TYPE_CDMA_LTE,
1900a567c9ed954f295df83c753239646c6f6a04128Amit Mahajan                                TelephonyComponentFactory.getInstance());
191c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                    }
192a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville                    Rlog.i(LOG_TAG, "Creating Phone with type = " + phoneType + " sub = " + i);
193a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
1941a87ab3d7170d618f048c4f5af8c7504a587aaa5Jack Yu                    sPhones[i] = phone;
195c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                }
196a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
1976bc4098827f3070a44b5e51508b455d7c7be9c07Wink Saville                // Set the default phone in base class.
1986bc4098827f3070a44b5e51508b455d7c7be9c07Wink Saville                // FIXME: This is a first best guess at what the defaults will be. It
1996bc4098827f3070a44b5e51508b455d7c7be9c07Wink Saville                // FIXME: needs to be done in a more controlled manner in the future.
2001a87ab3d7170d618f048c4f5af8c7504a587aaa5Jack Yu                sPhone = sPhones[0];
2016bc4098827f3070a44b5e51508b455d7c7be9c07Wink Saville                sCommandsInterface = sCommandsInterfaces[0];
202c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
20333ab7bad1f2ccb5dea26d0def6e43a4f2d1b9cb9David Braun                // Ensure that we have a default SMS app. Requesting the app with
20433ab7bad1f2ccb5dea26d0def6e43a4f2d1b9cb9David Braun                // updateIfNeeded set to true is enough to configure a default SMS app.
20533ab7bad1f2ccb5dea26d0def6e43a4f2d1b9cb9David Braun                ComponentName componentName =
20633ab7bad1f2ccb5dea26d0def6e43a4f2d1b9cb9David Braun                        SmsApplication.getDefaultSmsApplication(context, true /* updateIfNeeded */);
20733ab7bad1f2ccb5dea26d0def6e43a4f2d1b9cb9David Braun                String packageName = "NONE";
20833ab7bad1f2ccb5dea26d0def6e43a4f2d1b9cb9David Braun                if (componentName != null) {
20933ab7bad1f2ccb5dea26d0def6e43a4f2d1b9cb9David Braun                    packageName = componentName.getPackageName();
21033ab7bad1f2ccb5dea26d0def6e43a4f2d1b9cb9David Braun                }
21133ab7bad1f2ccb5dea26d0def6e43a4f2d1b9cb9David Braun                Rlog.i(LOG_TAG, "defaultSmsApplication: " + packageName);
21233ab7bad1f2ccb5dea26d0def6e43a4f2d1b9cb9David Braun
2138a4c72815186db4187587d4fc62125540a0e42a8David Braun                // Set up monitor to watch for changes to SMS packages
2148a4c72815186db4187587d4fc62125540a0e42a8David Braun                SmsApplication.initSmsPackageMonitor(context);
2158a4c72815186db4187587d4fc62125540a0e42a8David Braun
216c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville                sMadeDefaults = true;
217a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
218a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville                Rlog.i(LOG_TAG, "Creating SubInfoRecordUpdater ");
219dce529f00c52bedf4377ee5f7ae1b284fe6452beJeff Davidson                sSubInfoRecordUpdater = new SubscriptionInfoUpdater(
220dce529f00c52bedf4377ee5f7ae1b284fe6452beJeff Davidson                        BackgroundThread.get().getLooper(), context, sPhones, sCommandsInterfaces);
2211a87ab3d7170d618f048c4f5af8c7504a587aaa5Jack Yu                SubscriptionController.getInstance().updatePhonesAvailability(sPhones);
22280bd0262e4bb6dbbaf6d03dadb771ad105186e15Pavel Zhamaitsiak
22380bd0262e4bb6dbbaf6d03dadb771ad105186e15Pavel Zhamaitsiak                // Start monitoring after defaults have been made.
2247152d901c51e288759259ae3e482bb5fe1c23173Brad Ebinger                // Default phone must be ready before ImsPhone is created because ImsService might
2257152d901c51e288759259ae3e482bb5fe1c23173Brad Ebinger                // need it when it is being opened. This should initialize multiple ImsPhones for
2267152d901c51e288759259ae3e482bb5fe1c23173Brad Ebinger                // ImsResolver implementations of ImsService.
22780bd0262e4bb6dbbaf6d03dadb771ad105186e15Pavel Zhamaitsiak                for (int i = 0; i < numPhones; i++) {
2281a87ab3d7170d618f048c4f5af8c7504a587aaa5Jack Yu                    sPhones[i].startMonitoringImsService();
22980bd0262e4bb6dbbaf6d03dadb771ad105186e15Pavel Zhamaitsiak                }
2307a477263108748903cf5a4151a4e8b739f12264aRobert Greenwalt
2316bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt                ITelephonyRegistry tr = ITelephonyRegistry.Stub.asInterface(
2326bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt                        ServiceManager.getService("telephony.registry"));
2336bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt                SubscriptionController sc = SubscriptionController.getInstance();
2346bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt
2359521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt                sSubscriptionMonitor = new SubscriptionMonitor(tr, sContext, sc, numPhones);
2366bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt
23785953e2a7e5bc75cf1f5353feee97b3993dad5b3Robert Greenwalt                sPhoneSwitcher = new PhoneSwitcher(MAX_ACTIVE_PHONES, numPhones,
23885953e2a7e5bc75cf1f5353feee97b3993dad5b3Robert Greenwalt                        sContext, sc, Looper.myLooper(), tr, sCommandsInterfaces,
23985953e2a7e5bc75cf1f5353feee97b3993dad5b3Robert Greenwalt                        sPhones);
240e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
241e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                sProxyController = ProxyController.getInstance(context, sPhones,
242e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt                        sUiccController, sCommandsInterfaces, sPhoneSwitcher);
243e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
244d1d2aa157fa5047507393405b76dfb49fc9ffc0fAmit Mahajan                sIntentBroadcaster = IntentBroadcaster.getInstance(context);
245d1d2aa157fa5047507393405b76dfb49fc9ffc0fAmit Mahajan
2467c29cabeb38ae8cb4f5764c2dc0a768de22d2f92fionaxu                sNotificationChannelController = new NotificationChannelController(context);
2477c29cabeb38ae8cb4f5764c2dc0a768de22d2f92fionaxu
24885953e2a7e5bc75cf1f5353feee97b3993dad5b3Robert Greenwalt                sTelephonyNetworkFactories = new TelephonyNetworkFactory[numPhones];
24985953e2a7e5bc75cf1f5353feee97b3993dad5b3Robert Greenwalt                for (int i = 0; i < numPhones; i++) {
25085953e2a7e5bc75cf1f5353feee97b3993dad5b3Robert Greenwalt                    sTelephonyNetworkFactories[i] = new TelephonyNetworkFactory(
2519521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt                            sPhoneSwitcher, sc, sSubscriptionMonitor, Looper.myLooper(),
25285953e2a7e5bc75cf1f5353feee97b3993dad5b3Robert Greenwalt                            sContext, i, sPhones[i].mDcTracker);
25385953e2a7e5bc75cf1f5353feee97b3993dad5b3Robert Greenwalt                }
254c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville            }
255c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
256c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
257c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
258c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public static Phone getDefaultPhone() {
2596f5e6b5b4374d834734894d687dea58724b6c0b0Naveen Kalla        synchronized (sLockProxyPhones) {
2606f5e6b5b4374d834734894d687dea58724b6c0b0Naveen Kalla            if (!sMadeDefaults) {
2616f5e6b5b4374d834734894d687dea58724b6c0b0Naveen Kalla                throw new IllegalStateException("Default phones haven't been made yet!");
2626f5e6b5b4374d834734894d687dea58724b6c0b0Naveen Kalla            }
2631a87ab3d7170d618f048c4f5af8c7504a587aaa5Jack Yu            return sPhone;
264c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        }
265c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
266c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville
267a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    public static Phone getPhone(int phoneId) {
2686f5e6b5b4374d834734894d687dea58724b6c0b0Naveen Kalla        Phone phone;
269652c1add01ea5f0c93aa60c262863147d3aeefc2Wink Saville        String dbgInfo = "";
270652c1add01ea5f0c93aa60c262863147d3aeefc2Wink Saville
2716f5e6b5b4374d834734894d687dea58724b6c0b0Naveen Kalla        synchronized (sLockProxyPhones) {
2726f5e6b5b4374d834734894d687dea58724b6c0b0Naveen Kalla            if (!sMadeDefaults) {
2736f5e6b5b4374d834734894d687dea58724b6c0b0Naveen Kalla                throw new IllegalStateException("Default phones haven't been made yet!");
2746f5e6b5b4374d834734894d687dea58724b6c0b0Naveen Kalla                // CAF_MSIM FIXME need to introduce default phone id ?
2754b09dff383ae7dfca595aeeea886a594a1947340Wink Saville            } else if (phoneId == SubscriptionManager.DEFAULT_PHONE_INDEX) {
2761a87ab3d7170d618f048c4f5af8c7504a587aaa5Jack Yu                if (DBG) dbgInfo = "phoneId == DEFAULT_PHONE_ID return sPhone";
2771a87ab3d7170d618f048c4f5af8c7504a587aaa5Jack Yu                phone = sPhone;
2786f5e6b5b4374d834734894d687dea58724b6c0b0Naveen Kalla            } else {
2791a87ab3d7170d618f048c4f5af8c7504a587aaa5Jack Yu                if (DBG) dbgInfo = "phoneId != DEFAULT_PHONE_ID return sPhones[phoneId]";
2806bc4098827f3070a44b5e51508b455d7c7be9c07Wink Saville                phone = (((phoneId >= 0)
2816bc4098827f3070a44b5e51508b455d7c7be9c07Wink Saville                                && (phoneId < TelephonyManager.getDefault().getPhoneCount()))
2821a87ab3d7170d618f048c4f5af8c7504a587aaa5Jack Yu                        ? sPhones[phoneId] : null);
2836f5e6b5b4374d834734894d687dea58724b6c0b0Naveen Kalla            }
2849232dafa7ea833fc0b3a6024d6c7e23fc8e961eaRobert Greenwalt            if (DBG) {
2859232dafa7ea833fc0b3a6024d6c7e23fc8e961eaRobert Greenwalt                Rlog.d(LOG_TAG, "getPhone:- " + dbgInfo + " phoneId=" + phoneId +
2869232dafa7ea833fc0b3a6024d6c7e23fc8e961eaRobert Greenwalt                        " phone=" + phone);
2879232dafa7ea833fc0b3a6024d6c7e23fc8e961eaRobert Greenwalt            }
2886f5e6b5b4374d834734894d687dea58724b6c0b0Naveen Kalla            return phone;
289a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville        }
290a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    }
291a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
2926f5e6b5b4374d834734894d687dea58724b6c0b0Naveen Kalla    public static Phone[] getPhones() {
2936f5e6b5b4374d834734894d687dea58724b6c0b0Naveen Kalla        synchronized (sLockProxyPhones) {
2946f5e6b5b4374d834734894d687dea58724b6c0b0Naveen Kalla            if (!sMadeDefaults) {
2956f5e6b5b4374d834734894d687dea58724b6c0b0Naveen Kalla                throw new IllegalStateException("Default phones haven't been made yet!");
2966f5e6b5b4374d834734894d687dea58724b6c0b0Naveen Kalla            }
2971a87ab3d7170d618f048c4f5af8c7504a587aaa5Jack Yu            return sPhones;
298a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville        }
299a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    }
300a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
3015470a3b34b58cd7a5ce0bde9820b2f5f64bc5820Brad Ebinger    public static ImsResolver getImsResolver() {
3025470a3b34b58cd7a5ce0bde9820b2f5f64bc5820Brad Ebinger        return sImsResolver;
3035470a3b34b58cd7a5ce0bde9820b2f5f64bc5820Brad Ebinger    }
3045470a3b34b58cd7a5ce0bde9820b2f5f64bc5820Brad Ebinger
305c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    /**
306c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * Makes a {@link SipPhone} object.
307c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @param sipUri the local SIP URI the phone runs on
308c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     * @return the {@code SipPhone} object or null if the SIP URI is not valid
309c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville     */
310c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    public static SipPhone makeSipPhone(String sipUri) {
311c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville        return SipPhoneFactory.makePhone(sipUri, sContext, sPhoneNotifier);
312c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville    }
313b25da36f791607b5fc9a68ae01dd8c5ea1d5652cShishir Agrawal
314b25da36f791607b5fc9a68ae01dd8c5ea1d5652cShishir Agrawal    /**
315b25da36f791607b5fc9a68ae01dd8c5ea1d5652cShishir Agrawal     * Returns the preferred network type that should be set in the modem.
316b25da36f791607b5fc9a68ae01dd8c5ea1d5652cShishir Agrawal     *
317b25da36f791607b5fc9a68ae01dd8c5ea1d5652cShishir Agrawal     * @param context The current {@link Context}.
318b25da36f791607b5fc9a68ae01dd8c5ea1d5652cShishir Agrawal     * @return the preferred network mode that should be set.
319b25da36f791607b5fc9a68ae01dd8c5ea1d5652cShishir Agrawal     */
320a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    // TODO: Fix when we "properly" have TelephonyDevController/SubscriptionController ..
3213bc32aa4a3f533421f82a6d7991bb1971bf78191Amit Mahajan    public static int calculatePreferredNetworkType(Context context, int phoneSubId) {
3223bc32aa4a3f533421f82a6d7991bb1971bf78191Amit Mahajan        int networkType = android.provider.Settings.Global.getInt(context.getContentResolver(),
3233bc32aa4a3f533421f82a6d7991bb1971bf78191Amit Mahajan                android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId,
3243bc32aa4a3f533421f82a6d7991bb1971bf78191Amit Mahajan                RILConstants.PREFERRED_NETWORK_MODE);
3253bc32aa4a3f533421f82a6d7991bb1971bf78191Amit Mahajan        Rlog.d(LOG_TAG, "calculatePreferredNetworkType: phoneSubId = " + phoneSubId +
3263bc32aa4a3f533421f82a6d7991bb1971bf78191Amit Mahajan                " networkType = " + networkType);
327b25da36f791607b5fc9a68ae01dd8c5ea1d5652cShishir Agrawal        return networkType;
328b25da36f791607b5fc9a68ae01dd8c5ea1d5652cShishir Agrawal    }
329a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
330a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    /* Gets the default subscription */
331b237a11044ed842d2865ff8c8716befb06b6ca25Wink Saville    public static int getDefaultSubscription() {
332a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville        return SubscriptionController.getInstance().getDefaultSubId();
333a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    }
334a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
335a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    /* Returns User SMS Prompt property,  enabled or not */
336a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    public static boolean isSMSPromptEnabled() {
337a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville        boolean prompt = false;
338a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville        int value = 0;
339a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville        try {
340a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville            value = Settings.Global.getInt(sContext.getContentResolver(),
341a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville                    Settings.Global.MULTI_SIM_SMS_PROMPT);
342a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville        } catch (SettingNotFoundException snfe) {
343a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville            Rlog.e(LOG_TAG, "Settings Exception Reading Dual Sim SMS Prompt Values");
344a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville        }
345a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville        prompt = (value == 0) ? false : true ;
346a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville        Rlog.d(LOG_TAG, "SMS Prompt option:" + prompt);
347a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
348a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville       return prompt;
349a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    }
350a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
351a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    /**
352a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville     * Makes a {@link ImsPhone} object.
353a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville     * @return the {@code ImsPhone} object or null if the exception occured
354a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville     */
355c2b66d57e16623dffc2fe6d02ded4f24c014b6c8Amit Mahajan    public static Phone makeImsPhone(PhoneNotifier phoneNotifier, Phone defaultPhone) {
356a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville        return ImsPhoneFactory.makePhone(sContext, phoneNotifier, defaultPhone);
357a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    }
358e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville
359d728841b17b19ab8268a426051f51f64a6913142Jeff Davidson    /**
360d728841b17b19ab8268a426051f51f64a6913142Jeff Davidson     * Request a refresh of the embedded subscription list.
361d728841b17b19ab8268a426051f51f64a6913142Jeff Davidson     *
362d728841b17b19ab8268a426051f51f64a6913142Jeff Davidson     * @param callback Optional callback to execute after the refresh completes. Must terminate
363d728841b17b19ab8268a426051f51f64a6913142Jeff Davidson     *     quickly as it will be called from SubscriptionInfoUpdater's handler thread.
364d728841b17b19ab8268a426051f51f64a6913142Jeff Davidson     */
365d728841b17b19ab8268a426051f51f64a6913142Jeff Davidson    public static void requestEmbeddedSubscriptionInfoListRefresh(@Nullable Runnable callback) {
366d728841b17b19ab8268a426051f51f64a6913142Jeff Davidson        sSubInfoRecordUpdater.requestEmbeddedSubscriptionInfoListRefresh(callback);
367dce529f00c52bedf4377ee5f7ae1b284fe6452beJeff Davidson    }
368dce529f00c52bedf4377ee5f7ae1b284fe6452beJeff Davidson
369265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt    /**
370265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt     * Adds a local log category.
371265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt     *
372265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt     * Only used within the telephony process.  Use localLog to add log entries.
373265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt     *
374265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt     * TODO - is there a better way to do this?  Think about design when we have a minute.
375265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt     *
376265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt     * @param key the name of the category - will be the header in the service dump.
377265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt     * @param size the number of lines to maintain in this category
378265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt     */
379265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt    public static void addLocalLog(String key, int size) {
380265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt        synchronized(sLocalLogs) {
381265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt            if (sLocalLogs.containsKey(key)) {
382265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt                throw new IllegalArgumentException("key " + key + " already present");
383265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt            }
384265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt            sLocalLogs.put(key, new LocalLog(size));
385265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt        }
386265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt    }
387265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt
388265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt    /**
389265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt     * Add a line to the named Local Log.
390265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt     *
391265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt     * This will appear in the TelephonyDebugService dump.
392265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt     *
393265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt     * @param key the name of the log category to put this in.  Must be created
394265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt     *            via addLocalLog.
395265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt     * @param log the string to add to the log.
396265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt     */
397265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt    public static void localLog(String key, String log) {
398265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt        synchronized(sLocalLogs) {
399265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt            if (sLocalLogs.containsKey(key) == false) {
400265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt                throw new IllegalArgumentException("key " + key + " not found");
401265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt            }
402265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt            sLocalLogs.get(key).log(log);
403265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt        }
404265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt    }
405265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt
4069521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt    public static void dump(FileDescriptor fd, PrintWriter printwriter, String[] args) {
4079521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt        IndentingPrintWriter pw = new IndentingPrintWriter(printwriter, "  ");
408e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville        pw.println("PhoneFactory:");
409dc3b93d59312b84dcfa776f7691f6a87462b45a2Jack Yu        pw.println(" sMadeDefaults=" + sMadeDefaults);
4106bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt
41185953e2a7e5bc75cf1f5353feee97b3993dad5b3Robert Greenwalt        sPhoneSwitcher.dump(fd, pw, args);
41285953e2a7e5bc75cf1f5353feee97b3993dad5b3Robert Greenwalt        pw.println();
4136bfc71d2b5340f6274b3e63926a7068e364fc9ffRobert Greenwalt
4141a87ab3d7170d618f048c4f5af8c7504a587aaa5Jack Yu        Phone[] phones = (Phone[])PhoneFactory.getPhones();
415e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt        for (int i = 0; i < phones.length; i++) {
4169521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt            pw.increaseIndent();
417e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            Phone phone = phones[i];
418e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville
419e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville            try {
4201a87ab3d7170d618f048c4f5af8c7504a587aaa5Jack Yu                phone.dump(fd, pw, args);
421e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville            } catch (Exception e) {
422e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville                pw.println("Telephony DebugService: Could not get Phone[" + i + "] e=" + e);
423e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville                continue;
424e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville            }
425e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville
426e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville            pw.flush();
427e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville            pw.println("++++++++++++++++++++++++++++++++");
428e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville
429e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            sTelephonyNetworkFactories[i].dump(fd, pw, args);
430e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
431e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            pw.flush();
432e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            pw.println("++++++++++++++++++++++++++++++++");
433e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt
434e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville            try {
4351a87ab3d7170d618f048c4f5af8c7504a587aaa5Jack Yu                ((IccCardProxy)phone.getIccCard()).dump(fd, pw, args);
436e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville            } catch (Exception e) {
437e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville                e.printStackTrace();
438e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville            }
439e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville            pw.flush();
4409521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt            pw.decreaseIndent();
441e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville            pw.println("++++++++++++++++++++++++++++++++");
442e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville        }
443e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville
4449521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt        pw.println("SubscriptionMonitor:");
4459521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt        pw.increaseIndent();
4469521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt        try {
4479521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt            sSubscriptionMonitor.dump(fd, pw, args);
4489521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt        } catch (Exception e) {
4499521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt            e.printStackTrace();
4509521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt        }
4519521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt        pw.decreaseIndent();
4529521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt        pw.println("++++++++++++++++++++++++++++++++");
4539521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt
4549521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt        pw.println("UiccController:");
4559521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt        pw.increaseIndent();
456e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville        try {
457e9bf1f44cc6a888fff8419c8f35612d503ba3216Robert Greenwalt            sUiccController.dump(fd, pw, args);
458e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville        } catch (Exception e) {
459e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville            e.printStackTrace();
460e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville        }
461e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville        pw.flush();
4629521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt        pw.decreaseIndent();
463e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville        pw.println("++++++++++++++++++++++++++++++++");
464e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville
465277a5a2aae73ef0233fffc350f3829aee779899fJeff Davidson        if (sEuiccController != null) {
466277a5a2aae73ef0233fffc350f3829aee779899fJeff Davidson            pw.println("EuiccController:");
467277a5a2aae73ef0233fffc350f3829aee779899fJeff Davidson            pw.increaseIndent();
468277a5a2aae73ef0233fffc350f3829aee779899fJeff Davidson            try {
469277a5a2aae73ef0233fffc350f3829aee779899fJeff Davidson                sEuiccController.dump(fd, pw, args);
470277a5a2aae73ef0233fffc350f3829aee779899fJeff Davidson            } catch (Exception e) {
471277a5a2aae73ef0233fffc350f3829aee779899fJeff Davidson                e.printStackTrace();
472277a5a2aae73ef0233fffc350f3829aee779899fJeff Davidson            }
473277a5a2aae73ef0233fffc350f3829aee779899fJeff Davidson            pw.flush();
474277a5a2aae73ef0233fffc350f3829aee779899fJeff Davidson            pw.decreaseIndent();
475277a5a2aae73ef0233fffc350f3829aee779899fJeff Davidson            pw.println("++++++++++++++++++++++++++++++++");
476277a5a2aae73ef0233fffc350f3829aee779899fJeff Davidson        }
477277a5a2aae73ef0233fffc350f3829aee779899fJeff Davidson
4789521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt        pw.println("SubscriptionController:");
4799521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt        pw.increaseIndent();
480e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville        try {
481e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville            SubscriptionController.getInstance().dump(fd, pw, args);
482e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville        } catch (Exception e) {
483e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville            e.printStackTrace();
484e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville        }
485e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville        pw.flush();
4869521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt        pw.decreaseIndent();
4874a3d736dbf0b8262290d3720085779538ceaad72Zach Johnson        pw.println("++++++++++++++++++++++++++++++++");
4884a3d736dbf0b8262290d3720085779538ceaad72Zach Johnson
4899521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt        pw.println("SubInfoRecordUpdater:");
4909521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt        pw.increaseIndent();
4914a3d736dbf0b8262290d3720085779538ceaad72Zach Johnson        try {
4924a3d736dbf0b8262290d3720085779538ceaad72Zach Johnson            sSubInfoRecordUpdater.dump(fd, pw, args);
4934a3d736dbf0b8262290d3720085779538ceaad72Zach Johnson        } catch (Exception e) {
4944a3d736dbf0b8262290d3720085779538ceaad72Zach Johnson            e.printStackTrace();
4954a3d736dbf0b8262290d3720085779538ceaad72Zach Johnson        }
4964a3d736dbf0b8262290d3720085779538ceaad72Zach Johnson        pw.flush();
4979521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt        pw.decreaseIndent();
498265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt        pw.println("++++++++++++++++++++++++++++++++");
4999521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt
5009521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt        pw.println("LocalLogs:");
5019521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt        pw.increaseIndent();
502265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt        synchronized (sLocalLogs) {
503265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt            for (String key : sLocalLogs.keySet()) {
5049521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt                pw.println(key);
5059521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt                pw.increaseIndent();
5069521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt                sLocalLogs.get(key).dump(fd, pw, args);
5079521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt                pw.decreaseIndent();
508265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt            }
5099521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt            pw.flush();
510265445ed9ade6b904a3b4bfaf03cf346230e86e3Robert Greenwalt        }
5119521f8c043c167e3a3fa97ea50bf1e2e0cd188a1Robert Greenwalt        pw.decreaseIndent();
5127a9b640ed1ef153a9df46ba6959a49b6a85a643eshuoq        pw.println("++++++++++++++++++++++++++++++++");
5137a9b640ed1ef153a9df46ba6959a49b6a85a643eshuoq
5147a9b640ed1ef153a9df46ba6959a49b6a85a643eshuoq        pw.println("SharedPreferences:");
5157a9b640ed1ef153a9df46ba6959a49b6a85a643eshuoq        pw.increaseIndent();
5167a9b640ed1ef153a9df46ba6959a49b6a85a643eshuoq        try {
5177a9b640ed1ef153a9df46ba6959a49b6a85a643eshuoq            if (sContext != null) {
5187a9b640ed1ef153a9df46ba6959a49b6a85a643eshuoq                SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(sContext);
5197a9b640ed1ef153a9df46ba6959a49b6a85a643eshuoq                Map spValues = sp.getAll();
5207a9b640ed1ef153a9df46ba6959a49b6a85a643eshuoq                for (Object key : spValues.keySet()) {
5217a9b640ed1ef153a9df46ba6959a49b6a85a643eshuoq                    pw.println(key + " : " + spValues.get(key));
5227a9b640ed1ef153a9df46ba6959a49b6a85a643eshuoq                }
5237a9b640ed1ef153a9df46ba6959a49b6a85a643eshuoq            }
5247a9b640ed1ef153a9df46ba6959a49b6a85a643eshuoq        } catch (Exception e) {
5257a9b640ed1ef153a9df46ba6959a49b6a85a643eshuoq            e.printStackTrace();
5267a9b640ed1ef153a9df46ba6959a49b6a85a643eshuoq        }
5277a9b640ed1ef153a9df46ba6959a49b6a85a643eshuoq        pw.flush();
5287a9b640ed1ef153a9df46ba6959a49b6a85a643eshuoq        pw.decreaseIndent();
529e97be3971cb6b55e019433c32524cc60ce0d037bWink Saville    }
530c38bb60d867c5d61d90b7179a9ed2b2d1848124fWink Saville}
531