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