| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2006 The Android Open Source Project | 
 | 3 |  * | 
 | 4 |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
 | 5 |  * you may not use this file except in compliance with the License. | 
 | 6 |  * You may obtain a copy of the License at | 
 | 7 |  * | 
 | 8 |  *      http://www.apache.org/licenses/LICENSE-2.0 | 
 | 9 |  * | 
 | 10 |  * Unless required by applicable law or agreed to in writing, software | 
 | 11 |  * distributed under the License is distributed on an "AS IS" BASIS, | 
 | 12 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
 | 13 |  * See the License for the specific language governing permissions and | 
 | 14 |  * limitations under the License. | 
 | 15 |  */ | 
 | 16 |  | 
 | 17 | package com.android.phone; | 
 | 18 |  | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 19 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; | 
 | 20 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 21 | import android.app.ActivityManager; | 
 | 22 | import android.app.AppOpsManager; | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 23 | import android.content.ComponentName; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 24 | import android.content.Context; | 
 | 25 | import android.content.Intent; | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 26 | import android.content.SharedPreferences; | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 27 | import android.content.pm.PackageInfo; | 
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 28 | import android.content.pm.PackageManager; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 29 | import android.net.Uri; | 
 | 30 | import android.os.AsyncResult; | 
 | 31 | import android.os.Binder; | 
 | 32 | import android.os.Bundle; | 
 | 33 | import android.os.Handler; | 
 | 34 | import android.os.Looper; | 
 | 35 | import android.os.Message; | 
 | 36 | import android.os.Process; | 
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 37 | import android.os.ResultReceiver; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.os.ServiceManager; | 
 | 39 | import android.os.UserHandle; | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 40 | import android.os.UserManager; | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 41 | import android.os.WorkSource; | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 42 | import android.preference.PreferenceManager; | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 43 | import android.provider.Settings; | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 44 | import android.service.carrier.CarrierIdentifier; | 
| Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 45 | import android.telecom.PhoneAccount; | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 46 | import android.telecom.PhoneAccountHandle; | 
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 47 | import android.telecom.TelecomManager; | 
| Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 48 | import android.telephony.CarrierConfigManager; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 49 | import android.telephony.CellInfo; | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 50 | import android.telephony.ClientRequestStats; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 51 | import android.telephony.IccOpenLogicalChannelResponse; | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 52 | import android.telephony.ModemActivityInfo; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 53 | import android.telephony.NeighboringCellInfo; | 
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 54 | import android.telephony.RadioAccessFamily; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.telephony.ServiceState; | 
| Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 56 | import android.telephony.SubscriptionInfo; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 57 | import android.telephony.SubscriptionManager; | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 58 | import android.telephony.TelephonyHistogram; | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 59 | import android.telephony.TelephonyManager; | 
 | 60 | import android.telephony.VisualVoicemailSmsFilterSettings; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 61 | import android.text.TextUtils; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 62 | import android.util.ArraySet; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 63 | import android.util.Log; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 64 | import android.util.Pair; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 65 | import android.util.Slog; | 
| Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 66 | import com.android.ims.ImsManager; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 67 | import com.android.internal.telephony.CallManager; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 68 | import com.android.internal.telephony.CellNetworkScanResult; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 69 | import com.android.internal.telephony.CommandException; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 70 | import com.android.internal.telephony.DefaultPhoneNotifier; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 71 | import com.android.internal.telephony.ITelephony; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 72 | import com.android.internal.telephony.IccCard; | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 73 | import com.android.internal.telephony.MccTable; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 74 | import com.android.internal.telephony.OperatorInfo; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 75 | import com.android.internal.telephony.Phone; | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 76 | import com.android.internal.telephony.PhoneConstants; | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 77 | import com.android.internal.telephony.PhoneFactory; | 
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 78 | import com.android.internal.telephony.ProxyController; | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 79 | import com.android.internal.telephony.RIL; | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 80 | import com.android.internal.telephony.RILConstants; | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 81 | import com.android.internal.telephony.SubscriptionController; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 82 | import com.android.internal.telephony.uicc.IccIoResult; | 
 | 83 | import com.android.internal.telephony.uicc.IccUtils; | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 84 | import com.android.internal.telephony.uicc.UiccCard; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 85 | import com.android.internal.telephony.uicc.UiccController; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 86 | import com.android.internal.util.HexDump; | 
| Ta-wei Yen | b0f695b | 2016-08-08 17:33:11 -0700 | [diff] [blame] | 87 | import com.android.phone.settings.VisualVoicemailSettingsUtil; | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 88 | import com.android.phone.settings.VoicemailNotificationSettingsUtil; | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 89 | import java.io.FileDescriptor; | 
 | 90 | import java.io.PrintWriter; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 91 | import java.util.ArrayList; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 92 | import java.util.Arrays; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 93 | import java.util.List; | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 94 | import java.util.Locale; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 95 | import java.util.Map; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 96 |  | 
 | 97 | /** | 
 | 98 |  * Implementation of the ITelephony interface. | 
 | 99 |  */ | 
| Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 100 | public class PhoneInterfaceManager extends ITelephony.Stub { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 101 |     private static final String LOG_TAG = "PhoneInterfaceManager"; | 
 | 102 |     private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); | 
 | 103 |     private static final boolean DBG_LOC = false; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 104 |     private static final boolean DBG_MERGE = false; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 105 |  | 
 | 106 |     // Message codes used with mMainThreadHandler | 
 | 107 |     private static final int CMD_HANDLE_PIN_MMI = 1; | 
 | 108 |     private static final int CMD_HANDLE_NEIGHBORING_CELL = 2; | 
 | 109 |     private static final int EVENT_NEIGHBORING_CELL_DONE = 3; | 
 | 110 |     private static final int CMD_ANSWER_RINGING_CALL = 4; | 
 | 111 |     private static final int CMD_END_CALL = 5;  // not used yet | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 112 |     private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; | 
 | 113 |     private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 114 |     private static final int CMD_OPEN_CHANNEL = 9; | 
 | 115 |     private static final int EVENT_OPEN_CHANNEL_DONE = 10; | 
 | 116 |     private static final int CMD_CLOSE_CHANNEL = 11; | 
 | 117 |     private static final int EVENT_CLOSE_CHANNEL_DONE = 12; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 118 |     private static final int CMD_NV_READ_ITEM = 13; | 
 | 119 |     private static final int EVENT_NV_READ_ITEM_DONE = 14; | 
 | 120 |     private static final int CMD_NV_WRITE_ITEM = 15; | 
 | 121 |     private static final int EVENT_NV_WRITE_ITEM_DONE = 16; | 
 | 122 |     private static final int CMD_NV_WRITE_CDMA_PRL = 17; | 
 | 123 |     private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; | 
 | 124 |     private static final int CMD_NV_RESET_CONFIG = 19; | 
 | 125 |     private static final int EVENT_NV_RESET_CONFIG_DONE = 20; | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 126 |     private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; | 
 | 127 |     private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; | 
 | 128 |     private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; | 
 | 129 |     private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; | 
| Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 130 |     private static final int CMD_SEND_ENVELOPE = 25; | 
 | 131 |     private static final int EVENT_SEND_ENVELOPE_DONE = 26; | 
| Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 132 |     private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; | 
 | 133 |     private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; | 
 | 134 |     private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; | 
 | 135 |     private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; | 
 | 136 |     private static final int CMD_EXCHANGE_SIM_IO = 31; | 
 | 137 |     private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 138 |     private static final int CMD_SET_VOICEMAIL_NUMBER = 33; | 
 | 139 |     private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 140 |     private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; | 
 | 141 |     private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 142 |     private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; | 
 | 143 |     private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 144 |     private static final int CMD_PERFORM_NETWORK_SCAN = 39; | 
 | 145 |     private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; | 
 | 146 |     private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; | 
 | 147 |     private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 148 |     private static final int CMD_SET_ALLOWED_CARRIERS = 43; | 
 | 149 |     private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; | 
 | 150 |     private static final int CMD_GET_ALLOWED_CARRIERS = 45; | 
 | 151 |     private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; | 
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 152 |     private static final int CMD_HANDLE_USSD_REQUEST = 47; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 153 |  | 
 | 154 |     /** The singleton instance. */ | 
 | 155 |     private static PhoneInterfaceManager sInstance; | 
 | 156 |  | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 157 |     private PhoneGlobals mApp; | 
 | 158 |     private Phone mPhone; | 
 | 159 |     private CallManager mCM; | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 160 |     private UserManager mUserManager; | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 161 |     private AppOpsManager mAppOps; | 
 | 162 |     private MainThreadHandler mMainThreadHandler; | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 163 |     private SubscriptionController mSubscriptionController; | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 164 |     private SharedPreferences mTelephonySharedPreferences; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 165 |  | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 166 |     private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; | 
 | 167 |     private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 168 |     private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; | 
| Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 169 |  | 
 | 170 |     /** | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 171 |      * A request object to use for transmitting data to an ICC. | 
 | 172 |      */ | 
 | 173 |     private static final class IccAPDUArgument { | 
 | 174 |         public int channel, cla, command, p1, p2, p3; | 
 | 175 |         public String data; | 
 | 176 |  | 
 | 177 |         public IccAPDUArgument(int channel, int cla, int command, | 
 | 178 |                 int p1, int p2, int p3, String data) { | 
 | 179 |             this.channel = channel; | 
 | 180 |             this.cla = cla; | 
 | 181 |             this.command = command; | 
 | 182 |             this.p1 = p1; | 
 | 183 |             this.p2 = p2; | 
 | 184 |             this.p3 = p3; | 
 | 185 |             this.data = data; | 
 | 186 |         } | 
 | 187 |     } | 
 | 188 |  | 
 | 189 |     /** | 
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 190 |      * A request object to use for transmitting data to an ICC. | 
 | 191 |      */ | 
 | 192 |     private static final class ManualNetworkSelectionArgument { | 
 | 193 |         public OperatorInfo operatorInfo; | 
 | 194 |         public boolean persistSelection; | 
 | 195 |  | 
 | 196 |         public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { | 
 | 197 |             this.operatorInfo = operatorInfo; | 
 | 198 |             this.persistSelection = persistSelection; | 
 | 199 |         } | 
 | 200 |     } | 
 | 201 |  | 
 | 202 |     /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 203 |      * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the | 
 | 204 |      * request after sending. The main thread will notify the request when it is complete. | 
 | 205 |      */ | 
 | 206 |     private static final class MainThreadRequest { | 
 | 207 |         /** The argument to use for the request */ | 
 | 208 |         public Object argument; | 
 | 209 |         /** The result of the request that is run on the main thread */ | 
 | 210 |         public Object result; | 
| Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 211 |         // The subscriber id that this request applies to. Defaults to | 
 | 212 |         // SubscriptionManager.INVALID_SUBSCRIPTION_ID | 
 | 213 |         public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 214 |  | 
 | 215 |         public MainThreadRequest(Object argument) { | 
 | 216 |             this.argument = argument; | 
 | 217 |         } | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 218 |  | 
 | 219 |         public MainThreadRequest(Object argument, Integer subId) { | 
 | 220 |             this.argument = argument; | 
| Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 221 |             if (subId != null) { | 
 | 222 |                 this.subId = subId; | 
 | 223 |             } | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 224 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 225 |     } | 
 | 226 |  | 
| Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 227 |     private static final class IncomingThirdPartyCallArgs { | 
 | 228 |         public final ComponentName component; | 
 | 229 |         public final String callId; | 
 | 230 |         public final String callerDisplayName; | 
 | 231 |  | 
 | 232 |         public IncomingThirdPartyCallArgs(ComponentName component, String callId, | 
 | 233 |                 String callerDisplayName) { | 
 | 234 |             this.component = component; | 
 | 235 |             this.callId = callId; | 
 | 236 |             this.callerDisplayName = callerDisplayName; | 
 | 237 |         } | 
 | 238 |     } | 
 | 239 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 240 |     /** | 
 | 241 |      * A handler that processes messages on the main thread in the phone process. Since many | 
 | 242 |      * of the Phone calls are not thread safe this is needed to shuttle the requests from the | 
 | 243 |      * inbound binder threads to the main thread in the phone process.  The Binder thread | 
 | 244 |      * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting | 
 | 245 |      * on, which will be notified when the operation completes and will contain the result of the | 
 | 246 |      * request. | 
 | 247 |      * | 
 | 248 |      * <p>If a MainThreadRequest object is provided in the msg.obj field, | 
 | 249 |      * note that request.result must be set to something non-null for the calling thread to | 
 | 250 |      * unblock. | 
 | 251 |      */ | 
 | 252 |     private final class MainThreadHandler extends Handler { | 
 | 253 |         @Override | 
 | 254 |         public void handleMessage(Message msg) { | 
 | 255 |             MainThreadRequest request; | 
 | 256 |             Message onCompleted; | 
 | 257 |             AsyncResult ar; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 258 |             UiccCard uiccCard; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 259 |             IccAPDUArgument iccArgument; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 260 |  | 
 | 261 |             switch (msg.what) { | 
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 262 |                  case CMD_HANDLE_USSD_REQUEST: { | 
 | 263 |                      request = (MainThreadRequest) msg.obj; | 
 | 264 |                      final Phone phone = getPhoneFromRequest(request); | 
 | 265 |                      Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; | 
 | 266 |                      String ussdRequest =  ussdObject.first; | 
 | 267 |                      ResultReceiver wrappedCallback = ussdObject.second; | 
 | 268 |                      request.result = phone != null ? | 
 | 269 |                              phone.handleUssdRequest(ussdRequest, wrappedCallback) | 
 | 270 |                              :false; | 
 | 271 |                      // Wake up the requesting thread | 
 | 272 |                      synchronized (request) { | 
 | 273 |                          request.notifyAll(); | 
 | 274 |                      } | 
 | 275 |                      break; | 
 | 276 |                 } | 
 | 277 |  | 
| Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 278 |                 case CMD_HANDLE_PIN_MMI: { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 279 |                     request = (MainThreadRequest) msg.obj; | 
| Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 280 |                     final Phone phone = getPhoneFromRequest(request); | 
 | 281 |                     request.result = phone != null ? | 
 | 282 |                             getPhoneFromRequest(request).handlePinMmi((String) request.argument) | 
 | 283 |                             : false; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 284 |                     // Wake up the requesting thread | 
 | 285 |                     synchronized (request) { | 
 | 286 |                         request.notifyAll(); | 
 | 287 |                     } | 
 | 288 |                     break; | 
| Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 289 |                 } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 290 |  | 
 | 291 |                 case CMD_HANDLE_NEIGHBORING_CELL: | 
 | 292 |                     request = (MainThreadRequest) msg.obj; | 
 | 293 |                     onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE, | 
 | 294 |                             request); | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 295 |                     mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 296 |                     break; | 
 | 297 |  | 
 | 298 |                 case EVENT_NEIGHBORING_CELL_DONE: | 
 | 299 |                     ar = (AsyncResult) msg.obj; | 
 | 300 |                     request = (MainThreadRequest) ar.userObj; | 
 | 301 |                     if (ar.exception == null && ar.result != null) { | 
 | 302 |                         request.result = ar.result; | 
 | 303 |                     } else { | 
 | 304 |                         // create an empty list to notify the waiting thread | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 305 |                         request.result = new ArrayList<NeighboringCellInfo>(0); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 306 |                     } | 
 | 307 |                     // Wake up the requesting thread | 
 | 308 |                     synchronized (request) { | 
 | 309 |                         request.notifyAll(); | 
 | 310 |                     } | 
 | 311 |                     break; | 
 | 312 |  | 
 | 313 |                 case CMD_ANSWER_RINGING_CALL: | 
| Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 314 |                     request = (MainThreadRequest) msg.obj; | 
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 315 |                     int answer_subId = request.subId; | 
| Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 316 |                     answerRingingCallInternal(answer_subId); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 317 |                     break; | 
 | 318 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 319 |                 case CMD_END_CALL: | 
 | 320 |                     request = (MainThreadRequest) msg.obj; | 
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 321 |                     int end_subId = request.subId; | 
| Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 322 |                     final boolean hungUp; | 
| Anthony Lee | ae4e36d | 2015-05-21 07:17:46 -0700 | [diff] [blame] | 323 |                     Phone phone = getPhone(end_subId); | 
 | 324 |                     if (phone == null) { | 
 | 325 |                         if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId); | 
 | 326 |                         break; | 
 | 327 |                     } | 
 | 328 |                     int phoneType = phone.getPhoneType(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 329 |                     if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) { | 
 | 330 |                         // CDMA: If the user presses the Power button we treat it as | 
 | 331 |                         // ending the complete call session | 
| Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 332 |                         hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId)); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 333 |                     } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) { | 
 | 334 |                         // GSM: End the call as per the Phone state | 
 | 335 |                         hungUp = PhoneUtils.hangup(mCM); | 
 | 336 |                     } else { | 
 | 337 |                         throw new IllegalStateException("Unexpected phone type: " + phoneType); | 
 | 338 |                     } | 
 | 339 |                     if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up")); | 
 | 340 |                     request.result = hungUp; | 
 | 341 |                     // Wake up the requesting thread | 
 | 342 |                     synchronized (request) { | 
 | 343 |                         request.notifyAll(); | 
 | 344 |                     } | 
 | 345 |                     break; | 
 | 346 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 347 |                 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 348 |                     request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 349 |                     iccArgument = (IccAPDUArgument) request.argument; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 350 |                     uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 351 |                     if (uiccCard == null) { | 
 | 352 |                         loge("iccTransmitApduLogicalChannel: No UICC"); | 
 | 353 |                         request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
 | 354 |                         synchronized (request) { | 
 | 355 |                             request.notifyAll(); | 
 | 356 |                         } | 
 | 357 |                     } else { | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 358 |                         onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, | 
 | 359 |                             request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 360 |                         uiccCard.iccTransmitApduLogicalChannel( | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 361 |                             iccArgument.channel, iccArgument.cla, iccArgument.command, | 
 | 362 |                             iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 363 |                             onCompleted); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 364 |                     } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 365 |                     break; | 
 | 366 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 367 |                 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 368 |                     ar = (AsyncResult) msg.obj; | 
 | 369 |                     request = (MainThreadRequest) ar.userObj; | 
 | 370 |                     if (ar.exception == null && ar.result != null) { | 
 | 371 |                         request.result = ar.result; | 
 | 372 |                     } else { | 
 | 373 |                         request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
 | 374 |                         if (ar.result == null) { | 
 | 375 |                             loge("iccTransmitApduLogicalChannel: Empty response"); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 376 |                         } else if (ar.exception instanceof CommandException) { | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 377 |                             loge("iccTransmitApduLogicalChannel: CommandException: " + | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 378 |                                     ar.exception); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 379 |                         } else { | 
 | 380 |                             loge("iccTransmitApduLogicalChannel: Unknown exception"); | 
 | 381 |                         } | 
 | 382 |                     } | 
 | 383 |                     synchronized (request) { | 
 | 384 |                         request.notifyAll(); | 
 | 385 |                     } | 
 | 386 |                     break; | 
 | 387 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 388 |                 case CMD_TRANSMIT_APDU_BASIC_CHANNEL: | 
 | 389 |                     request = (MainThreadRequest) msg.obj; | 
 | 390 |                     iccArgument = (IccAPDUArgument) request.argument; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 391 |                     uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 392 |                     if (uiccCard == null) { | 
 | 393 |                         loge("iccTransmitApduBasicChannel: No UICC"); | 
 | 394 |                         request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
 | 395 |                         synchronized (request) { | 
 | 396 |                             request.notifyAll(); | 
 | 397 |                         } | 
 | 398 |                     } else { | 
 | 399 |                         onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, | 
 | 400 |                             request); | 
 | 401 |                         uiccCard.iccTransmitApduBasicChannel( | 
 | 402 |                             iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, | 
 | 403 |                             iccArgument.p3, iccArgument.data, onCompleted); | 
 | 404 |                     } | 
 | 405 |                     break; | 
 | 406 |  | 
 | 407 |                 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: | 
 | 408 |                     ar = (AsyncResult) msg.obj; | 
 | 409 |                     request = (MainThreadRequest) ar.userObj; | 
 | 410 |                     if (ar.exception == null && ar.result != null) { | 
 | 411 |                         request.result = ar.result; | 
 | 412 |                     } else { | 
 | 413 |                         request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
 | 414 |                         if (ar.result == null) { | 
 | 415 |                             loge("iccTransmitApduBasicChannel: Empty response"); | 
 | 416 |                         } else if (ar.exception instanceof CommandException) { | 
 | 417 |                             loge("iccTransmitApduBasicChannel: CommandException: " + | 
 | 418 |                                     ar.exception); | 
 | 419 |                         } else { | 
 | 420 |                             loge("iccTransmitApduBasicChannel: Unknown exception"); | 
 | 421 |                         } | 
 | 422 |                     } | 
 | 423 |                     synchronized (request) { | 
 | 424 |                         request.notifyAll(); | 
 | 425 |                     } | 
 | 426 |                     break; | 
 | 427 |  | 
 | 428 |                 case CMD_EXCHANGE_SIM_IO: | 
 | 429 |                     request = (MainThreadRequest) msg.obj; | 
 | 430 |                     iccArgument = (IccAPDUArgument) request.argument; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 431 |                     uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 432 |                     if (uiccCard == null) { | 
 | 433 |                         loge("iccExchangeSimIO: No UICC"); | 
 | 434 |                         request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
 | 435 |                         synchronized (request) { | 
 | 436 |                             request.notifyAll(); | 
 | 437 |                         } | 
 | 438 |                     } else { | 
 | 439 |                         onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, | 
 | 440 |                                 request); | 
 | 441 |                         uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ | 
 | 442 |                                 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, | 
 | 443 |                                 iccArgument.data, onCompleted); | 
 | 444 |                     } | 
 | 445 |                     break; | 
 | 446 |  | 
 | 447 |                 case EVENT_EXCHANGE_SIM_IO_DONE: | 
 | 448 |                     ar = (AsyncResult) msg.obj; | 
 | 449 |                     request = (MainThreadRequest) ar.userObj; | 
 | 450 |                     if (ar.exception == null && ar.result != null) { | 
 | 451 |                         request.result = ar.result; | 
 | 452 |                     } else { | 
 | 453 |                         request.result = new IccIoResult(0x6f, 0, (byte[])null); | 
 | 454 |                     } | 
 | 455 |                     synchronized (request) { | 
 | 456 |                         request.notifyAll(); | 
 | 457 |                     } | 
 | 458 |                     break; | 
 | 459 |  | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 460 |                 case CMD_SEND_ENVELOPE: | 
 | 461 |                     request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 462 |                     uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 463 |                     if (uiccCard == null) { | 
 | 464 |                         loge("sendEnvelopeWithStatus: No UICC"); | 
 | 465 |                         request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
 | 466 |                         synchronized (request) { | 
 | 467 |                             request.notifyAll(); | 
 | 468 |                         } | 
 | 469 |                     } else { | 
 | 470 |                         onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); | 
 | 471 |                         uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); | 
 | 472 |                     } | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 473 |                     break; | 
 | 474 |  | 
 | 475 |                 case EVENT_SEND_ENVELOPE_DONE: | 
 | 476 |                     ar = (AsyncResult) msg.obj; | 
 | 477 |                     request = (MainThreadRequest) ar.userObj; | 
| Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 478 |                     if (ar.exception == null && ar.result != null) { | 
 | 479 |                         request.result = ar.result; | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 480 |                     } else { | 
| Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 481 |                         request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
 | 482 |                         if (ar.result == null) { | 
 | 483 |                             loge("sendEnvelopeWithStatus: Empty response"); | 
 | 484 |                         } else if (ar.exception instanceof CommandException) { | 
 | 485 |                             loge("sendEnvelopeWithStatus: CommandException: " + | 
 | 486 |                                     ar.exception); | 
 | 487 |                         } else { | 
 | 488 |                             loge("sendEnvelopeWithStatus: exception:" + ar.exception); | 
 | 489 |                         } | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 490 |                     } | 
 | 491 |                     synchronized (request) { | 
 | 492 |                         request.notifyAll(); | 
 | 493 |                     } | 
 | 494 |                     break; | 
 | 495 |  | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 496 |                 case CMD_OPEN_CHANNEL: | 
 | 497 |                     request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 498 |                     uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 499 |                     if (uiccCard == null) { | 
 | 500 |                         loge("iccOpenLogicalChannel: No UICC"); | 
| Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 501 |                         request.result = new IccOpenLogicalChannelResponse(-1, | 
 | 502 |                             IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 503 |                         synchronized (request) { | 
 | 504 |                             request.notifyAll(); | 
 | 505 |                         } | 
 | 506 |                     } else { | 
 | 507 |                         onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); | 
 | 508 |                         uiccCard.iccOpenLogicalChannel((String)request.argument, onCompleted); | 
 | 509 |                     } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 510 |                     break; | 
 | 511 |  | 
 | 512 |                 case EVENT_OPEN_CHANNEL_DONE: | 
 | 513 |                     ar = (AsyncResult) msg.obj; | 
 | 514 |                     request = (MainThreadRequest) ar.userObj; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 515 |                     IccOpenLogicalChannelResponse openChannelResp; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 516 |                     if (ar.exception == null && ar.result != null) { | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 517 |                         int[] result = (int[]) ar.result; | 
 | 518 |                         int channelId = result[0]; | 
 | 519 |                         byte[] selectResponse = null; | 
 | 520 |                         if (result.length > 1) { | 
 | 521 |                             selectResponse = new byte[result.length - 1]; | 
 | 522 |                             for (int i = 1; i < result.length; ++i) { | 
 | 523 |                                 selectResponse[i - 1] = (byte) result[i]; | 
 | 524 |                             } | 
 | 525 |                         } | 
 | 526 |                         openChannelResp = new IccOpenLogicalChannelResponse(channelId, | 
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 527 |                             IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 528 |                     } else { | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 529 |                         if (ar.result == null) { | 
 | 530 |                             loge("iccOpenLogicalChannel: Empty response"); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 531 |                         } | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 532 |                         if (ar.exception != null) { | 
 | 533 |                             loge("iccOpenLogicalChannel: Exception: " + ar.exception); | 
 | 534 |                         } | 
 | 535 |  | 
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 536 |                         int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; | 
| Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 537 |                         if (ar.exception instanceof CommandException) { | 
 | 538 |                             CommandException.Error error = | 
 | 539 |                                 ((CommandException) (ar.exception)).getCommandError(); | 
 | 540 |                             if (error == CommandException.Error.MISSING_RESOURCE) { | 
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 541 |                                 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; | 
| Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 542 |                             } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { | 
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 543 |                                 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 544 |                             } | 
 | 545 |                         } | 
 | 546 |                         openChannelResp = new IccOpenLogicalChannelResponse( | 
 | 547 |                             IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 548 |                     } | 
| Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 549 |                     request.result = openChannelResp; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 550 |                     synchronized (request) { | 
 | 551 |                         request.notifyAll(); | 
 | 552 |                     } | 
 | 553 |                     break; | 
 | 554 |  | 
 | 555 |                 case CMD_CLOSE_CHANNEL: | 
 | 556 |                     request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 557 |                     uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 558 |                     if (uiccCard == null) { | 
 | 559 |                         loge("iccCloseLogicalChannel: No UICC"); | 
 | 560 |                         request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
 | 561 |                         synchronized (request) { | 
 | 562 |                             request.notifyAll(); | 
 | 563 |                         } | 
 | 564 |                     } else { | 
 | 565 |                         onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); | 
 | 566 |                         uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); | 
 | 567 |                     } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 568 |                     break; | 
 | 569 |  | 
 | 570 |                 case EVENT_CLOSE_CHANNEL_DONE: | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 571 |                     handleNullReturnEvent(msg, "iccCloseLogicalChannel"); | 
 | 572 |                     break; | 
 | 573 |  | 
 | 574 |                 case CMD_NV_READ_ITEM: | 
 | 575 |                     request = (MainThreadRequest) msg.obj; | 
 | 576 |                     onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); | 
 | 577 |                     mPhone.nvReadItem((Integer) request.argument, onCompleted); | 
 | 578 |                     break; | 
 | 579 |  | 
 | 580 |                 case EVENT_NV_READ_ITEM_DONE: | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 581 |                     ar = (AsyncResult) msg.obj; | 
 | 582 |                     request = (MainThreadRequest) ar.userObj; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 583 |                     if (ar.exception == null && ar.result != null) { | 
 | 584 |                         request.result = ar.result;     // String | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 585 |                     } else { | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 586 |                         request.result = ""; | 
 | 587 |                         if (ar.result == null) { | 
 | 588 |                             loge("nvReadItem: Empty response"); | 
 | 589 |                         } else if (ar.exception instanceof CommandException) { | 
 | 590 |                             loge("nvReadItem: CommandException: " + | 
 | 591 |                                     ar.exception); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 592 |                         } else { | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 593 |                             loge("nvReadItem: Unknown exception"); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 594 |                         } | 
 | 595 |                     } | 
 | 596 |                     synchronized (request) { | 
 | 597 |                         request.notifyAll(); | 
 | 598 |                     } | 
 | 599 |                     break; | 
 | 600 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 601 |                 case CMD_NV_WRITE_ITEM: | 
 | 602 |                     request = (MainThreadRequest) msg.obj; | 
 | 603 |                     onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); | 
 | 604 |                     Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; | 
 | 605 |                     mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted); | 
 | 606 |                     break; | 
 | 607 |  | 
 | 608 |                 case EVENT_NV_WRITE_ITEM_DONE: | 
 | 609 |                     handleNullReturnEvent(msg, "nvWriteItem"); | 
 | 610 |                     break; | 
 | 611 |  | 
 | 612 |                 case CMD_NV_WRITE_CDMA_PRL: | 
 | 613 |                     request = (MainThreadRequest) msg.obj; | 
 | 614 |                     onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); | 
 | 615 |                     mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); | 
 | 616 |                     break; | 
 | 617 |  | 
 | 618 |                 case EVENT_NV_WRITE_CDMA_PRL_DONE: | 
 | 619 |                     handleNullReturnEvent(msg, "nvWriteCdmaPrl"); | 
 | 620 |                     break; | 
 | 621 |  | 
 | 622 |                 case CMD_NV_RESET_CONFIG: | 
 | 623 |                     request = (MainThreadRequest) msg.obj; | 
 | 624 |                     onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request); | 
 | 625 |                     mPhone.nvResetConfig((Integer) request.argument, onCompleted); | 
 | 626 |                     break; | 
 | 627 |  | 
 | 628 |                 case EVENT_NV_RESET_CONFIG_DONE: | 
 | 629 |                     handleNullReturnEvent(msg, "nvResetConfig"); | 
 | 630 |                     break; | 
 | 631 |  | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 632 |                 case CMD_GET_PREFERRED_NETWORK_TYPE: | 
 | 633 |                     request = (MainThreadRequest) msg.obj; | 
 | 634 |                     onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 635 |                     getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 636 |                     break; | 
 | 637 |  | 
 | 638 |                 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: | 
 | 639 |                     ar = (AsyncResult) msg.obj; | 
 | 640 |                     request = (MainThreadRequest) ar.userObj; | 
 | 641 |                     if (ar.exception == null && ar.result != null) { | 
 | 642 |                         request.result = ar.result;     // Integer | 
 | 643 |                     } else { | 
| Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 644 |                         request.result = null; | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 645 |                         if (ar.result == null) { | 
 | 646 |                             loge("getPreferredNetworkType: Empty response"); | 
 | 647 |                         } else if (ar.exception instanceof CommandException) { | 
 | 648 |                             loge("getPreferredNetworkType: CommandException: " + | 
 | 649 |                                     ar.exception); | 
 | 650 |                         } else { | 
 | 651 |                             loge("getPreferredNetworkType: Unknown exception"); | 
 | 652 |                         } | 
 | 653 |                     } | 
 | 654 |                     synchronized (request) { | 
 | 655 |                         request.notifyAll(); | 
 | 656 |                     } | 
 | 657 |                     break; | 
 | 658 |  | 
 | 659 |                 case CMD_SET_PREFERRED_NETWORK_TYPE: | 
 | 660 |                     request = (MainThreadRequest) msg.obj; | 
 | 661 |                     onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); | 
 | 662 |                     int networkType = (Integer) request.argument; | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 663 |                     getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 664 |                     break; | 
 | 665 |  | 
 | 666 |                 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: | 
 | 667 |                     handleNullReturnEvent(msg, "setPreferredNetworkType"); | 
 | 668 |                     break; | 
 | 669 |  | 
| Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 670 |                 case CMD_INVOKE_OEM_RIL_REQUEST_RAW: | 
 | 671 |                     request = (MainThreadRequest)msg.obj; | 
 | 672 |                     onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); | 
 | 673 |                     mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted); | 
 | 674 |                     break; | 
 | 675 |  | 
 | 676 |                 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: | 
 | 677 |                     ar = (AsyncResult)msg.obj; | 
 | 678 |                     request = (MainThreadRequest)ar.userObj; | 
 | 679 |                     request.result = ar; | 
 | 680 |                     synchronized (request) { | 
 | 681 |                         request.notifyAll(); | 
 | 682 |                     } | 
 | 683 |                     break; | 
 | 684 |  | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 685 |                 case CMD_SET_VOICEMAIL_NUMBER: | 
 | 686 |                     request = (MainThreadRequest) msg.obj; | 
 | 687 |                     onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); | 
 | 688 |                     Pair<String, String> tagNum = (Pair<String, String>) request.argument; | 
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 689 |                     getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, | 
 | 690 |                             onCompleted); | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 691 |                     break; | 
 | 692 |  | 
 | 693 |                 case EVENT_SET_VOICEMAIL_NUMBER_DONE: | 
 | 694 |                     handleNullReturnEvent(msg, "setVoicemailNumber"); | 
 | 695 |                     break; | 
 | 696 |  | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 697 |                 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: | 
 | 698 |                     request = (MainThreadRequest) msg.obj; | 
 | 699 |                     onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, | 
 | 700 |                             request); | 
 | 701 |                     getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); | 
 | 702 |                     break; | 
 | 703 |  | 
 | 704 |                 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: | 
 | 705 |                     handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); | 
 | 706 |                     break; | 
 | 707 |  | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 708 |                 case CMD_PERFORM_NETWORK_SCAN: | 
 | 709 |                     request = (MainThreadRequest) msg.obj; | 
 | 710 |                     onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); | 
 | 711 |                     getPhoneFromRequest(request).getAvailableNetworks(onCompleted); | 
 | 712 |                     break; | 
 | 713 |  | 
 | 714 |                 case EVENT_PERFORM_NETWORK_SCAN_DONE: | 
 | 715 |                     ar = (AsyncResult) msg.obj; | 
 | 716 |                     request = (MainThreadRequest) ar.userObj; | 
 | 717 |                     CellNetworkScanResult cellScanResult; | 
 | 718 |                     if (ar.exception == null && ar.result != null) { | 
 | 719 |                         cellScanResult = new CellNetworkScanResult( | 
 | 720 |                                 CellNetworkScanResult.STATUS_SUCCESS, | 
 | 721 |                                 (List<OperatorInfo>) ar.result); | 
 | 722 |                     } else { | 
 | 723 |                         if (ar.result == null) { | 
 | 724 |                             loge("getCellNetworkScanResults: Empty response"); | 
 | 725 |                         } | 
 | 726 |                         if (ar.exception != null) { | 
 | 727 |                             loge("getCellNetworkScanResults: Exception: " + ar.exception); | 
 | 728 |                         } | 
 | 729 |                         int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; | 
 | 730 |                         if (ar.exception instanceof CommandException) { | 
 | 731 |                             CommandException.Error error = | 
 | 732 |                                 ((CommandException) (ar.exception)).getCommandError(); | 
 | 733 |                             if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { | 
 | 734 |                                 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; | 
 | 735 |                             } else if (error == CommandException.Error.GENERIC_FAILURE) { | 
 | 736 |                                 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; | 
 | 737 |                             } | 
 | 738 |                         } | 
 | 739 |                         cellScanResult = new CellNetworkScanResult(errorCode, null); | 
 | 740 |                     } | 
 | 741 |                     request.result = cellScanResult; | 
 | 742 |                     synchronized (request) { | 
 | 743 |                         request.notifyAll(); | 
 | 744 |                     } | 
 | 745 |                     break; | 
 | 746 |  | 
 | 747 |                 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: | 
 | 748 |                     request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 749 |                     ManualNetworkSelectionArgument selArg = | 
 | 750 |                             (ManualNetworkSelectionArgument) request.argument; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 751 |                     onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, | 
 | 752 |                             request); | 
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 753 |                     getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, | 
 | 754 |                             selArg.persistSelection, onCompleted); | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 755 |                     break; | 
 | 756 |  | 
 | 757 |                 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: | 
 | 758 |                     handleNullReturnEvent(msg, "setNetworkSelectionModeManual"); | 
 | 759 |                     break; | 
 | 760 |  | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 761 |                 case CMD_GET_MODEM_ACTIVITY_INFO: | 
 | 762 |                     request = (MainThreadRequest) msg.obj; | 
 | 763 |                     onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); | 
| Prerepa Viswanadham | 61a60ad | 2015-06-08 18:07:51 -0700 | [diff] [blame] | 764 |                     mPhone.getModemActivityInfo(onCompleted); | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 765 |                     break; | 
 | 766 |  | 
 | 767 |                 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: | 
 | 768 |                     ar = (AsyncResult) msg.obj; | 
 | 769 |                     request = (MainThreadRequest) ar.userObj; | 
 | 770 |                     if (ar.exception == null && ar.result != null) { | 
 | 771 |                         request.result = ar.result; | 
 | 772 |                     } else { | 
 | 773 |                         if (ar.result == null) { | 
 | 774 |                             loge("queryModemActivityInfo: Empty response"); | 
 | 775 |                         } else if (ar.exception instanceof CommandException) { | 
 | 776 |                             loge("queryModemActivityInfo: CommandException: " + | 
 | 777 |                                     ar.exception); | 
 | 778 |                         } else { | 
 | 779 |                             loge("queryModemActivityInfo: Unknown exception"); | 
 | 780 |                         } | 
 | 781 |                     } | 
| Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 782 |                     // Result cannot be null. Return ModemActivityInfo with all fields set to 0. | 
 | 783 |                     if (request.result == null) { | 
 | 784 |                         request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); | 
 | 785 |                     } | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 786 |                     synchronized (request) { | 
 | 787 |                         request.notifyAll(); | 
 | 788 |                     } | 
 | 789 |                     break; | 
 | 790 |  | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 791 |                 case CMD_SET_ALLOWED_CARRIERS: | 
 | 792 |                     request = (MainThreadRequest) msg.obj; | 
 | 793 |                     onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); | 
 | 794 |                     mPhone.setAllowedCarriers( | 
 | 795 |                             (List<CarrierIdentifier>) request.argument, | 
 | 796 |                             onCompleted); | 
 | 797 |                     break; | 
 | 798 |  | 
 | 799 |                 case EVENT_SET_ALLOWED_CARRIERS_DONE: | 
 | 800 |                     ar = (AsyncResult) msg.obj; | 
 | 801 |                     request = (MainThreadRequest) ar.userObj; | 
 | 802 |                     if (ar.exception == null && ar.result != null) { | 
 | 803 |                         request.result = ar.result; | 
 | 804 |                     } else { | 
 | 805 |                         if (ar.result == null) { | 
 | 806 |                             loge("setAllowedCarriers: Empty response"); | 
 | 807 |                         } else if (ar.exception instanceof CommandException) { | 
 | 808 |                             loge("setAllowedCarriers: CommandException: " + | 
 | 809 |                                     ar.exception); | 
 | 810 |                         } else { | 
 | 811 |                             loge("setAllowedCarriers: Unknown exception"); | 
 | 812 |                         } | 
 | 813 |                     } | 
 | 814 |                     // Result cannot be null. Return -1 on error. | 
 | 815 |                     if (request.result == null) { | 
 | 816 |                         request.result = new int[]{-1}; | 
 | 817 |                     } | 
 | 818 |                     synchronized (request) { | 
 | 819 |                         request.notifyAll(); | 
 | 820 |                     } | 
 | 821 |                     break; | 
 | 822 |  | 
 | 823 |                 case CMD_GET_ALLOWED_CARRIERS: | 
 | 824 |                     request = (MainThreadRequest) msg.obj; | 
 | 825 |                     onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); | 
 | 826 |                     mPhone.getAllowedCarriers(onCompleted); | 
 | 827 |                     break; | 
 | 828 |  | 
 | 829 |                 case EVENT_GET_ALLOWED_CARRIERS_DONE: | 
 | 830 |                     ar = (AsyncResult) msg.obj; | 
 | 831 |                     request = (MainThreadRequest) ar.userObj; | 
 | 832 |                     if (ar.exception == null && ar.result != null) { | 
 | 833 |                         request.result = ar.result; | 
 | 834 |                     } else { | 
 | 835 |                         if (ar.result == null) { | 
 | 836 |                             loge("getAllowedCarriers: Empty response"); | 
 | 837 |                         } else if (ar.exception instanceof CommandException) { | 
 | 838 |                             loge("getAllowedCarriers: CommandException: " + | 
 | 839 |                                     ar.exception); | 
 | 840 |                         } else { | 
 | 841 |                             loge("getAllowedCarriers: Unknown exception"); | 
 | 842 |                         } | 
 | 843 |                     } | 
 | 844 |                     // Result cannot be null. Return empty list of CarrierIdentifier. | 
 | 845 |                     if (request.result == null) { | 
 | 846 |                         request.result = new ArrayList<CarrierIdentifier>(0); | 
 | 847 |                     } | 
 | 848 |                     synchronized (request) { | 
 | 849 |                         request.notifyAll(); | 
 | 850 |                     } | 
 | 851 |                     break; | 
 | 852 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 853 |                 default: | 
 | 854 |                     Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); | 
 | 855 |                     break; | 
 | 856 |             } | 
 | 857 |         } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 858 |  | 
 | 859 |         private void handleNullReturnEvent(Message msg, String command) { | 
 | 860 |             AsyncResult ar = (AsyncResult) msg.obj; | 
 | 861 |             MainThreadRequest request = (MainThreadRequest) ar.userObj; | 
 | 862 |             if (ar.exception == null) { | 
 | 863 |                 request.result = true; | 
 | 864 |             } else { | 
 | 865 |                 request.result = false; | 
 | 866 |                 if (ar.exception instanceof CommandException) { | 
 | 867 |                     loge(command + ": CommandException: " + ar.exception); | 
 | 868 |                 } else { | 
 | 869 |                     loge(command + ": Unknown exception"); | 
 | 870 |                 } | 
 | 871 |             } | 
 | 872 |             synchronized (request) { | 
 | 873 |                 request.notifyAll(); | 
 | 874 |             } | 
 | 875 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 876 |     } | 
 | 877 |  | 
 | 878 |     /** | 
 | 879 |      * Posts the specified command to be executed on the main thread, | 
 | 880 |      * waits for the request to complete, and returns the result. | 
 | 881 |      * @see #sendRequestAsync | 
 | 882 |      */ | 
 | 883 |     private Object sendRequest(int command, Object argument) { | 
| Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 884 |         return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 885 |     } | 
 | 886 |  | 
 | 887 |     /** | 
 | 888 |      * Posts the specified command to be executed on the main thread, | 
 | 889 |      * waits for the request to complete, and returns the result. | 
 | 890 |      * @see #sendRequestAsync | 
 | 891 |      */ | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 892 |     private Object sendRequest(int command, Object argument, Integer subId) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 893 |         if (Looper.myLooper() == mMainThreadHandler.getLooper()) { | 
 | 894 |             throw new RuntimeException("This method will deadlock if called from the main thread."); | 
 | 895 |         } | 
 | 896 |  | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 897 |         MainThreadRequest request = new MainThreadRequest(argument, subId); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 898 |         Message msg = mMainThreadHandler.obtainMessage(command, request); | 
 | 899 |         msg.sendToTarget(); | 
 | 900 |  | 
 | 901 |         // Wait for the request to complete | 
 | 902 |         synchronized (request) { | 
 | 903 |             while (request.result == null) { | 
 | 904 |                 try { | 
 | 905 |                     request.wait(); | 
 | 906 |                 } catch (InterruptedException e) { | 
 | 907 |                     // Do nothing, go back and wait until the request is complete | 
 | 908 |                 } | 
 | 909 |             } | 
 | 910 |         } | 
 | 911 |         return request.result; | 
 | 912 |     } | 
 | 913 |  | 
 | 914 |     /** | 
 | 915 |      * Asynchronous ("fire and forget") version of sendRequest(): | 
 | 916 |      * Posts the specified command to be executed on the main thread, and | 
 | 917 |      * returns immediately. | 
 | 918 |      * @see #sendRequest | 
 | 919 |      */ | 
 | 920 |     private void sendRequestAsync(int command) { | 
 | 921 |         mMainThreadHandler.sendEmptyMessage(command); | 
 | 922 |     } | 
 | 923 |  | 
 | 924 |     /** | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 925 |      * Same as {@link #sendRequestAsync(int)} except it takes an argument. | 
 | 926 |      * @see {@link #sendRequest(int,Object)} | 
 | 927 |      */ | 
 | 928 |     private void sendRequestAsync(int command, Object argument) { | 
 | 929 |         MainThreadRequest request = new MainThreadRequest(argument); | 
 | 930 |         Message msg = mMainThreadHandler.obtainMessage(command, request); | 
 | 931 |         msg.sendToTarget(); | 
 | 932 |     } | 
 | 933 |  | 
 | 934 |     /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 935 |      * Initialize the singleton PhoneInterfaceManager instance. | 
 | 936 |      * This is only done once, at startup, from PhoneApp.onCreate(). | 
 | 937 |      */ | 
| Sailesh Nepal | 194161e | 2014-07-03 08:57:44 -0700 | [diff] [blame] | 938 |     /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 939 |         synchronized (PhoneInterfaceManager.class) { | 
 | 940 |             if (sInstance == null) { | 
| Sailesh Nepal | 194161e | 2014-07-03 08:57:44 -0700 | [diff] [blame] | 941 |                 sInstance = new PhoneInterfaceManager(app, phone); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 942 |             } else { | 
 | 943 |                 Log.wtf(LOG_TAG, "init() called multiple times!  sInstance = " + sInstance); | 
 | 944 |             } | 
 | 945 |             return sInstance; | 
 | 946 |         } | 
 | 947 |     } | 
 | 948 |  | 
 | 949 |     /** Private constructor; @see init() */ | 
| Sailesh Nepal | 194161e | 2014-07-03 08:57:44 -0700 | [diff] [blame] | 950 |     private PhoneInterfaceManager(PhoneGlobals app, Phone phone) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 951 |         mApp = app; | 
 | 952 |         mPhone = phone; | 
 | 953 |         mCM = PhoneGlobals.getInstance().mCM; | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 954 |         mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 955 |         mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); | 
 | 956 |         mMainThreadHandler = new MainThreadHandler(); | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 957 |         mTelephonySharedPreferences = | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 958 |                 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext()); | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 959 |         mSubscriptionController = SubscriptionController.getInstance(); | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 960 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 961 |         publish(); | 
 | 962 |     } | 
 | 963 |  | 
 | 964 |     private void publish() { | 
 | 965 |         if (DBG) log("publish: " + this); | 
 | 966 |  | 
 | 967 |         ServiceManager.addService("phone", this); | 
 | 968 |     } | 
 | 969 |  | 
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 970 |     private Phone getPhoneFromRequest(MainThreadRequest request) { | 
| Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 971 |         return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) | 
 | 972 |                 ? mPhone : getPhone(request.subId); | 
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 973 |     } | 
 | 974 |  | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 975 |     private UiccCard getUiccCardFromRequest(MainThreadRequest request) { | 
 | 976 |         Phone phone = getPhoneFromRequest(request); | 
 | 977 |         return phone == null ? null : | 
 | 978 |                 UiccController.getInstance().getUiccCard(phone.getPhoneId()); | 
 | 979 |     } | 
 | 980 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 981 |     // returns phone associated with the subId. | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 982 |     private Phone getPhone(int subId) { | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 983 |         return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 984 |     } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 985 |     // | 
 | 986 |     // Implementation of the ITelephony interface. | 
 | 987 |     // | 
 | 988 |  | 
 | 989 |     public void dial(String number) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 990 |         dialForSubscriber(getPreferredVoiceSubscription(), number); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 991 |     } | 
 | 992 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 993 |     public void dialForSubscriber(int subId, String number) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 994 |         if (DBG) log("dial: " + number); | 
 | 995 |         // No permission check needed here: This is just a wrapper around the | 
 | 996 |         // ACTION_DIAL intent, which is available to any app since it puts up | 
 | 997 |         // the UI before it does anything. | 
 | 998 |  | 
 | 999 |         String url = createTelUrl(number); | 
 | 1000 |         if (url == null) { | 
 | 1001 |             return; | 
 | 1002 |         } | 
 | 1003 |  | 
 | 1004 |         // PENDING: should we just silently fail if phone is offhook or ringing? | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1005 |         PhoneConstants.State state = mCM.getState(subId); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1006 |         if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { | 
 | 1007 |             Intent  intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); | 
 | 1008 |             intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 
 | 1009 |             mApp.startActivity(intent); | 
 | 1010 |         } | 
 | 1011 |     } | 
 | 1012 |  | 
 | 1013 |     public void call(String callingPackage, String number) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1014 |         callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1015 |     } | 
 | 1016 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1017 |     public void callForSubscriber(int subId, String callingPackage, String number) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1018 |         if (DBG) log("call: " + number); | 
 | 1019 |  | 
 | 1020 |         // This is just a wrapper around the ACTION_CALL intent, but we still | 
 | 1021 |         // need to do a permission check since we're calling startActivity() | 
 | 1022 |         // from the context of the phone app. | 
 | 1023 |         enforceCallPermission(); | 
 | 1024 |  | 
 | 1025 |         if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) | 
 | 1026 |                 != AppOpsManager.MODE_ALLOWED) { | 
 | 1027 |             return; | 
 | 1028 |         } | 
 | 1029 |  | 
 | 1030 |         String url = createTelUrl(number); | 
 | 1031 |         if (url == null) { | 
 | 1032 |             return; | 
 | 1033 |         } | 
 | 1034 |  | 
| Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1035 |         boolean isValid = false; | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 1036 |         final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList(); | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1037 |         if (slist != null) { | 
 | 1038 |             for (SubscriptionInfo subInfoRecord : slist) { | 
 | 1039 |                 if (subInfoRecord.getSubscriptionId() == subId) { | 
 | 1040 |                     isValid = true; | 
 | 1041 |                     break; | 
 | 1042 |                 } | 
| Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1043 |             } | 
 | 1044 |         } | 
 | 1045 |         if (isValid == false) { | 
 | 1046 |             return; | 
 | 1047 |         } | 
 | 1048 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1049 |         Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1050 |         intent.putExtra(SUBSCRIPTION_KEY, subId); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1051 |         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 
 | 1052 |         mApp.startActivity(intent); | 
 | 1053 |     } | 
 | 1054 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1055 |     /** | 
 | 1056 |      * End a call based on call state | 
 | 1057 |      * @return true is a call was ended | 
 | 1058 |      */ | 
 | 1059 |     public boolean endCall() { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1060 |         return endCallForSubscriber(getDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1061 |     } | 
 | 1062 |  | 
 | 1063 |     /** | 
 | 1064 |      * End a call based on the call state of the subId | 
 | 1065 |      * @return true is a call was ended | 
 | 1066 |      */ | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1067 |     public boolean endCallForSubscriber(int subId) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1068 |         enforceCallPermission(); | 
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1069 |         return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId)); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1070 |     } | 
 | 1071 |  | 
 | 1072 |     public void answerRingingCall() { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1073 |         answerRingingCallForSubscriber(getDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1074 |     } | 
 | 1075 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1076 |     public void answerRingingCallForSubscriber(int subId) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1077 |         if (DBG) log("answerRingingCall..."); | 
 | 1078 |         // TODO: there should eventually be a separate "ANSWER_PHONE" permission, | 
 | 1079 |         // but that can probably wait till the big TelephonyManager API overhaul. | 
 | 1080 |         // For now, protect this call with the MODIFY_PHONE_STATE permission. | 
 | 1081 |         enforceModifyPermission(); | 
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1082 |         sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId)); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1083 |     } | 
 | 1084 |  | 
 | 1085 |     /** | 
 | 1086 |      * Make the actual telephony calls to implement answerRingingCall(). | 
 | 1087 |      * This should only be called from the main thread of the Phone app. | 
 | 1088 |      * @see #answerRingingCall | 
 | 1089 |      * | 
 | 1090 |      * TODO: it would be nice to return true if we answered the call, or | 
 | 1091 |      * false if there wasn't actually a ringing incoming call, or some | 
 | 1092 |      * other error occurred.  (In other words, pass back the return value | 
 | 1093 |      * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().) | 
 | 1094 |      * But that would require calling this method via sendRequest() rather | 
 | 1095 |      * than sendRequestAsync(), and right now we don't actually *need* that | 
 | 1096 |      * return value, so let's just return void for now. | 
 | 1097 |      */ | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1098 |     private void answerRingingCallInternal(int subId) { | 
| Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1099 |         final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1100 |         if (hasRingingCall) { | 
| Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1101 |             final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle(); | 
 | 1102 |             final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1103 |             if (hasActiveCall && hasHoldingCall) { | 
 | 1104 |                 // Both lines are in use! | 
 | 1105 |                 // TODO: provide a flag to let the caller specify what | 
 | 1106 |                 // policy to use if both lines are in use.  (The current | 
 | 1107 |                 // behavior is hardwired to "answer incoming, end ongoing", | 
 | 1108 |                 // which is how the CALL button is specced to behave.) | 
 | 1109 |                 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall()); | 
 | 1110 |                 return; | 
 | 1111 |             } else { | 
 | 1112 |                 // answerCall() will automatically hold the current active | 
 | 1113 |                 // call, if there is one. | 
 | 1114 |                 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall()); | 
 | 1115 |                 return; | 
 | 1116 |             } | 
 | 1117 |         } else { | 
 | 1118 |             // No call was ringing. | 
 | 1119 |             return; | 
 | 1120 |         } | 
 | 1121 |     } | 
 | 1122 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1123 |     /** | 
| Santos Cordon | 5422a8d | 2014-09-12 04:20:56 -0700 | [diff] [blame] | 1124 |      * This method is no longer used and can be removed once TelephonyManager stops referring to it. | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1125 |      */ | 
| Santos Cordon | 5422a8d | 2014-09-12 04:20:56 -0700 | [diff] [blame] | 1126 |     public void silenceRinger() { | 
 | 1127 |         Log.e(LOG_TAG, "silenseRinger not supported"); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1128 |     } | 
 | 1129 |  | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1130 |     @Override | 
 | 1131 |     public boolean isOffhook(String callingPackage) { | 
 | 1132 |         return isOffhookForSubscriber(getDefaultSubscription(), callingPackage); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1133 |     } | 
 | 1134 |  | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1135 |     @Override | 
 | 1136 |     public boolean isOffhookForSubscriber(int subId, String callingPackage) { | 
 | 1137 |         if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) { | 
 | 1138 |             return false; | 
 | 1139 |         } | 
 | 1140 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1141 |         final Phone phone = getPhone(subId); | 
 | 1142 |         if (phone != null) { | 
 | 1143 |             return (phone.getState() == PhoneConstants.State.OFFHOOK); | 
 | 1144 |         } else { | 
 | 1145 |             return false; | 
 | 1146 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1147 |     } | 
 | 1148 |  | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1149 |     @Override | 
 | 1150 |     public boolean isRinging(String callingPackage) { | 
 | 1151 |         return (isRingingForSubscriber(getDefaultSubscription(), callingPackage)); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1152 |     } | 
 | 1153 |  | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1154 |     @Override | 
 | 1155 |     public boolean isRingingForSubscriber(int subId, String callingPackage) { | 
 | 1156 |         if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) { | 
 | 1157 |             return false; | 
 | 1158 |         } | 
 | 1159 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1160 |         final Phone phone = getPhone(subId); | 
 | 1161 |         if (phone != null) { | 
 | 1162 |             return (phone.getState() == PhoneConstants.State.RINGING); | 
 | 1163 |         } else { | 
 | 1164 |             return false; | 
 | 1165 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1166 |     } | 
 | 1167 |  | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1168 |     @Override | 
 | 1169 |     public boolean isIdle(String callingPackage) { | 
 | 1170 |         return isIdleForSubscriber(getDefaultSubscription(), callingPackage); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1171 |     } | 
 | 1172 |  | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1173 |     @Override | 
 | 1174 |     public boolean isIdleForSubscriber(int subId, String callingPackage) { | 
 | 1175 |         if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) { | 
 | 1176 |             return false; | 
 | 1177 |         } | 
 | 1178 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1179 |         final Phone phone = getPhone(subId); | 
 | 1180 |         if (phone != null) { | 
 | 1181 |             return (phone.getState() == PhoneConstants.State.IDLE); | 
 | 1182 |         } else { | 
 | 1183 |             return false; | 
 | 1184 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1185 |     } | 
 | 1186 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1187 |     public boolean supplyPin(String pin) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1188 |         return supplyPinForSubscriber(getDefaultSubscription(), pin); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1189 |     } | 
 | 1190 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1191 |     public boolean supplyPinForSubscriber(int subId, String pin) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1192 |         int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1193 |         return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; | 
 | 1194 |     } | 
 | 1195 |  | 
 | 1196 |     public boolean supplyPuk(String puk, String pin) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1197 |         return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1198 |     } | 
 | 1199 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1200 |     public boolean supplyPukForSubscriber(int subId, String puk, String pin) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1201 |         int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1202 |         return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; | 
 | 1203 |     } | 
 | 1204 |  | 
 | 1205 |     /** {@hide} */ | 
 | 1206 |     public int[] supplyPinReportResult(String pin) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1207 |         return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1208 |     } | 
 | 1209 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1210 |     public int[] supplyPinReportResultForSubscriber(int subId, String pin) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1211 |         enforceModifyPermission(); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1212 |         final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1213 |         checkSimPin.start(); | 
 | 1214 |         return checkSimPin.unlockSim(null, pin); | 
 | 1215 |     } | 
 | 1216 |  | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1217 |     /** {@hide} */ | 
 | 1218 |     public int[] supplyPukReportResult(String puk, String pin) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1219 |         return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1220 |     } | 
 | 1221 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1222 |     public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1223 |         enforceModifyPermission(); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1224 |         final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1225 |         checkSimPuk.start(); | 
 | 1226 |         return checkSimPuk.unlockSim(puk, pin); | 
 | 1227 |     } | 
 | 1228 |  | 
 | 1229 |     /** | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1230 |      * Helper thread to turn async call to SimCard#supplyPin into | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1231 |      * a synchronous one. | 
 | 1232 |      */ | 
 | 1233 |     private static class UnlockSim extends Thread { | 
 | 1234 |  | 
 | 1235 |         private final IccCard mSimCard; | 
 | 1236 |  | 
 | 1237 |         private boolean mDone = false; | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1238 |         private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; | 
 | 1239 |         private int mRetryCount = -1; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1240 |  | 
 | 1241 |         // For replies from SimCard interface | 
 | 1242 |         private Handler mHandler; | 
 | 1243 |  | 
 | 1244 |         // For async handler to identify request type | 
 | 1245 |         private static final int SUPPLY_PIN_COMPLETE = 100; | 
 | 1246 |  | 
 | 1247 |         public UnlockSim(IccCard simCard) { | 
 | 1248 |             mSimCard = simCard; | 
 | 1249 |         } | 
 | 1250 |  | 
 | 1251 |         @Override | 
 | 1252 |         public void run() { | 
 | 1253 |             Looper.prepare(); | 
 | 1254 |             synchronized (UnlockSim.this) { | 
 | 1255 |                 mHandler = new Handler() { | 
 | 1256 |                     @Override | 
 | 1257 |                     public void handleMessage(Message msg) { | 
 | 1258 |                         AsyncResult ar = (AsyncResult) msg.obj; | 
 | 1259 |                         switch (msg.what) { | 
 | 1260 |                             case SUPPLY_PIN_COMPLETE: | 
 | 1261 |                                 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); | 
 | 1262 |                                 synchronized (UnlockSim.this) { | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1263 |                                     mRetryCount = msg.arg1; | 
 | 1264 |                                     if (ar.exception != null) { | 
 | 1265 |                                         if (ar.exception instanceof CommandException && | 
 | 1266 |                                                 ((CommandException)(ar.exception)).getCommandError() | 
 | 1267 |                                                 == CommandException.Error.PASSWORD_INCORRECT) { | 
 | 1268 |                                             mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; | 
 | 1269 |                                         } else { | 
 | 1270 |                                             mResult = PhoneConstants.PIN_GENERAL_FAILURE; | 
 | 1271 |                                         } | 
 | 1272 |                                     } else { | 
 | 1273 |                                         mResult = PhoneConstants.PIN_RESULT_SUCCESS; | 
 | 1274 |                                     } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1275 |                                     mDone = true; | 
 | 1276 |                                     UnlockSim.this.notifyAll(); | 
 | 1277 |                                 } | 
 | 1278 |                                 break; | 
 | 1279 |                         } | 
 | 1280 |                     } | 
 | 1281 |                 }; | 
 | 1282 |                 UnlockSim.this.notifyAll(); | 
 | 1283 |             } | 
 | 1284 |             Looper.loop(); | 
 | 1285 |         } | 
 | 1286 |  | 
 | 1287 |         /* | 
 | 1288 |          * Use PIN or PUK to unlock SIM card | 
 | 1289 |          * | 
 | 1290 |          * If PUK is null, unlock SIM card with PIN | 
 | 1291 |          * | 
 | 1292 |          * If PUK is not null, unlock SIM card with PUK and set PIN code | 
 | 1293 |          */ | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1294 |         synchronized int[] unlockSim(String puk, String pin) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1295 |  | 
 | 1296 |             while (mHandler == null) { | 
 | 1297 |                 try { | 
 | 1298 |                     wait(); | 
 | 1299 |                 } catch (InterruptedException e) { | 
 | 1300 |                     Thread.currentThread().interrupt(); | 
 | 1301 |                 } | 
 | 1302 |             } | 
 | 1303 |             Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); | 
 | 1304 |  | 
 | 1305 |             if (puk == null) { | 
 | 1306 |                 mSimCard.supplyPin(pin, callback); | 
 | 1307 |             } else { | 
 | 1308 |                 mSimCard.supplyPuk(puk, pin, callback); | 
 | 1309 |             } | 
 | 1310 |  | 
 | 1311 |             while (!mDone) { | 
 | 1312 |                 try { | 
 | 1313 |                     Log.d(LOG_TAG, "wait for done"); | 
 | 1314 |                     wait(); | 
 | 1315 |                 } catch (InterruptedException e) { | 
 | 1316 |                     // Restore the interrupted status | 
 | 1317 |                     Thread.currentThread().interrupt(); | 
 | 1318 |                 } | 
 | 1319 |             } | 
 | 1320 |             Log.d(LOG_TAG, "done"); | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1321 |             int[] resultArray = new int[2]; | 
 | 1322 |             resultArray[0] = mResult; | 
 | 1323 |             resultArray[1] = mRetryCount; | 
 | 1324 |             return resultArray; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1325 |         } | 
 | 1326 |     } | 
 | 1327 |  | 
 | 1328 |     public void updateServiceLocation() { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1329 |         updateServiceLocationForSubscriber(getDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1330 |  | 
 | 1331 |     } | 
 | 1332 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1333 |     public void updateServiceLocationForSubscriber(int subId) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1334 |         // No permission check needed here: this call is harmless, and it's | 
 | 1335 |         // needed for the ServiceState.requestStateUpdate() call (which is | 
 | 1336 |         // already intentionally exposed to 3rd parties.) | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1337 |         final Phone phone = getPhone(subId); | 
 | 1338 |         if (phone != null) { | 
 | 1339 |             phone.updateServiceLocation(); | 
 | 1340 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1341 |     } | 
 | 1342 |  | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1343 |     @Override | 
 | 1344 |     public boolean isRadioOn(String callingPackage) { | 
 | 1345 |         return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1346 |     } | 
 | 1347 |  | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1348 |     @Override | 
 | 1349 |     public boolean isRadioOnForSubscriber(int subId, String callingPackage) { | 
 | 1350 |         if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) { | 
 | 1351 |             return false; | 
 | 1352 |         } | 
 | 1353 |         return isRadioOnForSubscriber(subId); | 
 | 1354 |     } | 
 | 1355 |  | 
 | 1356 |     private boolean isRadioOnForSubscriber(int subId) { | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1357 |         final Phone phone = getPhone(subId); | 
 | 1358 |         if (phone != null) { | 
 | 1359 |             return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; | 
 | 1360 |         } else { | 
 | 1361 |             return false; | 
 | 1362 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1363 |     } | 
 | 1364 |  | 
 | 1365 |     public void toggleRadioOnOff() { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1366 |         toggleRadioOnOffForSubscriber(getDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1367 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1368 |     } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1369 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1370 |     public void toggleRadioOnOffForSubscriber(int subId) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1371 |         enforceModifyPermission(); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1372 |         final Phone phone = getPhone(subId); | 
 | 1373 |         if (phone != null) { | 
 | 1374 |             phone.setRadioPower(!isRadioOnForSubscriber(subId)); | 
 | 1375 |         } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1376 |     } | 
 | 1377 |  | 
 | 1378 |     public boolean setRadio(boolean turnOn) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1379 |         return setRadioForSubscriber(getDefaultSubscription(), turnOn); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1380 |     } | 
 | 1381 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1382 |     public boolean setRadioForSubscriber(int subId, boolean turnOn) { | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1383 |         enforceModifyPermission(); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1384 |         final Phone phone = getPhone(subId); | 
 | 1385 |         if (phone == null) { | 
 | 1386 |             return false; | 
 | 1387 |         } | 
 | 1388 |         if ((phone.getServiceState().getState() != | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1389 |                 ServiceState.STATE_POWER_OFF) != turnOn) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1390 |             toggleRadioOnOffForSubscriber(subId); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1391 |         } | 
 | 1392 |         return true; | 
 | 1393 |     } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1394 |  | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1395 |     public boolean needMobileRadioShutdown() { | 
 | 1396 |         /* | 
 | 1397 |          * If any of the Radios are available, it will need to be | 
 | 1398 |          * shutdown. So return true if any Radio is available. | 
 | 1399 |          */ | 
 | 1400 |         for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { | 
 | 1401 |             Phone phone = PhoneFactory.getPhone(i); | 
 | 1402 |             if (phone != null && phone.isRadioAvailable()) return true; | 
 | 1403 |         } | 
 | 1404 |         logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); | 
 | 1405 |         return false; | 
 | 1406 |     } | 
 | 1407 |  | 
 | 1408 |     public void shutdownMobileRadios() { | 
 | 1409 |         for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { | 
 | 1410 |             logv("Shutting down Phone " + i); | 
 | 1411 |             shutdownRadioUsingPhoneId(i); | 
 | 1412 |         } | 
 | 1413 |     } | 
 | 1414 |  | 
 | 1415 |     private void shutdownRadioUsingPhoneId(int phoneId) { | 
 | 1416 |         enforceModifyPermission(); | 
 | 1417 |         Phone phone = PhoneFactory.getPhone(phoneId); | 
 | 1418 |         if (phone != null && phone.isRadioAvailable()) { | 
 | 1419 |             phone.shutdownRadio(); | 
 | 1420 |         } | 
 | 1421 |     } | 
 | 1422 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1423 |     public boolean setRadioPower(boolean turnOn) { | 
| Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1424 |         final Phone defaultPhone = PhoneFactory.getDefaultPhone(); | 
 | 1425 |         if (defaultPhone != null) { | 
 | 1426 |             defaultPhone.setRadioPower(turnOn); | 
 | 1427 |             return true; | 
 | 1428 |         } else { | 
 | 1429 |             loge("There's no default phone."); | 
 | 1430 |             return false; | 
 | 1431 |         } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1432 |     } | 
 | 1433 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1434 |     public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1435 |         enforceModifyPermission(); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1436 |         final Phone phone = getPhone(subId); | 
 | 1437 |         if (phone != null) { | 
 | 1438 |             phone.setRadioPower(turnOn); | 
 | 1439 |             return true; | 
 | 1440 |         } else { | 
 | 1441 |             return false; | 
 | 1442 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1443 |     } | 
 | 1444 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1445 |     // FIXME: subId version needed | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1446 |     @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1447 |     public boolean enableDataConnectivity() { | 
 | 1448 |         enforceModifyPermission(); | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1449 |         int subId = mSubscriptionController.getDefaultDataSubId(); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1450 |         final Phone phone = getPhone(subId); | 
 | 1451 |         if (phone != null) { | 
 | 1452 |             phone.setDataEnabled(true); | 
 | 1453 |             return true; | 
 | 1454 |         } else { | 
 | 1455 |             return false; | 
 | 1456 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1457 |     } | 
 | 1458 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1459 |     // FIXME: subId version needed | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1460 |     @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1461 |     public boolean disableDataConnectivity() { | 
 | 1462 |         enforceModifyPermission(); | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1463 |         int subId = mSubscriptionController.getDefaultDataSubId(); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1464 |         final Phone phone = getPhone(subId); | 
 | 1465 |         if (phone != null) { | 
 | 1466 |             phone.setDataEnabled(false); | 
 | 1467 |             return true; | 
 | 1468 |         } else { | 
 | 1469 |             return false; | 
 | 1470 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1471 |     } | 
 | 1472 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1473 |     // FIXME: subId version needed | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1474 |     @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1475 |     public boolean isDataConnectivityPossible() { | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1476 |         int subId = mSubscriptionController.getDefaultDataSubId(); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1477 |         final Phone phone = getPhone(subId); | 
 | 1478 |         if (phone != null) { | 
 | 1479 |             return phone.isDataConnectivityPossible(); | 
 | 1480 |         } else { | 
 | 1481 |             return false; | 
 | 1482 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1483 |     } | 
 | 1484 |  | 
 | 1485 |     public boolean handlePinMmi(String dialString) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1486 |         return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1487 |     } | 
 | 1488 |  | 
| pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1489 |     public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { | 
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1490 |       enforceCallPermission(); | 
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1491 |       if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
 | 1492 |           return; | 
 | 1493 |       } | 
 | 1494 |       Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); | 
 | 1495 |       sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); | 
 | 1496 |     }; | 
 | 1497 |  | 
 | 1498 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1499 |     public boolean handlePinMmiForSubscriber(int subId, String dialString) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1500 |         enforceModifyPermission(); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1501 |         if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
 | 1502 |             return false; | 
 | 1503 |         } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1504 |         return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1505 |     } | 
 | 1506 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1507 |     public int getCallState() { | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1508 |         return getCallStateForSlot(getSlotForDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1509 |     } | 
 | 1510 |  | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1511 |     public int getCallStateForSlot(int slotId) { | 
 | 1512 |         Phone phone = PhoneFactory.getPhone(slotId); | 
 | 1513 |         return phone == null ? TelephonyManager.CALL_STATE_IDLE : | 
 | 1514 |             DefaultPhoneNotifier.convertCallState(phone.getState()); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1515 |     } | 
 | 1516 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1517 |     @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1518 |     public int getDataState() { | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1519 |         Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1520 |         if (phone != null) { | 
 | 1521 |             return DefaultPhoneNotifier.convertDataState(phone.getDataConnectionState()); | 
 | 1522 |         } else { | 
 | 1523 |             return DefaultPhoneNotifier.convertDataState(PhoneConstants.DataState.DISCONNECTED); | 
 | 1524 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1525 |     } | 
 | 1526 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1527 |     @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1528 |     public int getDataActivity() { | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1529 |         Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1530 |         if (phone != null) { | 
 | 1531 |             return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); | 
 | 1532 |         } else { | 
 | 1533 |             return TelephonyManager.DATA_ACTIVITY_NONE; | 
 | 1534 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1535 |     } | 
 | 1536 |  | 
 | 1537 |     @Override | 
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1538 |     public Bundle getCellLocation(String callingPackage) { | 
 | 1539 |         enforceFineOrCoarseLocationPermission("getCellLocation"); | 
 | 1540 |  | 
 | 1541 |         // OP_COARSE_LOCATION controls both fine and coarse location. | 
 | 1542 |         if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(), | 
 | 1543 |                 callingPackage) != AppOpsManager.MODE_ALLOWED) { | 
| Amit Mahajan | 9acc70d | 2015-06-02 13:17:33 -0700 | [diff] [blame] | 1544 |             log("getCellLocation: returning null; mode != allowed"); | 
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1545 |             return null; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1546 |         } | 
 | 1547 |  | 
| Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 1548 |         if (checkIfCallerIsSelfOrForegroundUser() || | 
 | 1549 |                 checkCallerInteractAcrossUsersFull()) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1550 |             if (DBG_LOC) log("getCellLocation: is active user"); | 
 | 1551 |             Bundle data = new Bundle(); | 
| Legler Wu | 2c01cdf | 2014-12-08 19:00:59 +0800 | [diff] [blame] | 1552 |             Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1553 |             if (phone == null) { | 
 | 1554 |                 return null; | 
 | 1555 |             } | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 1556 |  | 
 | 1557 |             WorkSource workSource = getWorkSource(null, Binder.getCallingUid()); | 
 | 1558 |             phone.getCellLocation(workSource).fillInNotifierBundle(data); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1559 |             return data; | 
 | 1560 |         } else { | 
| Amit Mahajan | 9acc70d | 2015-06-02 13:17:33 -0700 | [diff] [blame] | 1561 |             log("getCellLocation: suppress non-active user"); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1562 |             return null; | 
 | 1563 |         } | 
 | 1564 |     } | 
 | 1565 |  | 
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1566 |     private void enforceFineOrCoarseLocationPermission(String message) { | 
 | 1567 |         try { | 
 | 1568 |             mApp.enforceCallingOrSelfPermission( | 
 | 1569 |                     android.Manifest.permission.ACCESS_FINE_LOCATION, null); | 
 | 1570 |         } catch (SecurityException e) { | 
 | 1571 |             // If we have ACCESS_FINE_LOCATION permission, skip the check for ACCESS_COARSE_LOCATION | 
 | 1572 |             // A failure should throw the SecurityException from ACCESS_COARSE_LOCATION since this | 
 | 1573 |             // is the weaker precondition | 
 | 1574 |             mApp.enforceCallingOrSelfPermission( | 
 | 1575 |                     android.Manifest.permission.ACCESS_COARSE_LOCATION, message); | 
 | 1576 |         } | 
 | 1577 |     } | 
 | 1578 |  | 
 | 1579 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1580 |     @Override | 
 | 1581 |     public void enableLocationUpdates() { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1582 |         enableLocationUpdatesForSubscriber(getDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1583 |     } | 
 | 1584 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1585 |     @Override | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1586 |     public void enableLocationUpdatesForSubscriber(int subId) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1587 |         mApp.enforceCallingOrSelfPermission( | 
 | 1588 |                 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1589 |         final Phone phone = getPhone(subId); | 
 | 1590 |         if (phone != null) { | 
 | 1591 |             phone.enableLocationUpdates(); | 
 | 1592 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1593 |     } | 
 | 1594 |  | 
 | 1595 |     @Override | 
 | 1596 |     public void disableLocationUpdates() { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1597 |         disableLocationUpdatesForSubscriber(getDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1598 |     } | 
 | 1599 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1600 |     @Override | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1601 |     public void disableLocationUpdatesForSubscriber(int subId) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1602 |         mApp.enforceCallingOrSelfPermission( | 
 | 1603 |                 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1604 |         final Phone phone = getPhone(subId); | 
 | 1605 |         if (phone != null) { | 
 | 1606 |             phone.disableLocationUpdates(); | 
 | 1607 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1608 |     } | 
 | 1609 |  | 
 | 1610 |     @Override | 
 | 1611 |     @SuppressWarnings("unchecked") | 
 | 1612 |     public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { | 
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1613 |         enforceFineOrCoarseLocationPermission("getNeighboringCellInfo"); | 
 | 1614 |  | 
 | 1615 |         // OP_COARSE_LOCATION controls both fine and coarse location. | 
 | 1616 |         if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(), | 
 | 1617 |                 callingPackage) != AppOpsManager.MODE_ALLOWED) { | 
 | 1618 |             return null; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1619 |         } | 
 | 1620 |  | 
 | 1621 |         if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), | 
 | 1622 |                 callingPackage) != AppOpsManager.MODE_ALLOWED) { | 
 | 1623 |             return null; | 
 | 1624 |         } | 
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1625 |  | 
| Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 1626 |         if (checkIfCallerIsSelfOrForegroundUser() || | 
 | 1627 |                 checkCallerInteractAcrossUsersFull()) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1628 |             if (DBG_LOC) log("getNeighboringCellInfo: is active user"); | 
 | 1629 |  | 
 | 1630 |             ArrayList<NeighboringCellInfo> cells = null; | 
 | 1631 |  | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 1632 |             WorkSource workSource = getWorkSource(null, Binder.getCallingUid()); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1633 |             try { | 
 | 1634 |                 cells = (ArrayList<NeighboringCellInfo>) sendRequest( | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 1635 |                         CMD_HANDLE_NEIGHBORING_CELL, workSource, | 
| Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 1636 |                         SubscriptionManager.INVALID_SUBSCRIPTION_ID); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1637 |             } catch (RuntimeException e) { | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1638 |                 Log.e(LOG_TAG, "getNeighboringCellInfo " + e); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1639 |             } | 
 | 1640 |             return cells; | 
 | 1641 |         } else { | 
 | 1642 |             if (DBG_LOC) log("getNeighboringCellInfo: suppress non-active user"); | 
 | 1643 |             return null; | 
 | 1644 |         } | 
 | 1645 |     } | 
 | 1646 |  | 
 | 1647 |  | 
 | 1648 |     @Override | 
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1649 |     public List<CellInfo> getAllCellInfo(String callingPackage) { | 
 | 1650 |         enforceFineOrCoarseLocationPermission("getAllCellInfo"); | 
 | 1651 |  | 
 | 1652 |         // OP_COARSE_LOCATION controls both fine and coarse location. | 
 | 1653 |         if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(), | 
 | 1654 |                 callingPackage) != AppOpsManager.MODE_ALLOWED) { | 
 | 1655 |             return null; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1656 |         } | 
 | 1657 |  | 
| Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 1658 |         if (checkIfCallerIsSelfOrForegroundUser() || | 
 | 1659 |                 checkCallerInteractAcrossUsersFull()) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1660 |             if (DBG_LOC) log("getAllCellInfo: is active user"); | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 1661 |             WorkSource workSource = getWorkSource(null, Binder.getCallingUid()); | 
| Legler Wu | 2c01cdf | 2014-12-08 19:00:59 +0800 | [diff] [blame] | 1662 |             List<CellInfo> cellInfos = new ArrayList<CellInfo>(); | 
 | 1663 |             for (Phone phone : PhoneFactory.getPhones()) { | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 1664 |                 final List<CellInfo> info = phone.getAllCellInfo(workSource); | 
 | 1665 |                 if (info != null) cellInfos.addAll(info); | 
| Legler Wu | 2c01cdf | 2014-12-08 19:00:59 +0800 | [diff] [blame] | 1666 |             } | 
 | 1667 |             return cellInfos; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1668 |         } else { | 
 | 1669 |             if (DBG_LOC) log("getAllCellInfo: suppress non-active user"); | 
 | 1670 |             return null; | 
 | 1671 |         } | 
 | 1672 |     } | 
 | 1673 |  | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1674 |     @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1675 |     public void setCellInfoListRate(int rateInMillis) { | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 1676 |         WorkSource workSource = getWorkSource(null, Binder.getCallingUid()); | 
 | 1677 |         mPhone.setCellInfoListRate(rateInMillis, workSource); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1678 |     } | 
 | 1679 |  | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1680 |     @Override | 
 | 1681 |     public String getImeiForSlot(int slotId, String callingPackage) { | 
 | 1682 |       if (!canReadPhoneState(callingPackage, "getImeiForSlot")) { | 
 | 1683 |           return null; | 
 | 1684 |       } | 
 | 1685 |       Phone phone = PhoneFactory.getPhone(slotId); | 
 | 1686 |       return phone == null ? null : phone.getImei(); | 
 | 1687 |     } | 
 | 1688 |  | 
 | 1689 |     @Override | 
 | 1690 |     public String getDeviceSoftwareVersionForSlot(int slotId, String callingPackage) { | 
 | 1691 |       if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) { | 
 | 1692 |           return null; | 
 | 1693 |       } | 
 | 1694 |       Phone phone = PhoneFactory.getPhone(slotId); | 
 | 1695 |       return phone == null ? null : phone.getDeviceSvn(); | 
 | 1696 |     } | 
 | 1697 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1698 |     // | 
 | 1699 |     // Internal helper methods. | 
 | 1700 |     // | 
 | 1701 |  | 
| Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 1702 |     /** | 
 | 1703 |      * Returns true if the caller holds INTERACT_ACROSS_USERS_FULL. | 
 | 1704 |      */ | 
 | 1705 |     private boolean checkCallerInteractAcrossUsersFull() { | 
 | 1706 |         return mPhone.getContext().checkCallingOrSelfPermission( | 
 | 1707 |                 android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) | 
 | 1708 |                 == PackageManager.PERMISSION_GRANTED; | 
 | 1709 |     } | 
 | 1710 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1711 |     private static boolean checkIfCallerIsSelfOrForegroundUser() { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1712 |         boolean ok; | 
 | 1713 |  | 
 | 1714 |         boolean self = Binder.getCallingUid() == Process.myUid(); | 
 | 1715 |         if (!self) { | 
 | 1716 |             // Get the caller's user id then clear the calling identity | 
 | 1717 |             // which will be restored in the finally clause. | 
 | 1718 |             int callingUser = UserHandle.getCallingUserId(); | 
 | 1719 |             long ident = Binder.clearCallingIdentity(); | 
 | 1720 |  | 
 | 1721 |             try { | 
 | 1722 |                 // With calling identity cleared the current user is the foreground user. | 
 | 1723 |                 int foregroundUser = ActivityManager.getCurrentUser(); | 
 | 1724 |                 ok = (foregroundUser == callingUser); | 
 | 1725 |                 if (DBG_LOC) { | 
 | 1726 |                     log("checkIfCallerIsSelfOrForegoundUser: foregroundUser=" + foregroundUser | 
 | 1727 |                             + " callingUser=" + callingUser + " ok=" + ok); | 
 | 1728 |                 } | 
 | 1729 |             } catch (Exception ex) { | 
 | 1730 |                 if (DBG_LOC) loge("checkIfCallerIsSelfOrForegoundUser: Exception ex=" + ex); | 
 | 1731 |                 ok = false; | 
 | 1732 |             } finally { | 
 | 1733 |                 Binder.restoreCallingIdentity(ident); | 
 | 1734 |             } | 
 | 1735 |         } else { | 
 | 1736 |             if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: is self"); | 
 | 1737 |             ok = true; | 
 | 1738 |         } | 
 | 1739 |         if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: ret=" + ok); | 
 | 1740 |         return ok; | 
 | 1741 |     } | 
 | 1742 |  | 
 | 1743 |     /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1744 |      * Make sure the caller has the MODIFY_PHONE_STATE permission. | 
 | 1745 |      * | 
 | 1746 |      * @throws SecurityException if the caller does not have the required permission | 
 | 1747 |      */ | 
 | 1748 |     private void enforceModifyPermission() { | 
 | 1749 |         mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); | 
 | 1750 |     } | 
 | 1751 |  | 
 | 1752 |     /** | 
| Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1753 |      * Make sure either system app or the caller has carrier privilege. | 
 | 1754 |      * | 
 | 1755 |      * @throws SecurityException if the caller does not have the required permission/privilege | 
 | 1756 |      */ | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1757 |     private void enforceModifyPermissionOrCarrierPrivilege(int subId) { | 
| Shishir Agrawal | f1ac4c9 | 2014-07-14 13:54:28 -0700 | [diff] [blame] | 1758 |         int permission = mApp.checkCallingOrSelfPermission( | 
 | 1759 |                 android.Manifest.permission.MODIFY_PHONE_STATE); | 
 | 1760 |         if (permission == PackageManager.PERMISSION_GRANTED) { | 
 | 1761 |             return; | 
 | 1762 |         } | 
 | 1763 |  | 
 | 1764 |         log("No modify permission, check carrier privilege next."); | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1765 |         enforceCarrierPrivilege(subId); | 
| Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1766 |     } | 
 | 1767 |  | 
 | 1768 |     /** | 
 | 1769 |      * Make sure the caller has carrier privilege. | 
 | 1770 |      * | 
 | 1771 |      * @throws SecurityException if the caller does not have the required permission | 
 | 1772 |      */ | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1773 |     private void enforceCarrierPrivilege(int subId) { | 
 | 1774 |         if (getCarrierPrivilegeStatus(subId) != | 
 | 1775 |                     TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { | 
| Shishir Agrawal | f1ac4c9 | 2014-07-14 13:54:28 -0700 | [diff] [blame] | 1776 |             loge("No Carrier Privilege."); | 
 | 1777 |             throw new SecurityException("No Carrier Privilege."); | 
| Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1778 |         } | 
 | 1779 |     } | 
 | 1780 |  | 
 | 1781 |     /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1782 |      * Make sure the caller has the CALL_PHONE permission. | 
 | 1783 |      * | 
 | 1784 |      * @throws SecurityException if the caller does not have the required permission | 
 | 1785 |      */ | 
 | 1786 |     private void enforceCallPermission() { | 
 | 1787 |         mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); | 
 | 1788 |     } | 
 | 1789 |  | 
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 1790 |     private void enforceConnectivityInternalPermission() { | 
 | 1791 |         mApp.enforceCallingOrSelfPermission( | 
 | 1792 |                 android.Manifest.permission.CONNECTIVITY_INTERNAL, | 
 | 1793 |                 "ConnectivityService"); | 
 | 1794 |     } | 
 | 1795 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1796 |     private String createTelUrl(String number) { | 
 | 1797 |         if (TextUtils.isEmpty(number)) { | 
 | 1798 |             return null; | 
 | 1799 |         } | 
 | 1800 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1801 |         return "tel:" + number; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1802 |     } | 
 | 1803 |  | 
| Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 1804 |     private static void log(String msg) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1805 |         Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); | 
 | 1806 |     } | 
 | 1807 |  | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1808 |     private static void logv(String msg) { | 
 | 1809 |         Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); | 
 | 1810 |     } | 
 | 1811 |  | 
| Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 1812 |     private static void loge(String msg) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1813 |         Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); | 
 | 1814 |     } | 
 | 1815 |  | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1816 |     @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1817 |     public int getActivePhoneType() { | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1818 |         return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1819 |     } | 
 | 1820 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1821 |     @Override | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1822 |     public int getActivePhoneTypeForSlot(int slotId) { | 
 | 1823 |         final Phone phone = PhoneFactory.getPhone(slotId); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1824 |         if (phone == null) { | 
 | 1825 |             return PhoneConstants.PHONE_TYPE_NONE; | 
 | 1826 |         } else { | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1827 |             return phone.getPhoneType(); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1828 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1829 |     } | 
 | 1830 |  | 
 | 1831 |     /** | 
 | 1832 |      * Returns the CDMA ERI icon index to display | 
 | 1833 |      */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1834 |     @Override | 
 | 1835 |     public int getCdmaEriIconIndex(String callingPackage) { | 
 | 1836 |         return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1837 |     } | 
 | 1838 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1839 |     @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1840 |     public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { | 
 | 1841 |         if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) { | 
 | 1842 |             return -1; | 
 | 1843 |         } | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1844 |         final Phone phone = getPhone(subId); | 
 | 1845 |         if (phone != null) { | 
 | 1846 |             return phone.getCdmaEriIconIndex(); | 
 | 1847 |         } else { | 
 | 1848 |             return -1; | 
 | 1849 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1850 |     } | 
 | 1851 |  | 
 | 1852 |     /** | 
 | 1853 |      * Returns the CDMA ERI icon mode, | 
 | 1854 |      * 0 - ON | 
 | 1855 |      * 1 - FLASHING | 
 | 1856 |      */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1857 |     @Override | 
 | 1858 |     public int getCdmaEriIconMode(String callingPackage) { | 
 | 1859 |         return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1860 |     } | 
 | 1861 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1862 |     @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1863 |     public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { | 
 | 1864 |         if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) { | 
 | 1865 |             return -1; | 
 | 1866 |         } | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1867 |         final Phone phone = getPhone(subId); | 
 | 1868 |         if (phone != null) { | 
 | 1869 |             return phone.getCdmaEriIconMode(); | 
 | 1870 |         } else { | 
 | 1871 |             return -1; | 
 | 1872 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1873 |     } | 
 | 1874 |  | 
 | 1875 |     /** | 
 | 1876 |      * Returns the CDMA ERI text, | 
 | 1877 |      */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1878 |     @Override | 
 | 1879 |     public String getCdmaEriText(String callingPackage) { | 
 | 1880 |         return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1881 |     } | 
 | 1882 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1883 |     @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1884 |     public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { | 
 | 1885 |         if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) { | 
 | 1886 |             return null; | 
 | 1887 |         } | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1888 |         final Phone phone = getPhone(subId); | 
 | 1889 |         if (phone != null) { | 
 | 1890 |             return phone.getCdmaEriText(); | 
 | 1891 |         } else { | 
 | 1892 |             return null; | 
 | 1893 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1894 |     } | 
 | 1895 |  | 
 | 1896 |     /** | 
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 1897 |      * Returns the CDMA MDN. | 
 | 1898 |      */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1899 |     @Override | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1900 |     public String getCdmaMdn(int subId) { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1901 |         enforceModifyPermissionOrCarrierPrivilege(subId); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1902 |         final Phone phone = getPhone(subId); | 
 | 1903 |         if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) { | 
 | 1904 |             return phone.getLine1Number(); | 
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 1905 |         } else { | 
 | 1906 |             return null; | 
 | 1907 |         } | 
 | 1908 |     } | 
 | 1909 |  | 
 | 1910 |     /** | 
 | 1911 |      * Returns the CDMA MIN. | 
 | 1912 |      */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1913 |     @Override | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1914 |     public String getCdmaMin(int subId) { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1915 |         enforceModifyPermissionOrCarrierPrivilege(subId); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1916 |         final Phone phone = getPhone(subId); | 
 | 1917 |         if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { | 
 | 1918 |             return phone.getCdmaMin(); | 
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 1919 |         } else { | 
 | 1920 |             return null; | 
 | 1921 |         } | 
 | 1922 |     } | 
 | 1923 |  | 
 | 1924 |     /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1925 |      * Returns true if CDMA provisioning needs to run. | 
 | 1926 |      */ | 
 | 1927 |     public boolean needsOtaServiceProvisioning() { | 
 | 1928 |         return mPhone.needsOtaServiceProvisioning(); | 
 | 1929 |     } | 
 | 1930 |  | 
 | 1931 |     /** | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1932 |      * Sets the voice mail number of a given subId. | 
 | 1933 |      */ | 
 | 1934 |     @Override | 
 | 1935 |     public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1936 |         enforceCarrierPrivilege(subId); | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1937 |         Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, | 
 | 1938 |                 new Pair<String, String>(alphaTag, number), new Integer(subId)); | 
 | 1939 |         return success; | 
 | 1940 |     } | 
 | 1941 |  | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 1942 |     @Override | 
| Ta-wei Yen | b0f695b | 2016-08-08 17:33:11 -0700 | [diff] [blame] | 1943 |     public void setVisualVoicemailEnabled(String callingPackage, | 
 | 1944 |             PhoneAccountHandle phoneAccountHandle, boolean enabled) { | 
 | 1945 |         mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
 | 1946 |         if (!TextUtils.equals(callingPackage, | 
 | 1947 |                 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) { | 
 | 1948 |             enforceModifyPermissionOrCarrierPrivilege( | 
 | 1949 |                     PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle)); | 
 | 1950 |         } | 
 | 1951 |         VisualVoicemailSettingsUtil.setEnabled(mPhone.getContext(), phoneAccountHandle, enabled); | 
 | 1952 |     } | 
 | 1953 |  | 
 | 1954 |     @Override | 
 | 1955 |     public boolean isVisualVoicemailEnabled(String callingPackage, | 
 | 1956 |             PhoneAccountHandle phoneAccountHandle) { | 
 | 1957 |         if (!canReadPhoneState(callingPackage, "isVisualVoicemailEnabled")) { | 
 | 1958 |             return false; | 
 | 1959 |         } | 
 | 1960 |         return VisualVoicemailSettingsUtil.isEnabled(mPhone.getContext(), phoneAccountHandle); | 
 | 1961 |     } | 
 | 1962 |  | 
 | 1963 |     @Override | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 1964 |     public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, | 
 | 1965 |             VisualVoicemailSmsFilterSettings settings) { | 
 | 1966 |         mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 1967 |         VisualVoicemailSmsFilterConfig | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 1968 |                 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId, | 
 | 1969 |                         settings); | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 1970 |     } | 
 | 1971 |  | 
 | 1972 |     @Override | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 1973 |     public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { | 
 | 1974 |         mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 1975 |         VisualVoicemailSmsFilterConfig | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 1976 |                 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId); | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 1977 |     } | 
 | 1978 |  | 
 | 1979 |     @Override | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 1980 |     public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( | 
 | 1981 |             String callingPackage, int subId) { | 
 | 1982 |         mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 1983 |         return VisualVoicemailSmsFilterConfig | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 1984 |                 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId); | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 1985 |     } | 
 | 1986 |  | 
 | 1987 |     @Override | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 1988 |     public VisualVoicemailSmsFilterSettings getSystemVisualVoicemailSmsFilterSettings( | 
 | 1989 |             String packageName, int subId) { | 
 | 1990 |         enforceReadPrivilegedPermission(); | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 1991 |         return VisualVoicemailSmsFilterConfig | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 1992 |                 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), packageName, subId); | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 1993 |     } | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1994 |     /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1995 |      * Returns the unread count of voicemails | 
 | 1996 |      */ | 
 | 1997 |     public int getVoiceMessageCount() { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1998 |         return getVoiceMessageCountForSubscriber(getDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1999 |     } | 
 | 2000 |  | 
 | 2001 |     /** | 
 | 2002 |      * Returns the unread count of voicemails for a subId | 
 | 2003 |      */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2004 |     @Override | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2005 |     public int getVoiceMessageCountForSubscriber( int subId) { | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2006 |         final Phone phone = getPhone(subId); | 
 | 2007 |         if (phone != null) { | 
 | 2008 |             return phone.getVoiceMessageCount(); | 
 | 2009 |         } else { | 
 | 2010 |             return 0; | 
 | 2011 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2012 |     } | 
 | 2013 |  | 
 | 2014 |     /** | 
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2015 |      * Returns the data network type. | 
 | 2016 |      * Legacy call, permission-free. | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2017 |      * | 
 | 2018 |      * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}. | 
 | 2019 |      */ | 
 | 2020 |     @Override | 
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2021 |     public int getNetworkType() { | 
 | 2022 |         final Phone phone = getPhone(getDefaultSubscription()); | 
 | 2023 |         if (phone != null) { | 
 | 2024 |             return phone.getServiceState().getDataNetworkType(); | 
 | 2025 |         } else { | 
 | 2026 |             return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
 | 2027 |         } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2028 |     } | 
 | 2029 |  | 
 | 2030 |     /** | 
 | 2031 |      * Returns the network type for a subId | 
 | 2032 |      */ | 
 | 2033 |     @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2034 |     public int getNetworkTypeForSubscriber(int subId, String callingPackage) { | 
 | 2035 |         if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) { | 
 | 2036 |             return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
 | 2037 |         } | 
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2038 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2039 |         final Phone phone = getPhone(subId); | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2040 |         if (phone != null) { | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2041 |             return phone.getServiceState().getDataNetworkType(); | 
 | 2042 |         } else { | 
 | 2043 |             return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
 | 2044 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2045 |     } | 
 | 2046 |  | 
 | 2047 |     /** | 
 | 2048 |      * Returns the data network type | 
 | 2049 |      */ | 
 | 2050 |     @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2051 |     public int getDataNetworkType(String callingPackage) { | 
 | 2052 |         return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2053 |     } | 
 | 2054 |  | 
 | 2055 |     /** | 
 | 2056 |      * Returns the data network type for a subId | 
 | 2057 |      */ | 
 | 2058 |     @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2059 |     public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { | 
 | 2060 |         if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) { | 
 | 2061 |             return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
 | 2062 |         } | 
 | 2063 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2064 |         final Phone phone = getPhone(subId); | 
 | 2065 |         if (phone != null) { | 
 | 2066 |             return phone.getServiceState().getDataNetworkType(); | 
 | 2067 |         } else { | 
 | 2068 |             return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
 | 2069 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2070 |     } | 
 | 2071 |  | 
 | 2072 |     /** | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2073 |      * Returns the Voice network type for a subId | 
 | 2074 |      */ | 
 | 2075 |     @Override | 
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2076 |     public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { | 
 | 2077 |         if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) { | 
 | 2078 |             return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
 | 2079 |         } | 
 | 2080 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2081 |         final Phone phone = getPhone(subId); | 
 | 2082 |         if (phone != null) { | 
 | 2083 |             return phone.getServiceState().getVoiceNetworkType(); | 
 | 2084 |         } else { | 
 | 2085 |             return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
 | 2086 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2087 |     } | 
 | 2088 |  | 
 | 2089 |     /** | 
 | 2090 |      * @return true if a ICC card is present | 
 | 2091 |      */ | 
 | 2092 |     public boolean hasIccCard() { | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2093 |         // FIXME Make changes to pass defaultSimId of type int | 
| Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 2094 |         return hasIccCardUsingSlotId(mSubscriptionController.getSlotId(getDefaultSubscription())); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2095 |     } | 
 | 2096 |  | 
 | 2097 |     /** | 
 | 2098 |      * @return true if a ICC card is present for a slotId | 
 | 2099 |      */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2100 |     @Override | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2101 |     public boolean hasIccCardUsingSlotId(int slotId) { | 
| fionaxu | 6e6c68b | 2016-06-23 13:31:32 -0700 | [diff] [blame] | 2102 |         final Phone phone = PhoneFactory.getPhone(slotId); | 
 | 2103 |         if (phone != null) { | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2104 |             return phone.getIccCard().hasIccCard(); | 
| Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 2105 |         } else { | 
 | 2106 |             return false; | 
 | 2107 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2108 |     } | 
 | 2109 |  | 
 | 2110 |     /** | 
 | 2111 |      * Return if the current radio is LTE on CDMA. This | 
 | 2112 |      * is a tri-state return value as for a period of time | 
 | 2113 |      * the mode may be unknown. | 
 | 2114 |      * | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2115 |      * @param callingPackage the name of the package making the call. | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2116 |      * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE} | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2117 |      * or {@link Phone#LTE_ON_CDMA_TRUE} | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2118 |      */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2119 |     @Override | 
 | 2120 |     public int getLteOnCdmaMode(String callingPackage) { | 
 | 2121 |         return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2122 |     } | 
 | 2123 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2124 |     @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2125 |     public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { | 
 | 2126 |         if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) { | 
 | 2127 |             return PhoneConstants.LTE_ON_CDMA_UNKNOWN; | 
 | 2128 |         } | 
 | 2129 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2130 |         final Phone phone = getPhone(subId); | 
 | 2131 |         if (phone == null) { | 
 | 2132 |             return PhoneConstants.LTE_ON_CDMA_UNKNOWN; | 
 | 2133 |         } else { | 
 | 2134 |             return phone.getLteOnCdmaMode(); | 
 | 2135 |         } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2136 |     } | 
 | 2137 |  | 
 | 2138 |     public void setPhone(Phone phone) { | 
 | 2139 |         mPhone = phone; | 
 | 2140 |     } | 
 | 2141 |  | 
 | 2142 |     /** | 
 | 2143 |      * {@hide} | 
 | 2144 |      * Returns Default subId, 0 in the case of single standby. | 
 | 2145 |      */ | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2146 |     private int getDefaultSubscription() { | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2147 |         return mSubscriptionController.getDefaultSubId(); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2148 |     } | 
 | 2149 |  | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2150 |     private int getSlotForDefaultSubscription() { | 
 | 2151 |         return mSubscriptionController.getPhoneId(getDefaultSubscription()); | 
 | 2152 |     } | 
 | 2153 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2154 |     private int getPreferredVoiceSubscription() { | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2155 |         return mSubscriptionController.getDefaultVoiceSubId(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2156 |     } | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 2157 |  | 
 | 2158 |     /** | 
 | 2159 |      * @see android.telephony.TelephonyManager.WifiCallingChoices | 
 | 2160 |      */ | 
 | 2161 |     public int getWhenToMakeWifiCalls() { | 
| Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 2162 |         return Settings.System.getInt(mPhone.getContext().getContentResolver(), | 
 | 2163 |                 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference()); | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 2164 |     } | 
 | 2165 |  | 
 | 2166 |     /** | 
 | 2167 |      * @see android.telephony.TelephonyManager.WifiCallingChoices | 
 | 2168 |      */ | 
 | 2169 |     public void setWhenToMakeWifiCalls(int preference) { | 
| Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 2170 |         if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); | 
 | 2171 |         Settings.System.putInt(mPhone.getContext().getContentResolver(), | 
 | 2172 |                 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); | 
| Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2173 |     } | 
 | 2174 |  | 
| Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 2175 |     private static int getWhenToMakeWifiCallsDefaultPreference() { | 
| Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 2176 |         // TODO: Use a build property to choose this value. | 
| Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 2177 |         return TelephonyManager.WifiCallingChoices.ALWAYS_USE; | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 2178 |     } | 
| Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 2179 |  | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2180 |     @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2181 |     public IccOpenLogicalChannelResponse iccOpenLogicalChannel(int subId, String AID) { | 
 | 2182 |         enforceModifyPermissionOrCarrierPrivilege(subId); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2183 |  | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2184 |         if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + AID); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2185 |         IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest( | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2186 |             CMD_OPEN_CHANNEL, AID, subId); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2187 |         if (DBG) log("iccOpenLogicalChannel: " + response); | 
 | 2188 |         return response; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2189 |     } | 
 | 2190 |  | 
 | 2191 |     @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2192 |     public boolean iccCloseLogicalChannel(int subId, int channel) { | 
 | 2193 |         enforceModifyPermissionOrCarrierPrivilege(subId); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2194 |  | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2195 |         if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2196 |         if (channel < 0) { | 
 | 2197 |           return false; | 
 | 2198 |         } | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2199 |         Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2200 |         if (DBG) log("iccCloseLogicalChannel: " + success); | 
 | 2201 |         return success; | 
 | 2202 |     } | 
 | 2203 |  | 
 | 2204 |     @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2205 |     public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2206 |             int command, int p1, int p2, int p3, String data) { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2207 |         enforceModifyPermissionOrCarrierPrivilege(subId); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2208 |  | 
 | 2209 |         if (DBG) { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2210 |             log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel + | 
 | 2211 |                     " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2212 |                     " data=" + data); | 
 | 2213 |         } | 
 | 2214 |  | 
 | 2215 |         if (channel < 0) { | 
 | 2216 |             return ""; | 
 | 2217 |         } | 
 | 2218 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2219 |         IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2220 |                 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2221 |         if (DBG) log("iccTransmitApduLogicalChannel: " + response); | 
 | 2222 |  | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2223 |         // Append the returned status code to the end of the response payload. | 
 | 2224 |         String s = Integer.toHexString( | 
 | 2225 |                 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); | 
| Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 2226 |         if (response.payload != null) { | 
 | 2227 |             s = IccUtils.bytesToHexString(response.payload) + s; | 
 | 2228 |         } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2229 |         return s; | 
 | 2230 |     } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2231 |  | 
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 2232 |     @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2233 |     public String iccTransmitApduBasicChannel(int subId, int cla, int command, int p1, int p2, | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2234 |                 int p3, String data) { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2235 |         enforceModifyPermissionOrCarrierPrivilege(subId); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2236 |  | 
 | 2237 |         if (DBG) { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2238 |             log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command | 
 | 2239 |                     + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2240 |         } | 
 | 2241 |  | 
 | 2242 |         IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2243 |                 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2244 |         if (DBG) log("iccTransmitApduBasicChannel: " + response); | 
 | 2245 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2246 |         // Append the returned status code to the end of the response payload. | 
 | 2247 |         String s = Integer.toHexString( | 
 | 2248 |                 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); | 
| Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 2249 |         if (response.payload != null) { | 
 | 2250 |             s = IccUtils.bytesToHexString(response.payload) + s; | 
 | 2251 |         } | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2252 |         return s; | 
 | 2253 |     } | 
 | 2254 |  | 
 | 2255 |     @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2256 |     public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3, | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2257 |             String filePath) { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2258 |         enforceModifyPermissionOrCarrierPrivilege(subId); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2259 |  | 
 | 2260 |         if (DBG) { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2261 |             log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " + | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2262 |                 p1 + " " + p2 + " " + p3 + ":" + filePath); | 
 | 2263 |         } | 
 | 2264 |  | 
 | 2265 |         IccIoResult response = | 
 | 2266 |             (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO, | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2267 |                     new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), | 
 | 2268 |                     subId); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2269 |  | 
 | 2270 |         if (DBG) { | 
 | 2271 |           log("Exchange SIM_IO [R]" + response); | 
 | 2272 |         } | 
 | 2273 |  | 
 | 2274 |         byte[] result = null; | 
 | 2275 |         int length = 2; | 
 | 2276 |         if (response.payload != null) { | 
 | 2277 |             length = 2 + response.payload.length; | 
 | 2278 |             result = new byte[length]; | 
 | 2279 |             System.arraycopy(response.payload, 0, result, 0, response.payload.length); | 
 | 2280 |         } else { | 
 | 2281 |             result = new byte[length]; | 
 | 2282 |         } | 
 | 2283 |  | 
 | 2284 |         result[length - 1] = (byte) response.sw2; | 
 | 2285 |         result[length - 2] = (byte) response.sw1; | 
 | 2286 |         return result; | 
 | 2287 |     } | 
 | 2288 |  | 
 | 2289 |     @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2290 |     public String sendEnvelopeWithStatus(int subId, String content) { | 
 | 2291 |         enforceModifyPermissionOrCarrierPrivilege(subId); | 
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 2292 |  | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2293 |         IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId); | 
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 2294 |         if (response.payload == null) { | 
 | 2295 |           return ""; | 
 | 2296 |         } | 
 | 2297 |  | 
 | 2298 |         // Append the returned status code to the end of the response payload. | 
 | 2299 |         String s = Integer.toHexString( | 
 | 2300 |                 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); | 
 | 2301 |         s = IccUtils.bytesToHexString(response.payload) + s; | 
 | 2302 |         return s; | 
 | 2303 |     } | 
 | 2304 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2305 |     /** | 
 | 2306 |      * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} | 
 | 2307 |      * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. | 
 | 2308 |      * | 
 | 2309 |      * @param itemID the ID of the item to read | 
 | 2310 |      * @return the NV item as a String, or null on error. | 
 | 2311 |      */ | 
 | 2312 |     @Override | 
 | 2313 |     public String nvReadItem(int itemID) { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2314 |         enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription()); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2315 |         if (DBG) log("nvReadItem: item " + itemID); | 
 | 2316 |         String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID); | 
 | 2317 |         if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); | 
 | 2318 |         return value; | 
 | 2319 |     } | 
 | 2320 |  | 
 | 2321 |     /** | 
 | 2322 |      * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} | 
 | 2323 |      * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. | 
 | 2324 |      * | 
 | 2325 |      * @param itemID the ID of the item to read | 
 | 2326 |      * @param itemValue the value to write, as a String | 
 | 2327 |      * @return true on success; false on any failure | 
 | 2328 |      */ | 
 | 2329 |     @Override | 
 | 2330 |     public boolean nvWriteItem(int itemID, String itemValue) { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2331 |         enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription()); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2332 |         if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); | 
 | 2333 |         Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, | 
 | 2334 |                 new Pair<Integer, String>(itemID, itemValue)); | 
 | 2335 |         if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); | 
 | 2336 |         return success; | 
 | 2337 |     } | 
 | 2338 |  | 
 | 2339 |     /** | 
 | 2340 |      * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. | 
 | 2341 |      * Used for device configuration by some CDMA operators. | 
 | 2342 |      * | 
 | 2343 |      * @param preferredRoamingList byte array containing the new PRL | 
 | 2344 |      * @return true on success; false on any failure | 
 | 2345 |      */ | 
 | 2346 |     @Override | 
 | 2347 |     public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2348 |         enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription()); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2349 |         if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); | 
 | 2350 |         Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); | 
 | 2351 |         if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); | 
 | 2352 |         return success; | 
 | 2353 |     } | 
 | 2354 |  | 
 | 2355 |     /** | 
 | 2356 |      * Perform the specified type of NV config reset. | 
 | 2357 |      * Used for device configuration by some CDMA operators. | 
 | 2358 |      * | 
 | 2359 |      * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset) | 
 | 2360 |      * @return true on success; false on any failure | 
 | 2361 |      */ | 
 | 2362 |     @Override | 
 | 2363 |     public boolean nvResetConfig(int resetType) { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2364 |         enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription()); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2365 |         if (DBG) log("nvResetConfig: type " + resetType); | 
 | 2366 |         Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType); | 
 | 2367 |         if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail")); | 
 | 2368 |         return success; | 
 | 2369 |     } | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 2370 |  | 
 | 2371 |     /** | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2372 |      * {@hide} | 
 | 2373 |      * Returns Default sim, 0 in the case of single standby. | 
 | 2374 |      */ | 
 | 2375 |     public int getDefaultSim() { | 
 | 2376 |         //TODO Need to get it from Telephony Devcontroller | 
 | 2377 |         return 0; | 
 | 2378 |     } | 
 | 2379 |  | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 2380 |     public String[] getPcscfAddress(String apnType, String callingPackage) { | 
 | 2381 |         if (!canReadPhoneState(callingPackage, "getPcscfAddress")) { | 
 | 2382 |             return new String[0]; | 
 | 2383 |         } | 
 | 2384 |  | 
 | 2385 |  | 
| ram | 87fca6f | 2014-07-18 18:58:44 +0530 | [diff] [blame] | 2386 |         return mPhone.getPcscfAddress(apnType); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2387 |     } | 
 | 2388 |  | 
 | 2389 |     public void setImsRegistrationState(boolean registered) { | 
 | 2390 |         enforceModifyPermission(); | 
 | 2391 |         mPhone.setImsRegistrationState(registered); | 
 | 2392 |     } | 
 | 2393 |  | 
 | 2394 |     /** | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 2395 |      * Set the network selection mode to automatic. | 
 | 2396 |      * | 
 | 2397 |      */ | 
 | 2398 |     @Override | 
 | 2399 |     public void setNetworkSelectionModeAutomatic(int subId) { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2400 |         enforceModifyPermissionOrCarrierPrivilege(subId); | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 2401 |         if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); | 
 | 2402 |         sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); | 
 | 2403 |     } | 
 | 2404 |  | 
 | 2405 |     /** | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 2406 |      * Set the network selection mode to manual with the selected carrier. | 
 | 2407 |      */ | 
 | 2408 |     @Override | 
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 2409 |     public boolean setNetworkSelectionModeManual(int subId, OperatorInfo operator, | 
 | 2410 |             boolean persistSelection) { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2411 |         enforceModifyPermissionOrCarrierPrivilege(subId); | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 2412 |         if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator); | 
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 2413 |         ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator, | 
 | 2414 |                 persistSelection); | 
 | 2415 |         return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 2416 |     } | 
 | 2417 |  | 
 | 2418 |     /** | 
 | 2419 |      * Scans for available networks. | 
 | 2420 |      */ | 
 | 2421 |     @Override | 
 | 2422 |     public CellNetworkScanResult getCellNetworkScanResults(int subId) { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2423 |         enforceModifyPermissionOrCarrierPrivilege(subId); | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 2424 |         if (DBG) log("getCellNetworkScanResults: subId " + subId); | 
 | 2425 |         CellNetworkScanResult result = (CellNetworkScanResult) sendRequest( | 
 | 2426 |                 CMD_PERFORM_NETWORK_SCAN, null, subId); | 
 | 2427 |         return result; | 
 | 2428 |     } | 
 | 2429 |  | 
 | 2430 |     /** | 
| Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 2431 |      * Get the calculated preferred network type. | 
 | 2432 |      * Used for debugging incorrect network type. | 
 | 2433 |      * | 
 | 2434 |      * @return the preferred network type, defined in RILConstants.java. | 
 | 2435 |      */ | 
 | 2436 |     @Override | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 2437 |     public int getCalculatedPreferredNetworkType(String callingPackage) { | 
 | 2438 |         if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) { | 
 | 2439 |             return RILConstants.PREFERRED_NETWORK_MODE; | 
 | 2440 |         } | 
 | 2441 |  | 
| Amit Mahajan | 43330e0 | 2014-11-18 11:54:45 -0800 | [diff] [blame] | 2442 |         return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere. | 
| Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 2443 |     } | 
 | 2444 |  | 
 | 2445 |     /** | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 2446 |      * Get the preferred network type. | 
 | 2447 |      * Used for device configuration by some CDMA operators. | 
 | 2448 |      * | 
 | 2449 |      * @return the preferred network type, defined in RILConstants.java. | 
 | 2450 |      */ | 
 | 2451 |     @Override | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 2452 |     public int getPreferredNetworkType(int subId) { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2453 |         enforceModifyPermissionOrCarrierPrivilege(subId); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 2454 |         if (DBG) log("getPreferredNetworkType"); | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 2455 |         int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 2456 |         int networkType = (result != null ? result[0] : -1); | 
 | 2457 |         if (DBG) log("getPreferredNetworkType: " + networkType); | 
 | 2458 |         return networkType; | 
 | 2459 |     } | 
 | 2460 |  | 
 | 2461 |     /** | 
 | 2462 |      * Set the preferred network type. | 
 | 2463 |      * Used for device configuration by some CDMA operators. | 
 | 2464 |      * | 
 | 2465 |      * @param networkType the preferred network type, defined in RILConstants.java. | 
 | 2466 |      * @return true on success; false on any failure. | 
 | 2467 |      */ | 
 | 2468 |     @Override | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 2469 |     public boolean setPreferredNetworkType(int subId, int networkType) { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2470 |         enforceModifyPermissionOrCarrierPrivilege(subId); | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 2471 |         if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); | 
 | 2472 |         Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 2473 |         if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); | 
| Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 2474 |         if (success) { | 
 | 2475 |             Settings.Global.putInt(mPhone.getContext().getContentResolver(), | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 2476 |                     Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); | 
| Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 2477 |         } | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 2478 |         return success; | 
 | 2479 |     } | 
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 2480 |  | 
 | 2481 |     /** | 
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 2482 |      * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning | 
 | 2483 |      * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for | 
 | 2484 |      * tethering. | 
 | 2485 |      * | 
 | 2486 |      * @return 0: Not required. 1: required. 2: Not set. | 
 | 2487 |      * @hide | 
 | 2488 |      */ | 
 | 2489 |     @Override | 
 | 2490 |     public int getTetherApnRequired() { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2491 |         enforceModifyPermission(); | 
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 2492 |         int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(), | 
 | 2493 |                 Settings.Global.TETHER_DUN_REQUIRED, 2); | 
 | 2494 |         // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and | 
 | 2495 |         // config_tether_apndata. | 
 | 2496 |         if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) { | 
 | 2497 |             dunRequired = 1; | 
 | 2498 |         } | 
 | 2499 |         return dunRequired; | 
 | 2500 |     } | 
 | 2501 |  | 
 | 2502 |     /** | 
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 2503 |      * Set mobile data enabled | 
 | 2504 |      * Used by the user through settings etc to turn on/off mobile data | 
 | 2505 |      * | 
 | 2506 |      * @param enable {@code true} turn turn data on, else {@code false} | 
 | 2507 |      */ | 
 | 2508 |     @Override | 
| Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 2509 |     public void setDataEnabled(int subId, boolean enable) { | 
| Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 2510 |         enforceModifyPermissionOrCarrierPrivilege(subId); | 
| Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 2511 |         int phoneId = mSubscriptionController.getPhoneId(subId); | 
| Joe Onorato | a601dd2 | 2016-02-23 13:03:53 -0800 | [diff] [blame] | 2512 |         if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId); | 
| Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 2513 |         Phone phone = PhoneFactory.getPhone(phoneId); | 
 | 2514 |         if (phone != null) { | 
| Joe Onorato | a601dd2 | 2016-02-23 13:03:53 -0800 | [diff] [blame] | 2515 |             if (DBG) log("setDataEnabled: subId=" + subId + " enable=" + enable); | 
| Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 2516 |             phone.setDataEnabled(enable); | 
 | 2517 |         } else { | 
 | 2518 |             loge("setDataEnabled: no phone for subId=" + subId); | 
 | 2519 |         } | 
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 2520 |     } | 
 | 2521 |  | 
 | 2522 |     /** | 
| Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 2523 |      * Get whether mobile data is enabled. | 
 | 2524 |      * | 
| Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 2525 |      * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. | 
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 2526 |      * | 
 | 2527 |      * @return {@code true} if data is enabled else {@code false} | 
 | 2528 |      */ | 
 | 2529 |     @Override | 
| Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 2530 |     public boolean getDataEnabled(int subId) { | 
| Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 2531 |         try { | 
 | 2532 |             mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, | 
 | 2533 |                     null); | 
 | 2534 |         } catch (Exception e) { | 
| Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 2535 |             enforceModifyPermissionOrCarrierPrivilege(subId); | 
| Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 2536 |         } | 
| Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 2537 |         int phoneId = mSubscriptionController.getPhoneId(subId); | 
| Joe Onorato | a601dd2 | 2016-02-23 13:03:53 -0800 | [diff] [blame] | 2538 |         if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId); | 
| Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 2539 |         Phone phone = PhoneFactory.getPhone(phoneId); | 
 | 2540 |         if (phone != null) { | 
 | 2541 |             boolean retVal = phone.getDataEnabled(); | 
| Joe Onorato | a601dd2 | 2016-02-23 13:03:53 -0800 | [diff] [blame] | 2542 |             if (DBG) log("getDataEnabled: subId=" + subId + " retVal=" + retVal); | 
| Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 2543 |             return retVal; | 
 | 2544 |         } else { | 
| Joe Onorato | a601dd2 | 2016-02-23 13:03:53 -0800 | [diff] [blame] | 2545 |             if (DBG) loge("getDataEnabled: no phone subId=" + subId + " retVal=false"); | 
| Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 2546 |             return false; | 
 | 2547 |         } | 
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 2548 |     } | 
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 2549 |  | 
 | 2550 |     @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2551 |     public int getCarrierPrivilegeStatus(int subId) { | 
 | 2552 |         final Phone phone = getPhone(subId); | 
 | 2553 |         if (phone == null) { | 
 | 2554 |             loge("getCarrierPrivilegeStatus: Invalid subId"); | 
 | 2555 |             return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; | 
 | 2556 |         } | 
 | 2557 |         UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 2558 |         if (card == null) { | 
| Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 2559 |             loge("getCarrierPrivilegeStatus: No UICC"); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 2560 |             return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; | 
 | 2561 |         } | 
 | 2562 |         return card.getCarrierPrivilegeStatusForCurrentTransaction( | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2563 |                 phone.getContext().getPackageManager()); | 
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 2564 |     } | 
| Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 2565 |  | 
 | 2566 |     @Override | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 2567 |     public int checkCarrierPrivilegesForPackage(String pkgName) { | 
| Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 2568 |         if (TextUtils.isEmpty(pkgName)) | 
 | 2569 |             return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; | 
| Shishir Agrawal | 2140925 | 2015-01-15 23:33:50 -0800 | [diff] [blame] | 2570 |         UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId()); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 2571 |         if (card == null) { | 
 | 2572 |             loge("checkCarrierPrivilegesForPackage: No UICC"); | 
 | 2573 |             return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; | 
 | 2574 |         } | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 2575 |         return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName); | 
 | 2576 |     } | 
 | 2577 |  | 
 | 2578 |     @Override | 
 | 2579 |     public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { | 
| Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 2580 |         if (TextUtils.isEmpty(pkgName)) | 
 | 2581 |             return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 2582 |         int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; | 
 | 2583 |         for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { | 
 | 2584 |             UiccCard card = UiccController.getInstance().getUiccCard(i); | 
 | 2585 |             if (card == null) { | 
| Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 2586 |               // No UICC in that slot. | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 2587 |               continue; | 
 | 2588 |             } | 
 | 2589 |  | 
 | 2590 |             result = card.getCarrierPrivilegeStatus( | 
 | 2591 |                 mPhone.getContext().getPackageManager(), pkgName); | 
 | 2592 |             if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { | 
 | 2593 |                 break; | 
 | 2594 |             } | 
 | 2595 |         } | 
 | 2596 |  | 
 | 2597 |         return result; | 
| Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 2598 |     } | 
| Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 2599 |  | 
 | 2600 |     @Override | 
| Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 2601 |     public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { | 
 | 2602 |         if (!SubscriptionManager.isValidPhoneId(phoneId)) { | 
 | 2603 |             loge("phoneId " + phoneId + " is not valid."); | 
 | 2604 |             return null; | 
 | 2605 |         } | 
 | 2606 |         UiccCard card = UiccController.getInstance().getUiccCard(phoneId); | 
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 2607 |         if (card == null) { | 
| Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 2608 |             loge("getCarrierPackageNamesForIntent: No UICC"); | 
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 2609 |             return null ; | 
 | 2610 |         } | 
| Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 2611 |         return card.getCarrierPackageNamesForIntent( | 
| Svetoslav | 483aff7 | 2015-04-21 14:16:07 -0700 | [diff] [blame] | 2612 |                 mPhone.getContext().getPackageManager(), intent); | 
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 2613 |     } | 
 | 2614 |  | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 2615 |     @Override | 
 | 2616 |     public List<String> getPackagesWithCarrierPrivileges() { | 
 | 2617 |         PackageManager pm = mPhone.getContext().getPackageManager(); | 
 | 2618 |         List<String> privilegedPackages = new ArrayList<>(); | 
 | 2619 |         List<PackageInfo> packages = null; | 
 | 2620 |         for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { | 
 | 2621 |             UiccCard card = UiccController.getInstance().getUiccCard(i); | 
 | 2622 |             if (card == null) { | 
 | 2623 |                 // No UICC in that slot. | 
 | 2624 |                 continue; | 
 | 2625 |             } | 
 | 2626 |             if (card.hasCarrierPrivilegeRules()) { | 
 | 2627 |                 if (packages == null) { | 
 | 2628 |                     // Only check packages in user 0 for now | 
 | 2629 |                     packages = pm.getInstalledPackagesAsUser( | 
 | 2630 |                             PackageManager.MATCH_DISABLED_COMPONENTS | 
 | 2631 |                             | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS | 
 | 2632 |                             | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); | 
 | 2633 |                 } | 
 | 2634 |                 for (int p = packages.size() - 1; p >= 0; p--) { | 
 | 2635 |                     PackageInfo pkgInfo = packages.get(p); | 
 | 2636 |                     if (pkgInfo != null && pkgInfo.packageName != null | 
 | 2637 |                             && card.getCarrierPrivilegeStatus(pkgInfo) | 
 | 2638 |                                 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { | 
 | 2639 |                         privilegedPackages.add(pkgInfo.packageName); | 
 | 2640 |                     } | 
 | 2641 |                 } | 
 | 2642 |             } | 
 | 2643 |         } | 
 | 2644 |         return privilegedPackages; | 
 | 2645 |     } | 
 | 2646 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2647 |     private String getIccId(int subId) { | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2648 |         final Phone phone = getPhone(subId); | 
 | 2649 |         UiccCard card = phone == null ? null : phone.getUiccCard(); | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 2650 |         if (card == null) { | 
 | 2651 |             loge("getIccId: No UICC"); | 
 | 2652 |             return null; | 
 | 2653 |         } | 
 | 2654 |         String iccId = card.getIccId(); | 
 | 2655 |         if (TextUtils.isEmpty(iccId)) { | 
 | 2656 |             loge("getIccId: ICC ID is null or empty."); | 
 | 2657 |             return null; | 
 | 2658 |         } | 
 | 2659 |         return iccId; | 
 | 2660 |     } | 
 | 2661 |  | 
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 2662 |     @Override | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 2663 |     public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, | 
 | 2664 |             String number) { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2665 |         enforceCarrierPrivilege(subId); | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 2666 |  | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 2667 |         final String iccId = getIccId(subId); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2668 |         final Phone phone = getPhone(subId); | 
 | 2669 |         if (phone == null) { | 
 | 2670 |             return false; | 
 | 2671 |         } | 
 | 2672 |         final String subscriberId = phone.getSubscriberId(); | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 2673 |  | 
 | 2674 |         if (DBG_MERGE) { | 
 | 2675 |             Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" | 
 | 2676 |                     + subscriberId + " to " + number); | 
 | 2677 |         } | 
 | 2678 |  | 
| Shishir Agrawal | 495d7e1 | 2014-12-01 11:50:28 -0800 | [diff] [blame] | 2679 |         if (TextUtils.isEmpty(iccId)) { | 
 | 2680 |             return false; | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 2681 |         } | 
| Shishir Agrawal | 495d7e1 | 2014-12-01 11:50:28 -0800 | [diff] [blame] | 2682 |  | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 2683 |         final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); | 
 | 2684 |  | 
 | 2685 |         final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; | 
| Shishir Agrawal | 495d7e1 | 2014-12-01 11:50:28 -0800 | [diff] [blame] | 2686 |         if (alphaTag == null) { | 
 | 2687 |             editor.remove(alphaTagPrefKey); | 
 | 2688 |         } else { | 
 | 2689 |             editor.putString(alphaTagPrefKey, alphaTag); | 
 | 2690 |         } | 
 | 2691 |  | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 2692 |         // Record both the line number and IMSI for this ICCID, since we need to | 
 | 2693 |         // track all merged IMSIs based on line number | 
 | 2694 |         final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; | 
 | 2695 |         final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; | 
| Shishir Agrawal | 495d7e1 | 2014-12-01 11:50:28 -0800 | [diff] [blame] | 2696 |         if (number == null) { | 
 | 2697 |             editor.remove(numberPrefKey); | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 2698 |             editor.remove(subscriberPrefKey); | 
| Shishir Agrawal | 495d7e1 | 2014-12-01 11:50:28 -0800 | [diff] [blame] | 2699 |         } else { | 
 | 2700 |             editor.putString(numberPrefKey, number); | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 2701 |             editor.putString(subscriberPrefKey, subscriberId); | 
| Shishir Agrawal | 495d7e1 | 2014-12-01 11:50:28 -0800 | [diff] [blame] | 2702 |         } | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 2703 |  | 
| Shishir Agrawal | 495d7e1 | 2014-12-01 11:50:28 -0800 | [diff] [blame] | 2704 |         editor.commit(); | 
 | 2705 |         return true; | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 2706 |     } | 
 | 2707 |  | 
 | 2708 |     @Override | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 2709 |     public String getLine1NumberForDisplay(int subId, String callingPackage) { | 
| Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 2710 |         // This is open to apps with WRITE_SMS. | 
 | 2711 |         if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) { | 
| Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 2712 |             if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 2713 |             return null; | 
 | 2714 |         } | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 2715 |  | 
 | 2716 |         String iccId = getIccId(subId); | 
 | 2717 |         if (iccId != null) { | 
 | 2718 |             String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; | 
| Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 2719 |             if (DBG_MERGE) { | 
 | 2720 |                 log("getLine1NumberForDisplay returning " + | 
 | 2721 |                         mTelephonySharedPreferences.getString(numberPrefKey, null)); | 
 | 2722 |             } | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 2723 |             return mTelephonySharedPreferences.getString(numberPrefKey, null); | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 2724 |         } | 
| Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 2725 |         if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 2726 |         return null; | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 2727 |     } | 
 | 2728 |  | 
 | 2729 |     @Override | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 2730 |     public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { | 
 | 2731 |         if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) { | 
 | 2732 |             return null; | 
 | 2733 |         } | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 2734 |  | 
 | 2735 |         String iccId = getIccId(subId); | 
 | 2736 |         if (iccId != null) { | 
 | 2737 |             String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 2738 |             return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 2739 |         } | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 2740 |         return null; | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 2741 |     } | 
| Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 2742 |  | 
 | 2743 |     @Override | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 2744 |     public String[] getMergedSubscriberIds(String callingPackage) { | 
 | 2745 |         if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) { | 
 | 2746 |             return null; | 
 | 2747 |         } | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 2748 |         final Context context = mPhone.getContext(); | 
 | 2749 |         final TelephonyManager tele = TelephonyManager.from(context); | 
 | 2750 |         final SubscriptionManager sub = SubscriptionManager.from(context); | 
 | 2751 |  | 
 | 2752 |         // Figure out what subscribers are currently active | 
 | 2753 |         final ArraySet<String> activeSubscriberIds = new ArraySet<>(); | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 2754 |         // Clear calling identity, when calling TelephonyManager, because callerUid must be | 
 | 2755 |         // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail. | 
 | 2756 |         final long identity  = Binder.clearCallingIdentity(); | 
 | 2757 |         try { | 
 | 2758 |             final int[] subIds = sub.getActiveSubscriptionIdList(); | 
 | 2759 |             for (int subId : subIds) { | 
 | 2760 |                 activeSubscriberIds.add(tele.getSubscriberId(subId)); | 
 | 2761 |             } | 
 | 2762 |         } finally { | 
 | 2763 |             Binder.restoreCallingIdentity(identity); | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 2764 |         } | 
 | 2765 |  | 
 | 2766 |         // First pass, find a number override for an active subscriber | 
 | 2767 |         String mergeNumber = null; | 
 | 2768 |         final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); | 
 | 2769 |         for (String key : prefs.keySet()) { | 
 | 2770 |             if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { | 
 | 2771 |                 final String subscriberId = (String) prefs.get(key); | 
 | 2772 |                 if (activeSubscriberIds.contains(subscriberId)) { | 
 | 2773 |                     final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); | 
 | 2774 |                     final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; | 
 | 2775 |                     mergeNumber = (String) prefs.get(numberKey); | 
 | 2776 |                     if (DBG_MERGE) { | 
 | 2777 |                         Slog.d(LOG_TAG, "Found line number " + mergeNumber | 
 | 2778 |                                 + " for active subscriber " + subscriberId); | 
 | 2779 |                     } | 
 | 2780 |                     if (!TextUtils.isEmpty(mergeNumber)) { | 
 | 2781 |                         break; | 
 | 2782 |                     } | 
 | 2783 |                 } | 
 | 2784 |             } | 
 | 2785 |         } | 
 | 2786 |  | 
 | 2787 |         // Shortcut when no active merged subscribers | 
 | 2788 |         if (TextUtils.isEmpty(mergeNumber)) { | 
 | 2789 |             return null; | 
 | 2790 |         } | 
 | 2791 |  | 
 | 2792 |         // Second pass, find all subscribers under that line override | 
 | 2793 |         final ArraySet<String> result = new ArraySet<>(); | 
 | 2794 |         for (String key : prefs.keySet()) { | 
 | 2795 |             if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { | 
 | 2796 |                 final String number = (String) prefs.get(key); | 
 | 2797 |                 if (mergeNumber.equals(number)) { | 
 | 2798 |                     final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); | 
 | 2799 |                     final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; | 
 | 2800 |                     final String subscriberId = (String) prefs.get(subscriberKey); | 
 | 2801 |                     if (!TextUtils.isEmpty(subscriberId)) { | 
 | 2802 |                         result.add(subscriberId); | 
 | 2803 |                     } | 
 | 2804 |                 } | 
 | 2805 |             } | 
 | 2806 |         } | 
 | 2807 |  | 
 | 2808 |         final String[] resultArray = result.toArray(new String[result.size()]); | 
 | 2809 |         Arrays.sort(resultArray); | 
 | 2810 |         if (DBG_MERGE) { | 
 | 2811 |             Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge"); | 
 | 2812 |         } | 
 | 2813 |         return resultArray; | 
 | 2814 |     } | 
 | 2815 |  | 
 | 2816 |     @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2817 |     public boolean setOperatorBrandOverride(int subId, String brand) { | 
 | 2818 |         enforceCarrierPrivilege(subId); | 
 | 2819 |         final Phone phone = getPhone(subId); | 
 | 2820 |         return phone == null ? false : phone.setOperatorBrandOverride(brand); | 
| Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 2821 |     } | 
| Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 2822 |  | 
 | 2823 |     @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2824 |     public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, | 
| Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 2825 |             List<String> gsmNonRoamingList, List<String> cdmaRoamingList, | 
 | 2826 |             List<String> cdmaNonRoamingList) { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2827 |         enforceCarrierPrivilege(subId); | 
 | 2828 |         final Phone phone = getPhone(subId); | 
 | 2829 |         if (phone == null) { | 
 | 2830 |             return false; | 
 | 2831 |         } | 
 | 2832 |         return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, | 
| Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 2833 |                 cdmaNonRoamingList); | 
 | 2834 |     } | 
 | 2835 |  | 
 | 2836 |     @Override | 
| Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 2837 |     public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { | 
 | 2838 |         enforceModifyPermission(); | 
 | 2839 |  | 
 | 2840 |         int returnValue = 0; | 
 | 2841 |         try { | 
 | 2842 |             AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); | 
 | 2843 |             if(result.exception == null) { | 
 | 2844 |                 if (result.result != null) { | 
 | 2845 |                     byte[] responseData = (byte[])(result.result); | 
 | 2846 |                     if(responseData.length > oemResp.length) { | 
 | 2847 |                         Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + | 
 | 2848 |                                 responseData.length +  "bytes. Buffer Size is " + | 
 | 2849 |                                 oemResp.length + "bytes."); | 
 | 2850 |                     } | 
 | 2851 |                     System.arraycopy(responseData, 0, oemResp, 0, responseData.length); | 
 | 2852 |                     returnValue = responseData.length; | 
 | 2853 |                 } | 
 | 2854 |             } else { | 
 | 2855 |                 CommandException ex = (CommandException) result.exception; | 
 | 2856 |                 returnValue = ex.getCommandError().ordinal(); | 
 | 2857 |                 if(returnValue > 0) returnValue *= -1; | 
 | 2858 |             } | 
 | 2859 |         } catch (RuntimeException e) { | 
 | 2860 |             Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); | 
 | 2861 |             returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); | 
 | 2862 |             if(returnValue > 0) returnValue *= -1; | 
 | 2863 |         } | 
 | 2864 |  | 
 | 2865 |         return returnValue; | 
 | 2866 |     } | 
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 2867 |  | 
 | 2868 |     @Override | 
 | 2869 |     public void setRadioCapability(RadioAccessFamily[] rafs) { | 
 | 2870 |         try { | 
 | 2871 |             ProxyController.getInstance().setRadioCapability(rafs); | 
 | 2872 |         } catch (RuntimeException e) { | 
 | 2873 |             Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); | 
 | 2874 |         } | 
 | 2875 |     } | 
 | 2876 |  | 
 | 2877 |     @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2878 |     public int getRadioAccessFamily(int phoneId, String callingPackage) { | 
 | 2879 |         if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) { | 
 | 2880 |             return RadioAccessFamily.RAF_UNKNOWN; | 
 | 2881 |         } | 
 | 2882 |  | 
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 2883 |         return ProxyController.getInstance().getRadioAccessFamily(phoneId); | 
 | 2884 |     } | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 2885 |  | 
 | 2886 |     @Override | 
 | 2887 |     public void enableVideoCalling(boolean enable) { | 
 | 2888 |         enforceModifyPermission(); | 
| Tyler Gunn | fdd69de | 2015-12-04 21:24:38 -0800 | [diff] [blame] | 2889 |         ImsManager.setVtSetting(mPhone.getContext(), enable); | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 2890 |     } | 
 | 2891 |  | 
 | 2892 |     @Override | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 2893 |     public boolean isVideoCallingEnabled(String callingPackage) { | 
 | 2894 |         if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) { | 
 | 2895 |             return false; | 
 | 2896 |         } | 
 | 2897 |  | 
| Andrew Lee | 77527ac | 2014-10-21 16:57:39 -0700 | [diff] [blame] | 2898 |         // Check the user preference and the  system-level IMS setting. Even if the user has | 
 | 2899 |         // enabled video calling, if IMS is disabled we aren't able to support video calling. | 
 | 2900 |         // In the long run, we may instead need to check if there exists a connection service | 
 | 2901 |         // which can support video calling. | 
| Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 2902 |         return ImsManager.isVtEnabledByPlatform(mPhone.getContext()) | 
 | 2903 |                 && ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext()) | 
| Tyler Gunn | fdd69de | 2015-12-04 21:24:38 -0800 | [diff] [blame] | 2904 |                 && ImsManager.isVtEnabledByUser(mPhone.getContext()); | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 2905 |     } | 
| Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 2906 |  | 
| Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 2907 |     @Override | 
 | 2908 |     public boolean canChangeDtmfToneLength() { | 
| Jonathan Basseri | 9504c6b | 2015-06-04 14:23:32 -0700 | [diff] [blame] | 2909 |         return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); | 
| Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 2910 |     } | 
 | 2911 |  | 
 | 2912 |     @Override | 
 | 2913 |     public boolean isWorldPhone() { | 
| Jonathan Basseri | 9504c6b | 2015-06-04 14:23:32 -0700 | [diff] [blame] | 2914 |         return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); | 
| Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 2915 |     } | 
 | 2916 |  | 
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 2917 |     @Override | 
 | 2918 |     public boolean isTtyModeSupported() { | 
 | 2919 |         TelecomManager telecomManager = TelecomManager.from(mPhone.getContext()); | 
 | 2920 |         TelephonyManager telephonyManager = | 
 | 2921 |                 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE); | 
| Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 2922 |         return telecomManager.isTtySupported(); | 
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 2923 |     } | 
 | 2924 |  | 
 | 2925 |     @Override | 
 | 2926 |     public boolean isHearingAidCompatibilitySupported() { | 
 | 2927 |         return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled); | 
 | 2928 |     } | 
 | 2929 |  | 
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 2930 |     /** | 
 | 2931 |      * Returns the unique device ID of phone, for example, the IMEI for | 
 | 2932 |      * GSM and the MEID for CDMA phones. Return null if device ID is not available. | 
 | 2933 |      * | 
 | 2934 |      * <p>Requires Permission: | 
 | 2935 |      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} | 
 | 2936 |      */ | 
 | 2937 |     @Override | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 2938 |     public String getDeviceId(String callingPackage) { | 
 | 2939 |         if (!canReadPhoneState(callingPackage, "getDeviceId")) { | 
 | 2940 |             return null; | 
 | 2941 |         } | 
 | 2942 |  | 
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 2943 |         final Phone phone = PhoneFactory.getPhone(0); | 
 | 2944 |         if (phone != null) { | 
 | 2945 |             return phone.getDeviceId(); | 
 | 2946 |         } else { | 
 | 2947 |             return null; | 
 | 2948 |         } | 
 | 2949 |     } | 
 | 2950 |  | 
| Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 2951 |     /* | 
 | 2952 |      * {@hide} | 
 | 2953 |      * Returns the IMS Registration Status | 
 | 2954 |      */ | 
| Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 2955 |     @Override | 
| Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 2956 |     public boolean isImsRegistered() { | 
 | 2957 |         return mPhone.isImsRegistered(); | 
 | 2958 |     } | 
| Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 2959 |  | 
 | 2960 |     @Override | 
 | 2961 |     public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { | 
 | 2962 |         return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); | 
 | 2963 |     } | 
| Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 2964 |  | 
| Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 2965 |     /* | 
 | 2966 |      * {@hide} | 
 | 2967 |      * Returns the IMS Registration Status | 
 | 2968 |      */ | 
| Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 2969 |     public boolean isWifiCallingAvailable() { | 
| Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 2970 |         return mPhone.isWifiCallingEnabled(); | 
 | 2971 |     } | 
 | 2972 |  | 
 | 2973 |     /* | 
 | 2974 |      * {@hide} | 
 | 2975 |      * Returns the IMS Registration Status | 
 | 2976 |      */ | 
| Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 2977 |     public boolean isVolteAvailable() { | 
| Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 2978 |         return mPhone.isVolteEnabled(); | 
 | 2979 |     } | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 2980 |  | 
| Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 2981 |     /* | 
 | 2982 |      * {@hide} Returns the IMS Registration Status | 
 | 2983 |      */ | 
 | 2984 |     public boolean isVideoTelephonyAvailable() { | 
 | 2985 |         return mPhone.isVideoEnabled(); | 
 | 2986 |     } | 
 | 2987 |  | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 2988 |     private boolean canReadPhoneState(String callingPackage, String message) { | 
| Etan Cohen | 921655c | 2015-06-24 13:54:50 -0700 | [diff] [blame] | 2989 |         try { | 
| Amit Mahajan | 83ea23b | 2015-07-30 16:05:11 -0700 | [diff] [blame] | 2990 |             mApp.enforceCallingOrSelfPermission( | 
| Etan Cohen | 921655c | 2015-06-24 13:54:50 -0700 | [diff] [blame] | 2991 |                     android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message); | 
 | 2992 |  | 
| Amit Mahajan | 83ea23b | 2015-07-30 16:05:11 -0700 | [diff] [blame] | 2993 |             // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission | 
| Etan Cohen | 921655c | 2015-06-24 13:54:50 -0700 | [diff] [blame] | 2994 |             return true; | 
| Amit Mahajan | 785783f | 2015-06-29 10:36:50 -0700 | [diff] [blame] | 2995 |         } catch (SecurityException e) { | 
 | 2996 |             mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, | 
 | 2997 |                     message); | 
| Etan Cohen | 921655c | 2015-06-24 13:54:50 -0700 | [diff] [blame] | 2998 |         } | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 2999 |  | 
 | 3000 |         if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(), | 
 | 3001 |                 callingPackage) != AppOpsManager.MODE_ALLOWED) { | 
 | 3002 |             return false; | 
 | 3003 |         } | 
 | 3004 |  | 
 | 3005 |         return true; | 
 | 3006 |     } | 
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3007 |  | 
| Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 3008 |     /** | 
| Amit Mahajan | b9b4978 | 2015-09-15 18:16:32 -0700 | [diff] [blame] | 3009 |      * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers. | 
| Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 3010 |      */ | 
 | 3011 |     private boolean canReadPhoneNumber(String callingPackage, String message) { | 
| Makoto Onuki | e4072d1 | 2015-08-03 15:12:23 -0700 | [diff] [blame] | 3012 |         // Default SMS app can always read it. | 
 | 3013 |         if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS, | 
 | 3014 |                 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) { | 
 | 3015 |             return true; | 
 | 3016 |         } | 
| Chad Brubaker | 7a8fba2 | 2016-11-10 11:23:18 -0800 | [diff] [blame] | 3017 |  | 
| Makoto Onuki | e4072d1 | 2015-08-03 15:12:23 -0700 | [diff] [blame] | 3018 |         try { | 
 | 3019 |             return canReadPhoneState(callingPackage, message); | 
| Amit Mahajan | b9b4978 | 2015-09-15 18:16:32 -0700 | [diff] [blame] | 3020 |         } catch (SecurityException readPhoneStateSecurityException) { | 
| Makoto Onuki | e4072d1 | 2015-08-03 15:12:23 -0700 | [diff] [blame] | 3021 |         } | 
| Chad Brubaker | 7a8fba2 | 2016-11-10 11:23:18 -0800 | [diff] [blame] | 3022 |         // Can be read with READ_SMS too. | 
 | 3023 |         try { | 
 | 3024 |             mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message); | 
 | 3025 |             int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS); | 
 | 3026 |             if (opCode != AppOpsManager.OP_NONE) { | 
 | 3027 |                 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage) | 
 | 3028 |                         == AppOpsManager.MODE_ALLOWED; | 
 | 3029 |             } else { | 
 | 3030 |                 return true; | 
 | 3031 |             } | 
 | 3032 |         } catch (SecurityException readSmsSecurityException) { | 
 | 3033 |         } | 
 | 3034 |         // Can be read with READ_PHONE_NUMBER too. | 
 | 3035 |         try { | 
 | 3036 |             mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBER, | 
 | 3037 |                     message); | 
 | 3038 |             int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBER); | 
 | 3039 |             if (opCode != AppOpsManager.OP_NONE) { | 
 | 3040 |                 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage) | 
 | 3041 |                         == AppOpsManager.MODE_ALLOWED; | 
 | 3042 |             } else { | 
 | 3043 |                 return true; | 
 | 3044 |             } | 
 | 3045 |         } catch (SecurityException readPhoneNumberSecurityException) { | 
 | 3046 |         } | 
 | 3047 |  | 
 | 3048 |         throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() + | 
 | 3049 |                 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE + | 
 | 3050 |                 ", " + android.Manifest.permission.READ_SMS + ", or " + | 
 | 3051 |                 android.Manifest.permission.READ_PHONE_NUMBER); | 
| Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 3052 |     } | 
 | 3053 |  | 
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3054 |     @Override | 
 | 3055 |     public void factoryReset(int subId) { | 
 | 3056 |         enforceConnectivityInternalPermission(); | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 3057 |         if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { | 
 | 3058 |             return; | 
 | 3059 |         } | 
 | 3060 |  | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 3061 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3062 |         try { | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 3063 |             if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( | 
 | 3064 |                     UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 3065 |                 // Enable data | 
 | 3066 |                 setDataEnabled(subId, true); | 
 | 3067 |                 // Set network selection mode to automatic | 
 | 3068 |                 setNetworkSelectionModeAutomatic(subId); | 
 | 3069 |                 // Set preferred mobile network type to the best available | 
 | 3070 |                 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE); | 
 | 3071 |                 // Turn off roaming | 
 | 3072 |                 SubscriptionManager.from(mApp).setDataRoaming(0, subId); | 
 | 3073 |             } | 
 | 3074 |         } finally { | 
 | 3075 |             Binder.restoreCallingIdentity(identity); | 
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3076 |         } | 
 | 3077 |     } | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 3078 |  | 
 | 3079 |     @Override | 
 | 3080 |     public String getLocaleFromDefaultSim() { | 
 | 3081 |         // We query all subscriptions instead of just the active ones, because | 
 | 3082 |         // this might be called early on in the provisioning flow when the | 
 | 3083 |         // subscriptions potentially aren't active yet. | 
 | 3084 |         final List<SubscriptionInfo> slist = getAllSubscriptionInfoList(); | 
 | 3085 |         if (slist == null || slist.isEmpty()) { | 
 | 3086 |             return null; | 
 | 3087 |         } | 
 | 3088 |  | 
 | 3089 |         // This function may be called very early, say, from the setup wizard, at | 
 | 3090 |         // which point we won't have a default subscription set. If that's the case | 
 | 3091 |         // we just choose the first, which will be valid in "most cases". | 
 | 3092 |         final int defaultSubId = getDefaultSubscription(); | 
 | 3093 |         SubscriptionInfo info = null; | 
 | 3094 |         if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { | 
 | 3095 |             info = slist.get(0); | 
 | 3096 |         } else { | 
 | 3097 |             for (SubscriptionInfo item : slist) { | 
 | 3098 |                 if (item.getSubscriptionId() == defaultSubId) { | 
 | 3099 |                     info = item; | 
 | 3100 |                     break; | 
 | 3101 |                 } | 
 | 3102 |             } | 
 | 3103 |  | 
 | 3104 |             if (info == null) { | 
 | 3105 |                 return null; | 
 | 3106 |             } | 
 | 3107 |         } | 
 | 3108 |  | 
 | 3109 |         // Try and fetch the locale from the carrier properties or from the SIM language | 
 | 3110 |         // preferences (EF-PL and EF-LI)... | 
| Tony Hill | 183b2de | 2015-06-24 14:53:58 +0100 | [diff] [blame] | 3111 |         final int mcc = info.getMcc(); | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 3112 |         final Phone defaultPhone = getPhone(info.getSubscriptionId()); | 
| Narayan Kamath | 011676f | 2015-07-29 12:04:08 +0100 | [diff] [blame] | 3113 |         String simLanguage = null; | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 3114 |         if (defaultPhone != null) { | 
 | 3115 |             final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs(); | 
 | 3116 |             if (localeFromDefaultSim != null) { | 
| Narayan Kamath | 011676f | 2015-07-29 12:04:08 +0100 | [diff] [blame] | 3117 |                 if (!localeFromDefaultSim.getCountry().isEmpty()) { | 
| Tony Hill | 183b2de | 2015-06-24 14:53:58 +0100 | [diff] [blame] | 3118 |                     if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim); | 
 | 3119 |                     return localeFromDefaultSim.toLanguageTag(); | 
| Narayan Kamath | 011676f | 2015-07-29 12:04:08 +0100 | [diff] [blame] | 3120 |                 } else { | 
 | 3121 |                     simLanguage = localeFromDefaultSim.getLanguage(); | 
| Tony Hill | 183b2de | 2015-06-24 14:53:58 +0100 | [diff] [blame] | 3122 |                 } | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 3123 |             } | 
 | 3124 |         } | 
 | 3125 |  | 
| Narayan Kamath | 011676f | 2015-07-29 12:04:08 +0100 | [diff] [blame] | 3126 |         // The SIM language preferences only store a language (e.g. fr = French), not an | 
 | 3127 |         // exact locale (e.g. fr_FR = French/France). So, if the locale returned from | 
 | 3128 |         // the SIM and carrier preferences does not include a country we add the country | 
 | 3129 |         // determined from the SIM MCC to provide an exact locale. | 
 | 3130 |         final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage); | 
| Tony Hill | 183b2de | 2015-06-24 14:53:58 +0100 | [diff] [blame] | 3131 |         if (mccLocale != null) { | 
 | 3132 |             if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale); | 
 | 3133 |             return mccLocale.toLanguageTag(); | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 3134 |         } | 
 | 3135 |  | 
| Tony Hill | 183b2de | 2015-06-24 14:53:58 +0100 | [diff] [blame] | 3136 |         if (DBG) log("No locale found - returning null"); | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 3137 |         return null; | 
 | 3138 |     } | 
 | 3139 |  | 
 | 3140 |     private List<SubscriptionInfo> getAllSubscriptionInfoList() { | 
 | 3141 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3142 |         try { | 
 | 3143 |             return mSubscriptionController.getAllSubInfoList( | 
 | 3144 |                     mPhone.getContext().getOpPackageName()); | 
 | 3145 |         } finally { | 
 | 3146 |             Binder.restoreCallingIdentity(identity); | 
 | 3147 |         } | 
 | 3148 |     } | 
 | 3149 |  | 
 | 3150 |     private List<SubscriptionInfo> getActiveSubscriptionInfoList() { | 
 | 3151 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3152 |         try { | 
 | 3153 |             return mSubscriptionController.getActiveSubscriptionInfoList( | 
 | 3154 |                     mPhone.getContext().getOpPackageName()); | 
 | 3155 |         } finally { | 
 | 3156 |             Binder.restoreCallingIdentity(identity); | 
 | 3157 |         } | 
 | 3158 |     } | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 3159 |  | 
 | 3160 |     /** | 
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 3161 |      * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object | 
 | 3162 |      * representing the state of the modem. | 
 | 3163 |      * | 
 | 3164 |      * NOTE: This clears the modem state, so there should only every be one caller. | 
 | 3165 |      * @hide | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 3166 |      */ | 
 | 3167 |     @Override | 
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 3168 |     public void requestModemActivityInfo(ResultReceiver result) { | 
 | 3169 |         enforceModifyPermission(); | 
 | 3170 |  | 
 | 3171 |         ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null); | 
 | 3172 |         Bundle bundle = new Bundle(); | 
 | 3173 |         bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info); | 
 | 3174 |         result.send(0, bundle); | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 3175 |     } | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 3176 |  | 
 | 3177 |     /** | 
 | 3178 |      * {@hide} | 
 | 3179 |      * Returns the service state information on specified subscription. | 
 | 3180 |      */ | 
 | 3181 |     @Override | 
 | 3182 |     public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { | 
 | 3183 |  | 
 | 3184 |         if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) { | 
 | 3185 |             return null; | 
 | 3186 |         } | 
 | 3187 |  | 
 | 3188 |         final Phone phone = getPhone(subId); | 
 | 3189 |         if (phone == null) { | 
 | 3190 |             return null; | 
 | 3191 |         } | 
 | 3192 |  | 
 | 3193 |         return phone.getServiceState(); | 
 | 3194 |     } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 3195 |  | 
 | 3196 |     /** | 
 | 3197 |      * Returns the URI for the per-account voicemail ringtone set in Phone settings. | 
 | 3198 |      * | 
 | 3199 |      * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the | 
 | 3200 |      * voicemail ringtone. | 
 | 3201 |      * @return The URI for the ringtone to play when receiving a voicemail from a specific | 
 | 3202 |      * PhoneAccount. | 
 | 3203 |      */ | 
 | 3204 |     @Override | 
 | 3205 |     public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { | 
 | 3206 |         final Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); | 
 | 3207 |         if (phone == null) { | 
 | 3208 |             return null; | 
 | 3209 |         } | 
 | 3210 |  | 
 | 3211 |         return VoicemailNotificationSettingsUtil.getRingtoneUri(phone); | 
 | 3212 |     } | 
 | 3213 |  | 
 | 3214 |     /** | 
 | 3215 |      * Returns whether vibration is set for voicemail notification in Phone settings. | 
 | 3216 |      * | 
 | 3217 |      * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the | 
 | 3218 |      * voicemail vibration setting. | 
 | 3219 |      * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. | 
 | 3220 |      */ | 
 | 3221 |     @Override | 
 | 3222 |     public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { | 
 | 3223 |         final Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); | 
 | 3224 |         if (phone == null) { | 
 | 3225 |             return false; | 
 | 3226 |         } | 
 | 3227 |  | 
 | 3228 |         return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone); | 
 | 3229 |     } | 
 | 3230 |  | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 3231 |     /** | 
 | 3232 |      * Make sure either called from same process as self (phone) or IPC caller has read privilege. | 
 | 3233 |      * | 
 | 3234 |      * @throws SecurityException if the caller does not have the required permission | 
 | 3235 |      */ | 
 | 3236 |     private void enforceReadPrivilegedPermission() { | 
 | 3237 |         mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, | 
 | 3238 |                 null); | 
 | 3239 |     } | 
 | 3240 |  | 
 | 3241 |     /** | 
 | 3242 |      * Return the application ID for the app type. | 
 | 3243 |      * | 
 | 3244 |      * @param subId the subscription ID that this request applies to. | 
 | 3245 |      * @param appType the uicc app type. | 
 | 3246 |      * @return Application ID for specificied app type, or null if no uicc. | 
 | 3247 |      */ | 
 | 3248 |     @Override | 
 | 3249 |     public String getAidForAppType(int subId, int appType) { | 
 | 3250 |         enforceReadPrivilegedPermission(); | 
 | 3251 |         Phone phone = getPhone(subId); | 
 | 3252 |         if (phone == null) { | 
 | 3253 |             return null; | 
 | 3254 |         } | 
 | 3255 |         String aid = null; | 
 | 3256 |         try { | 
 | 3257 |             aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) | 
 | 3258 |                     .getApplicationByType(appType).getAid(); | 
 | 3259 |         } catch (Exception e) { | 
 | 3260 |             Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); | 
 | 3261 |         } | 
 | 3262 |         return aid; | 
 | 3263 |     } | 
 | 3264 |  | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 3265 |     /** | 
 | 3266 |      * Return the Electronic Serial Number. | 
 | 3267 |      * | 
 | 3268 |      * @param subId the subscription ID that this request applies to. | 
 | 3269 |      * @return ESN or null if error. | 
 | 3270 |      */ | 
 | 3271 |     @Override | 
 | 3272 |     public String getEsn(int subId) { | 
 | 3273 |         enforceReadPrivilegedPermission(); | 
 | 3274 |         Phone phone = getPhone(subId); | 
 | 3275 |         if (phone == null) { | 
 | 3276 |             return null; | 
 | 3277 |         } | 
 | 3278 |         String esn = null; | 
 | 3279 |         try { | 
 | 3280 |             esn = phone.getEsn(); | 
 | 3281 |         } catch (Exception e) { | 
 | 3282 |             Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); | 
 | 3283 |         } | 
 | 3284 |         return esn; | 
 | 3285 |     } | 
 | 3286 |  | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 3287 |     /** | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 3288 |      * Return the Preferred Roaming List Version. | 
 | 3289 |      * | 
 | 3290 |      * @param subId the subscription ID that this request applies to. | 
 | 3291 |      * @return PRLVersion or null if error. | 
 | 3292 |      */ | 
 | 3293 |     @Override | 
 | 3294 |     public String getCdmaPrlVersion(int subId) { | 
 | 3295 |         enforceReadPrivilegedPermission(); | 
 | 3296 |         Phone phone = getPhone(subId); | 
 | 3297 |         if (phone == null) { | 
 | 3298 |             return null; | 
 | 3299 |         } | 
 | 3300 |         String cdmaPrlVersion = null; | 
 | 3301 |         try { | 
 | 3302 |             cdmaPrlVersion = phone.getCdmaPrlVersion(); | 
 | 3303 |         } catch (Exception e) { | 
 | 3304 |             Log.e(LOG_TAG, "Not getting PRLVersion", e); | 
 | 3305 |         } | 
 | 3306 |         return cdmaPrlVersion; | 
 | 3307 |     } | 
 | 3308 |  | 
 | 3309 |     /** | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 3310 |      * Get snapshot of Telephony histograms | 
 | 3311 |      * @return List of Telephony histograms | 
 | 3312 |      * @hide | 
 | 3313 |      */ | 
 | 3314 |     @Override | 
 | 3315 |     public List<TelephonyHistogram> getTelephonyHistograms() { | 
 | 3316 |         enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription()); | 
 | 3317 |         return RIL.getTelephonyRILTimingHistograms(); | 
 | 3318 |     } | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 3319 |  | 
 | 3320 |     /** | 
 | 3321 |      * {@hide} | 
 | 3322 |      * Set the allowed carrier list for slotId | 
 | 3323 |      * Require system privileges. In the future we may add this to carrier APIs. | 
 | 3324 |      * | 
 | 3325 |      * @return The number of carriers set successfully, should match length of carriers | 
 | 3326 |      */ | 
 | 3327 |     @Override | 
 | 3328 |     public int setAllowedCarriers(int slotId, List<CarrierIdentifier> carriers) { | 
 | 3329 |         enforceModifyPermission(); | 
 | 3330 |         int subId = SubscriptionManager.getSubId(slotId)[0]; | 
 | 3331 |         int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId); | 
 | 3332 |         return retVal[0]; | 
 | 3333 |     } | 
 | 3334 |  | 
 | 3335 |     /** | 
 | 3336 |      * {@hide} | 
 | 3337 |      * Get the allowed carrier list for slotId. | 
 | 3338 |      * Require system privileges. In the future we may add this to carrier APIs. | 
 | 3339 |      * | 
 | 3340 |      * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list | 
 | 3341 |      * means all carriers are allowed. | 
 | 3342 |      */ | 
 | 3343 |     @Override | 
 | 3344 |     public List<CarrierIdentifier> getAllowedCarriers(int slotId) { | 
 | 3345 |         enforceReadPrivilegedPermission(); | 
 | 3346 |         int subId = SubscriptionManager.getSubId(slotId)[0]; | 
 | 3347 |         return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId); | 
 | 3348 |     } | 
 | 3349 |  | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 3350 |     /** | 
 | 3351 |      * Action set from carrier signalling broadcast receivers to enable/disable metered apns | 
 | 3352 |      * @param subId the subscription ID that this action applies to. | 
 | 3353 |      * @param enabled control enable or disable metered apns. | 
 | 3354 |      * {@hide} | 
 | 3355 |      */ | 
 | 3356 |     @Override | 
 | 3357 |     public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { | 
 | 3358 |         enforceModifyPermission(); | 
 | 3359 |         final Phone phone = getPhone(subId); | 
 | 3360 |         if (phone == null) { | 
 | 3361 |             loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); | 
 | 3362 |             return; | 
 | 3363 |         } | 
 | 3364 |         try { | 
 | 3365 |             phone.carrierActionSetMeteredApnsEnabled(enabled); | 
 | 3366 |         } catch (Exception e) { | 
 | 3367 |             Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); | 
 | 3368 |         } | 
 | 3369 |     } | 
 | 3370 |  | 
 | 3371 |     /** | 
 | 3372 |      * Action set from carrier signalling broadcast receivers to enable/disable radio | 
 | 3373 |      * @param subId the subscription ID that this action applies to. | 
 | 3374 |      * @param enabled control enable or disable radio. | 
 | 3375 |      * {@hide} | 
 | 3376 |      */ | 
 | 3377 |     @Override | 
 | 3378 |     public void carrierActionSetRadioEnabled(int subId, boolean enabled) { | 
 | 3379 |         enforceModifyPermission(); | 
 | 3380 |         final Phone phone = getPhone(subId); | 
 | 3381 |         if (phone == null) { | 
 | 3382 |             loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); | 
 | 3383 |             return; | 
 | 3384 |         } | 
 | 3385 |         try { | 
 | 3386 |             phone.carrierActionSetRadioEnabled(enabled); | 
 | 3387 |         } catch (Exception e) { | 
 | 3388 |             Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); | 
 | 3389 |         } | 
 | 3390 |     } | 
 | 3391 |  | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 3392 |     /** | 
 | 3393 |      * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a | 
 | 3394 |      * bug report is being generated. | 
 | 3395 |      */ | 
 | 3396 |     @Override | 
| Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 3397 |     protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { | 
| dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 3398 |         if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP) | 
 | 3399 |                 != PackageManager.PERMISSION_GRANTED) { | 
 | 3400 |             writer.println("Permission Denial: can't dump Phone from pid=" | 
 | 3401 |                     + Binder.getCallingPid() | 
 | 3402 |                     + ", uid=" + Binder.getCallingUid() | 
 | 3403 |                     + "without permission " | 
 | 3404 |                     + android.Manifest.permission.DUMP); | 
 | 3405 |             return; | 
 | 3406 |         } | 
| Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 3407 |         DumpsysHandler.dump(mPhone.getContext(), fd, writer, args); | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 3408 |     } | 
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 3409 |  | 
 | 3410 |     /** | 
 | 3411 |      * Get aggregated video call data usage from all subscriptions since boot. | 
 | 3412 |      * @return total data usage in bytes | 
 | 3413 |      * {@hide} | 
 | 3414 |      */ | 
 | 3415 |     @Override | 
 | 3416 |     public long getVtDataUsage() { | 
 | 3417 |         mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, | 
 | 3418 |                 null); | 
 | 3419 |  | 
 | 3420 |         // NetworkStatsService keeps tracking the active network interface and identity. It will | 
 | 3421 |         // record the delta with the corresponding network identity. What we need to do here is | 
 | 3422 |         // returning total video call data usage from all subscriptions since boot. | 
 | 3423 |  | 
 | 3424 |         // TODO: Add sub id support in the future. We'll need it when we support DSDA and | 
 | 3425 |         // simultaneous VT calls. | 
 | 3426 |         final Phone[] phones = PhoneFactory.getPhones(); | 
 | 3427 |         long total = 0; | 
 | 3428 |         for (Phone phone : phones) { | 
 | 3429 |             total += phone.getVtDataUsage(); | 
 | 3430 |         } | 
 | 3431 |         return total; | 
 | 3432 |     } | 
| Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 3433 |  | 
 | 3434 |     /** | 
 | 3435 |      * Policy control of data connection. Usually used when data limit is passed. | 
 | 3436 |      * @param enabled True if enabling the data, otherwise disabling. | 
 | 3437 |      * @param subId Subscription index | 
 | 3438 |      * {@hide} | 
 | 3439 |      */ | 
 | 3440 |     @Override | 
 | 3441 |     public void setPolicyDataEnabled(boolean enabled, int subId) { | 
 | 3442 |         enforceModifyPermission(); | 
 | 3443 |         Phone phone = getPhone(subId); | 
 | 3444 |         if (phone != null) { | 
 | 3445 |             phone.setPolicyDataEnabled(enabled); | 
 | 3446 |         } | 
 | 3447 |     } | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 3448 |  | 
 | 3449 |     /** | 
 | 3450 |      * Get Client request stats | 
 | 3451 |      * @return List of Client Request Stats | 
 | 3452 |      * @hide | 
 | 3453 |      */ | 
 | 3454 |     @Override | 
 | 3455 |     public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { | 
 | 3456 |         if (!canReadPhoneState(callingPackage, "getClientRequestStats")) { | 
 | 3457 |             return null; | 
 | 3458 |         } | 
 | 3459 |  | 
 | 3460 |         Phone phone = getPhone(subId); | 
 | 3461 |         if (phone != null) { | 
 | 3462 |             return phone.getClientRequestStats(); | 
 | 3463 |         } | 
 | 3464 |  | 
 | 3465 |         return null; | 
 | 3466 |     } | 
 | 3467 |  | 
 | 3468 |     private WorkSource getWorkSource(WorkSource workSource, int uid) { | 
 | 3469 |         if (workSource != null) { | 
 | 3470 |             return workSource; | 
 | 3471 |         } | 
 | 3472 |  | 
 | 3473 |         String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid); | 
 | 3474 |         workSource = new WorkSource(uid, packageName); | 
 | 3475 |         return workSource; | 
 | 3476 |     } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3477 | } |