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