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