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