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