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