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