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