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