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