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