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