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; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 36 | import android.preference.PreferenceManager; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 37 | import android.provider.Settings; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.telephony.CellInfo; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 39 | import android.telephony.IccOpenLogicalChannelResponse; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 40 | import android.telephony.NeighboringCellInfo; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 41 | import android.telephony.RadioAccessFamily; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.telephony.ServiceState; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 43 | import android.telephony.SubscriptionInfo; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 44 | import android.telephony.TelephonyManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.text.TextUtils; |
| 46 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 47 | import android.util.Pair; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 48 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 49 | import com.android.ims.ImsManager; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 50 | import com.android.internal.telephony.CallManager; |
| 51 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 52 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 54 | import com.android.internal.telephony.IccCard; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import com.android.internal.telephony.Phone; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 56 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 57 | import com.android.internal.telephony.ProxyController; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 58 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 59 | import com.android.internal.telephony.SubscriptionController; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 60 | import com.android.internal.telephony.uicc.IccIoResult; |
| 61 | import com.android.internal.telephony.uicc.IccUtils; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 62 | import com.android.internal.telephony.uicc.UiccCard; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 63 | import com.android.internal.telephony.uicc.UiccController; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 64 | import com.android.internal.util.HexDump; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 65 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 66 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 67 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 68 | import java.util.ArrayList; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 69 | import java.util.List; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * Implementation of the ITelephony interface. |
| 73 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 74 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 75 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 76 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 77 | private static final boolean DBG_LOC = false; |
| 78 | |
| 79 | // Message codes used with mMainThreadHandler |
| 80 | private static final int CMD_HANDLE_PIN_MMI = 1; |
| 81 | private static final int CMD_HANDLE_NEIGHBORING_CELL = 2; |
| 82 | private static final int EVENT_NEIGHBORING_CELL_DONE = 3; |
| 83 | private static final int CMD_ANSWER_RINGING_CALL = 4; |
| 84 | private static final int CMD_END_CALL = 5; // not used yet |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 85 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 86 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 87 | private static final int CMD_OPEN_CHANNEL = 9; |
| 88 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 89 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 90 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 91 | private static final int CMD_NV_READ_ITEM = 13; |
| 92 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 93 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 94 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 95 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 96 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
| 97 | private static final int CMD_NV_RESET_CONFIG = 19; |
| 98 | private static final int EVENT_NV_RESET_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 99 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 100 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 101 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 102 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 103 | private static final int CMD_SEND_ENVELOPE = 25; |
| 104 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 105 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 106 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
| 107 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 108 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 109 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 110 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 111 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 112 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 113 | |
| 114 | /** The singleton instance. */ |
| 115 | private static PhoneInterfaceManager sInstance; |
| 116 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 117 | private PhoneGlobals mApp; |
| 118 | private Phone mPhone; |
| 119 | private CallManager mCM; |
| 120 | private AppOpsManager mAppOps; |
| 121 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 122 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 123 | private SharedPreferences mTelephonySharedPreferences; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 124 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 125 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 126 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 127 | private static final String PREF_ENABLE_VIDEO_CALLING = "enable_video_calling"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 128 | |
| 129 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 130 | * A request object to use for transmitting data to an ICC. |
| 131 | */ |
| 132 | private static final class IccAPDUArgument { |
| 133 | public int channel, cla, command, p1, p2, p3; |
| 134 | public String data; |
| 135 | |
| 136 | public IccAPDUArgument(int channel, int cla, int command, |
| 137 | int p1, int p2, int p3, String data) { |
| 138 | this.channel = channel; |
| 139 | this.cla = cla; |
| 140 | this.command = command; |
| 141 | this.p1 = p1; |
| 142 | this.p2 = p2; |
| 143 | this.p3 = p3; |
| 144 | this.data = data; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 149 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 150 | * request after sending. The main thread will notify the request when it is complete. |
| 151 | */ |
| 152 | private static final class MainThreadRequest { |
| 153 | /** The argument to use for the request */ |
| 154 | public Object argument; |
| 155 | /** The result of the request that is run on the main thread */ |
| 156 | public Object result; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 157 | /** The subscriber id that this request applies to. Null if default. */ |
| 158 | public Integer subId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 159 | |
| 160 | public MainThreadRequest(Object argument) { |
| 161 | this.argument = argument; |
| 162 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 163 | |
| 164 | public MainThreadRequest(Object argument, Integer subId) { |
| 165 | this.argument = argument; |
| 166 | this.subId = subId; |
| 167 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 170 | private static final class IncomingThirdPartyCallArgs { |
| 171 | public final ComponentName component; |
| 172 | public final String callId; |
| 173 | public final String callerDisplayName; |
| 174 | |
| 175 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 176 | String callerDisplayName) { |
| 177 | this.component = component; |
| 178 | this.callId = callId; |
| 179 | this.callerDisplayName = callerDisplayName; |
| 180 | } |
| 181 | } |
| 182 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 183 | /** |
| 184 | * A handler that processes messages on the main thread in the phone process. Since many |
| 185 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 186 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 187 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 188 | * on, which will be notified when the operation completes and will contain the result of the |
| 189 | * request. |
| 190 | * |
| 191 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 192 | * note that request.result must be set to something non-null for the calling thread to |
| 193 | * unblock. |
| 194 | */ |
| 195 | private final class MainThreadHandler extends Handler { |
| 196 | @Override |
| 197 | public void handleMessage(Message msg) { |
| 198 | MainThreadRequest request; |
| 199 | Message onCompleted; |
| 200 | AsyncResult ar; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 201 | UiccCard uiccCard = UiccController.getInstance().getUiccCard(); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 202 | IccAPDUArgument iccArgument; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 203 | |
| 204 | switch (msg.what) { |
| 205 | case CMD_HANDLE_PIN_MMI: |
| 206 | request = (MainThreadRequest) msg.obj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 207 | request.result = mPhone.handlePinMmi((String) request.argument); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 208 | // Wake up the requesting thread |
| 209 | synchronized (request) { |
| 210 | request.notifyAll(); |
| 211 | } |
| 212 | break; |
| 213 | |
| 214 | case CMD_HANDLE_NEIGHBORING_CELL: |
| 215 | request = (MainThreadRequest) msg.obj; |
| 216 | onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE, |
| 217 | request); |
| 218 | mPhone.getNeighboringCids(onCompleted); |
| 219 | break; |
| 220 | |
| 221 | case EVENT_NEIGHBORING_CELL_DONE: |
| 222 | ar = (AsyncResult) msg.obj; |
| 223 | request = (MainThreadRequest) ar.userObj; |
| 224 | if (ar.exception == null && ar.result != null) { |
| 225 | request.result = ar.result; |
| 226 | } else { |
| 227 | // create an empty list to notify the waiting thread |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 228 | request.result = new ArrayList<NeighboringCellInfo>(0); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 229 | } |
| 230 | // Wake up the requesting thread |
| 231 | synchronized (request) { |
| 232 | request.notifyAll(); |
| 233 | } |
| 234 | break; |
| 235 | |
| 236 | case CMD_ANSWER_RINGING_CALL: |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 237 | request = (MainThreadRequest) msg.obj; |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 238 | int answer_subId = ((Integer)request.argument).intValue(); |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 239 | answerRingingCallInternal(answer_subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 240 | break; |
| 241 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 242 | case CMD_END_CALL: |
| 243 | request = (MainThreadRequest) msg.obj; |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 244 | int end_subId = ((Integer)request.argument).intValue(); |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 245 | final boolean hungUp; |
| 246 | int phoneType = getPhone(end_subId).getPhoneType(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 247 | if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) { |
| 248 | // CDMA: If the user presses the Power button we treat it as |
| 249 | // ending the complete call session |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 250 | hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId)); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 251 | } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) { |
| 252 | // GSM: End the call as per the Phone state |
| 253 | hungUp = PhoneUtils.hangup(mCM); |
| 254 | } else { |
| 255 | throw new IllegalStateException("Unexpected phone type: " + phoneType); |
| 256 | } |
| 257 | if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up")); |
| 258 | request.result = hungUp; |
| 259 | // Wake up the requesting thread |
| 260 | synchronized (request) { |
| 261 | request.notifyAll(); |
| 262 | } |
| 263 | break; |
| 264 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 265 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 266 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 267 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 268 | if (uiccCard == null) { |
| 269 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 270 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 271 | synchronized (request) { |
| 272 | request.notifyAll(); |
| 273 | } |
| 274 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 275 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 276 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 277 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 278 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 279 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 280 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 281 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 282 | break; |
| 283 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 284 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 285 | ar = (AsyncResult) msg.obj; |
| 286 | request = (MainThreadRequest) ar.userObj; |
| 287 | if (ar.exception == null && ar.result != null) { |
| 288 | request.result = ar.result; |
| 289 | } else { |
| 290 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 291 | if (ar.result == null) { |
| 292 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 293 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 294 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 295 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 296 | } else { |
| 297 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 298 | } |
| 299 | } |
| 300 | synchronized (request) { |
| 301 | request.notifyAll(); |
| 302 | } |
| 303 | break; |
| 304 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 305 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 306 | request = (MainThreadRequest) msg.obj; |
| 307 | iccArgument = (IccAPDUArgument) request.argument; |
| 308 | if (uiccCard == null) { |
| 309 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 310 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 311 | synchronized (request) { |
| 312 | request.notifyAll(); |
| 313 | } |
| 314 | } else { |
| 315 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 316 | request); |
| 317 | uiccCard.iccTransmitApduBasicChannel( |
| 318 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 319 | iccArgument.p3, iccArgument.data, onCompleted); |
| 320 | } |
| 321 | break; |
| 322 | |
| 323 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 324 | ar = (AsyncResult) msg.obj; |
| 325 | request = (MainThreadRequest) ar.userObj; |
| 326 | if (ar.exception == null && ar.result != null) { |
| 327 | request.result = ar.result; |
| 328 | } else { |
| 329 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 330 | if (ar.result == null) { |
| 331 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 332 | } else if (ar.exception instanceof CommandException) { |
| 333 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 334 | ar.exception); |
| 335 | } else { |
| 336 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 337 | } |
| 338 | } |
| 339 | synchronized (request) { |
| 340 | request.notifyAll(); |
| 341 | } |
| 342 | break; |
| 343 | |
| 344 | case CMD_EXCHANGE_SIM_IO: |
| 345 | request = (MainThreadRequest) msg.obj; |
| 346 | iccArgument = (IccAPDUArgument) request.argument; |
| 347 | if (uiccCard == null) { |
| 348 | loge("iccExchangeSimIO: No UICC"); |
| 349 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 350 | synchronized (request) { |
| 351 | request.notifyAll(); |
| 352 | } |
| 353 | } else { |
| 354 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 355 | request); |
| 356 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 357 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 358 | iccArgument.data, onCompleted); |
| 359 | } |
| 360 | break; |
| 361 | |
| 362 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 363 | ar = (AsyncResult) msg.obj; |
| 364 | request = (MainThreadRequest) ar.userObj; |
| 365 | if (ar.exception == null && ar.result != null) { |
| 366 | request.result = ar.result; |
| 367 | } else { |
| 368 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 369 | } |
| 370 | synchronized (request) { |
| 371 | request.notifyAll(); |
| 372 | } |
| 373 | break; |
| 374 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 375 | case CMD_SEND_ENVELOPE: |
| 376 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 377 | if (uiccCard == null) { |
| 378 | loge("sendEnvelopeWithStatus: No UICC"); |
| 379 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 380 | synchronized (request) { |
| 381 | request.notifyAll(); |
| 382 | } |
| 383 | } else { |
| 384 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 385 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 386 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 387 | break; |
| 388 | |
| 389 | case EVENT_SEND_ENVELOPE_DONE: |
| 390 | ar = (AsyncResult) msg.obj; |
| 391 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 392 | if (ar.exception == null && ar.result != null) { |
| 393 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 394 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 395 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 396 | if (ar.result == null) { |
| 397 | loge("sendEnvelopeWithStatus: Empty response"); |
| 398 | } else if (ar.exception instanceof CommandException) { |
| 399 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 400 | ar.exception); |
| 401 | } else { |
| 402 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 403 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 404 | } |
| 405 | synchronized (request) { |
| 406 | request.notifyAll(); |
| 407 | } |
| 408 | break; |
| 409 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 410 | case CMD_OPEN_CHANNEL: |
| 411 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 412 | if (uiccCard == null) { |
| 413 | loge("iccOpenLogicalChannel: No UICC"); |
| 414 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 415 | synchronized (request) { |
| 416 | request.notifyAll(); |
| 417 | } |
| 418 | } else { |
| 419 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
| 420 | uiccCard.iccOpenLogicalChannel((String)request.argument, onCompleted); |
| 421 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 422 | break; |
| 423 | |
| 424 | case EVENT_OPEN_CHANNEL_DONE: |
| 425 | ar = (AsyncResult) msg.obj; |
| 426 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 427 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 428 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 429 | int[] result = (int[]) ar.result; |
| 430 | int channelId = result[0]; |
| 431 | byte[] selectResponse = null; |
| 432 | if (result.length > 1) { |
| 433 | selectResponse = new byte[result.length - 1]; |
| 434 | for (int i = 1; i < result.length; ++i) { |
| 435 | selectResponse[i - 1] = (byte) result[i]; |
| 436 | } |
| 437 | } |
| 438 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 439 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 440 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 441 | if (ar.result == null) { |
| 442 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 443 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 444 | if (ar.exception != null) { |
| 445 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 446 | } |
| 447 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 448 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 449 | if ((ar.exception != null) && (ar.exception instanceof CommandException)) { |
| 450 | if (ar.exception.getMessage().compareTo("MISSING_RESOURCE") == 0) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 451 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 452 | } else if (ar.exception.getMessage().compareTo("NO_SUCH_ELEMENT") == 0) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 453 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 454 | } |
| 455 | } |
| 456 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 457 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 458 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 459 | request.result = openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 460 | synchronized (request) { |
| 461 | request.notifyAll(); |
| 462 | } |
| 463 | break; |
| 464 | |
| 465 | case CMD_CLOSE_CHANNEL: |
| 466 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 467 | if (uiccCard == null) { |
| 468 | loge("iccCloseLogicalChannel: No UICC"); |
| 469 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 470 | synchronized (request) { |
| 471 | request.notifyAll(); |
| 472 | } |
| 473 | } else { |
| 474 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 475 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 476 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 477 | break; |
| 478 | |
| 479 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 480 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 481 | break; |
| 482 | |
| 483 | case CMD_NV_READ_ITEM: |
| 484 | request = (MainThreadRequest) msg.obj; |
| 485 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
| 486 | mPhone.nvReadItem((Integer) request.argument, onCompleted); |
| 487 | break; |
| 488 | |
| 489 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 490 | ar = (AsyncResult) msg.obj; |
| 491 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 492 | if (ar.exception == null && ar.result != null) { |
| 493 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 494 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 495 | request.result = ""; |
| 496 | if (ar.result == null) { |
| 497 | loge("nvReadItem: Empty response"); |
| 498 | } else if (ar.exception instanceof CommandException) { |
| 499 | loge("nvReadItem: CommandException: " + |
| 500 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 501 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 502 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 503 | } |
| 504 | } |
| 505 | synchronized (request) { |
| 506 | request.notifyAll(); |
| 507 | } |
| 508 | break; |
| 509 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 510 | case CMD_NV_WRITE_ITEM: |
| 511 | request = (MainThreadRequest) msg.obj; |
| 512 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 513 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
| 514 | mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted); |
| 515 | break; |
| 516 | |
| 517 | case EVENT_NV_WRITE_ITEM_DONE: |
| 518 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 519 | break; |
| 520 | |
| 521 | case CMD_NV_WRITE_CDMA_PRL: |
| 522 | request = (MainThreadRequest) msg.obj; |
| 523 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
| 524 | mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
| 525 | break; |
| 526 | |
| 527 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 528 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 529 | break; |
| 530 | |
| 531 | case CMD_NV_RESET_CONFIG: |
| 532 | request = (MainThreadRequest) msg.obj; |
| 533 | onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request); |
| 534 | mPhone.nvResetConfig((Integer) request.argument, onCompleted); |
| 535 | break; |
| 536 | |
| 537 | case EVENT_NV_RESET_CONFIG_DONE: |
| 538 | handleNullReturnEvent(msg, "nvResetConfig"); |
| 539 | break; |
| 540 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 541 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 542 | request = (MainThreadRequest) msg.obj; |
| 543 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 544 | mPhone.getPreferredNetworkType(onCompleted); |
| 545 | break; |
| 546 | |
| 547 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 548 | ar = (AsyncResult) msg.obj; |
| 549 | request = (MainThreadRequest) ar.userObj; |
| 550 | if (ar.exception == null && ar.result != null) { |
| 551 | request.result = ar.result; // Integer |
| 552 | } else { |
| 553 | request.result = -1; |
| 554 | if (ar.result == null) { |
| 555 | loge("getPreferredNetworkType: Empty response"); |
| 556 | } else if (ar.exception instanceof CommandException) { |
| 557 | loge("getPreferredNetworkType: CommandException: " + |
| 558 | ar.exception); |
| 559 | } else { |
| 560 | loge("getPreferredNetworkType: Unknown exception"); |
| 561 | } |
| 562 | } |
| 563 | synchronized (request) { |
| 564 | request.notifyAll(); |
| 565 | } |
| 566 | break; |
| 567 | |
| 568 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 569 | request = (MainThreadRequest) msg.obj; |
| 570 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 571 | int networkType = (Integer) request.argument; |
| 572 | mPhone.setPreferredNetworkType(networkType, onCompleted); |
| 573 | break; |
| 574 | |
| 575 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 576 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 577 | break; |
| 578 | |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 579 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 580 | request = (MainThreadRequest)msg.obj; |
| 581 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
| 582 | mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted); |
| 583 | break; |
| 584 | |
| 585 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 586 | ar = (AsyncResult)msg.obj; |
| 587 | request = (MainThreadRequest)ar.userObj; |
| 588 | request.result = ar; |
| 589 | synchronized (request) { |
| 590 | request.notifyAll(); |
| 591 | } |
| 592 | break; |
| 593 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 594 | case CMD_SET_VOICEMAIL_NUMBER: |
| 595 | request = (MainThreadRequest) msg.obj; |
| 596 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 597 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
| 598 | Phone phone = (request.subId == null) ? mPhone : getPhone(request.subId); |
| 599 | phone.setVoiceMailNumber(tagNum.first, tagNum.second, onCompleted); |
| 600 | break; |
| 601 | |
| 602 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 603 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 604 | break; |
| 605 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 606 | default: |
| 607 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 608 | break; |
| 609 | } |
| 610 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 611 | |
| 612 | private void handleNullReturnEvent(Message msg, String command) { |
| 613 | AsyncResult ar = (AsyncResult) msg.obj; |
| 614 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 615 | if (ar.exception == null) { |
| 616 | request.result = true; |
| 617 | } else { |
| 618 | request.result = false; |
| 619 | if (ar.exception instanceof CommandException) { |
| 620 | loge(command + ": CommandException: " + ar.exception); |
| 621 | } else { |
| 622 | loge(command + ": Unknown exception"); |
| 623 | } |
| 624 | } |
| 625 | synchronized (request) { |
| 626 | request.notifyAll(); |
| 627 | } |
| 628 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | /** |
| 632 | * Posts the specified command to be executed on the main thread, |
| 633 | * waits for the request to complete, and returns the result. |
| 634 | * @see #sendRequestAsync |
| 635 | */ |
| 636 | private Object sendRequest(int command, Object argument) { |
Santos Cordon | 500b0e0 | 2014-06-17 10:33:33 -0700 | [diff] [blame] | 637 | return sendRequest(command, argument, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | /** |
| 641 | * Posts the specified command to be executed on the main thread, |
| 642 | * waits for the request to complete, and returns the result. |
| 643 | * @see #sendRequestAsync |
| 644 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 645 | private Object sendRequest(int command, Object argument, Integer subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 646 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 647 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 648 | } |
| 649 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 650 | MainThreadRequest request = new MainThreadRequest(argument, subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 651 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 652 | msg.sendToTarget(); |
| 653 | |
| 654 | // Wait for the request to complete |
| 655 | synchronized (request) { |
| 656 | while (request.result == null) { |
| 657 | try { |
| 658 | request.wait(); |
| 659 | } catch (InterruptedException e) { |
| 660 | // Do nothing, go back and wait until the request is complete |
| 661 | } |
| 662 | } |
| 663 | } |
| 664 | return request.result; |
| 665 | } |
| 666 | |
| 667 | /** |
| 668 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 669 | * Posts the specified command to be executed on the main thread, and |
| 670 | * returns immediately. |
| 671 | * @see #sendRequest |
| 672 | */ |
| 673 | private void sendRequestAsync(int command) { |
| 674 | mMainThreadHandler.sendEmptyMessage(command); |
| 675 | } |
| 676 | |
| 677 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 678 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
| 679 | * @see {@link #sendRequest(int,Object)} |
| 680 | */ |
| 681 | private void sendRequestAsync(int command, Object argument) { |
| 682 | MainThreadRequest request = new MainThreadRequest(argument); |
| 683 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 684 | msg.sendToTarget(); |
| 685 | } |
| 686 | |
| 687 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 688 | * Initialize the singleton PhoneInterfaceManager instance. |
| 689 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 690 | */ |
Sailesh Nepal | 194161e | 2014-07-03 08:57:44 -0700 | [diff] [blame] | 691 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 692 | synchronized (PhoneInterfaceManager.class) { |
| 693 | if (sInstance == null) { |
Sailesh Nepal | 194161e | 2014-07-03 08:57:44 -0700 | [diff] [blame] | 694 | sInstance = new PhoneInterfaceManager(app, phone); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 695 | } else { |
| 696 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 697 | } |
| 698 | return sInstance; |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | /** Private constructor; @see init() */ |
Sailesh Nepal | 194161e | 2014-07-03 08:57:44 -0700 | [diff] [blame] | 703 | private PhoneInterfaceManager(PhoneGlobals app, Phone phone) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 704 | mApp = app; |
| 705 | mPhone = phone; |
| 706 | mCM = PhoneGlobals.getInstance().mCM; |
| 707 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 708 | mMainThreadHandler = new MainThreadHandler(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 709 | mTelephonySharedPreferences = |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 710 | PreferenceManager.getDefaultSharedPreferences(mPhone.getContext()); |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 711 | mSubscriptionController = SubscriptionController.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 712 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 713 | publish(); |
| 714 | } |
| 715 | |
| 716 | private void publish() { |
| 717 | if (DBG) log("publish: " + this); |
| 718 | |
| 719 | ServiceManager.addService("phone", this); |
| 720 | } |
| 721 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 722 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 723 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 724 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 725 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 726 | // |
| 727 | // Implementation of the ITelephony interface. |
| 728 | // |
| 729 | |
| 730 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 731 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 732 | } |
| 733 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 734 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 735 | if (DBG) log("dial: " + number); |
| 736 | // No permission check needed here: This is just a wrapper around the |
| 737 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 738 | // the UI before it does anything. |
| 739 | |
| 740 | String url = createTelUrl(number); |
| 741 | if (url == null) { |
| 742 | return; |
| 743 | } |
| 744 | |
| 745 | // PENDING: should we just silently fail if phone is offhook or ringing? |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 746 | PhoneConstants.State state = mCM.getState(subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 747 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 748 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 749 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 750 | mApp.startActivity(intent); |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 755 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 756 | } |
| 757 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 758 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 759 | if (DBG) log("call: " + number); |
| 760 | |
| 761 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 762 | // need to do a permission check since we're calling startActivity() |
| 763 | // from the context of the phone app. |
| 764 | enforceCallPermission(); |
| 765 | |
| 766 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
| 767 | != AppOpsManager.MODE_ALLOWED) { |
| 768 | return; |
| 769 | } |
| 770 | |
| 771 | String url = createTelUrl(number); |
| 772 | if (url == null) { |
| 773 | return; |
| 774 | } |
| 775 | |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 776 | boolean isValid = false; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 777 | List<SubscriptionInfo> slist = mSubscriptionController.getActiveSubscriptionInfoList(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 778 | if (slist != null) { |
| 779 | for (SubscriptionInfo subInfoRecord : slist) { |
| 780 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 781 | isValid = true; |
| 782 | break; |
| 783 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 784 | } |
| 785 | } |
| 786 | if (isValid == false) { |
| 787 | return; |
| 788 | } |
| 789 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 790 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 791 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 792 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 793 | mApp.startActivity(intent); |
| 794 | } |
| 795 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 796 | /** |
| 797 | * End a call based on call state |
| 798 | * @return true is a call was ended |
| 799 | */ |
| 800 | public boolean endCall() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 801 | return endCallForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | /** |
| 805 | * End a call based on the call state of the subId |
| 806 | * @return true is a call was ended |
| 807 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 808 | public boolean endCallForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 809 | enforceCallPermission(); |
Wink Saville | 9f73bda | 2014-11-05 08:13:36 -0800 | [diff] [blame] | 810 | return (Boolean) sendRequest(CMD_END_CALL, new Integer(subId), null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | public void answerRingingCall() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 814 | answerRingingCallForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 815 | } |
| 816 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 817 | public void answerRingingCallForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 818 | if (DBG) log("answerRingingCall..."); |
| 819 | // TODO: there should eventually be a separate "ANSWER_PHONE" permission, |
| 820 | // but that can probably wait till the big TelephonyManager API overhaul. |
| 821 | // For now, protect this call with the MODIFY_PHONE_STATE permission. |
| 822 | enforceModifyPermission(); |
Wink Saville | 9f73bda | 2014-11-05 08:13:36 -0800 | [diff] [blame] | 823 | sendRequest(CMD_ANSWER_RINGING_CALL, new Integer(subId), null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | /** |
| 827 | * Make the actual telephony calls to implement answerRingingCall(). |
| 828 | * This should only be called from the main thread of the Phone app. |
| 829 | * @see #answerRingingCall |
| 830 | * |
| 831 | * TODO: it would be nice to return true if we answered the call, or |
| 832 | * false if there wasn't actually a ringing incoming call, or some |
| 833 | * other error occurred. (In other words, pass back the return value |
| 834 | * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().) |
| 835 | * But that would require calling this method via sendRequest() rather |
| 836 | * than sendRequestAsync(), and right now we don't actually *need* that |
| 837 | * return value, so let's just return void for now. |
| 838 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 839 | private void answerRingingCallInternal(int subId) { |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 840 | final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 841 | if (hasRingingCall) { |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 842 | final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle(); |
| 843 | final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 844 | if (hasActiveCall && hasHoldingCall) { |
| 845 | // Both lines are in use! |
| 846 | // TODO: provide a flag to let the caller specify what |
| 847 | // policy to use if both lines are in use. (The current |
| 848 | // behavior is hardwired to "answer incoming, end ongoing", |
| 849 | // which is how the CALL button is specced to behave.) |
| 850 | PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall()); |
| 851 | return; |
| 852 | } else { |
| 853 | // answerCall() will automatically hold the current active |
| 854 | // call, if there is one. |
| 855 | PhoneUtils.answerCall(mCM.getFirstActiveRingingCall()); |
| 856 | return; |
| 857 | } |
| 858 | } else { |
| 859 | // No call was ringing. |
| 860 | return; |
| 861 | } |
| 862 | } |
| 863 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 864 | /** |
Santos Cordon | 5422a8d | 2014-09-12 04:20:56 -0700 | [diff] [blame] | 865 | * 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] | 866 | */ |
Santos Cordon | 5422a8d | 2014-09-12 04:20:56 -0700 | [diff] [blame] | 867 | public void silenceRinger() { |
| 868 | Log.e(LOG_TAG, "silenseRinger not supported"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | public boolean isOffhook() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 872 | return isOffhookForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 873 | } |
| 874 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 875 | public boolean isOffhookForSubscriber(int subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 876 | return (getPhone(subId).getState() == PhoneConstants.State.OFFHOOK); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | public boolean isRinging() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 880 | return (isRingingForSubscriber(getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 881 | } |
| 882 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 883 | public boolean isRingingForSubscriber(int subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 884 | return (getPhone(subId).getState() == PhoneConstants.State.RINGING); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | public boolean isIdle() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 888 | return isIdleForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 889 | } |
| 890 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 891 | public boolean isIdleForSubscriber(int subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 892 | return (getPhone(subId).getState() == PhoneConstants.State.IDLE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | public boolean isSimPinEnabled() { |
| 896 | enforceReadPermission(); |
| 897 | return (PhoneGlobals.getInstance().isSimPinEnabled()); |
| 898 | } |
| 899 | |
| 900 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 901 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 902 | } |
| 903 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 904 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 905 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 906 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 907 | } |
| 908 | |
| 909 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 910 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 911 | } |
| 912 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 913 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 914 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 915 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 916 | } |
| 917 | |
| 918 | /** {@hide} */ |
| 919 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 920 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 921 | } |
| 922 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 923 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 924 | enforceModifyPermission(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 925 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 926 | checkSimPin.start(); |
| 927 | return checkSimPin.unlockSim(null, pin); |
| 928 | } |
| 929 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 930 | /** {@hide} */ |
| 931 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 932 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 933 | } |
| 934 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 935 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 936 | enforceModifyPermission(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 937 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 938 | checkSimPuk.start(); |
| 939 | return checkSimPuk.unlockSim(puk, pin); |
| 940 | } |
| 941 | |
| 942 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 943 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 944 | * a synchronous one. |
| 945 | */ |
| 946 | private static class UnlockSim extends Thread { |
| 947 | |
| 948 | private final IccCard mSimCard; |
| 949 | |
| 950 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 951 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 952 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 953 | |
| 954 | // For replies from SimCard interface |
| 955 | private Handler mHandler; |
| 956 | |
| 957 | // For async handler to identify request type |
| 958 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 959 | |
| 960 | public UnlockSim(IccCard simCard) { |
| 961 | mSimCard = simCard; |
| 962 | } |
| 963 | |
| 964 | @Override |
| 965 | public void run() { |
| 966 | Looper.prepare(); |
| 967 | synchronized (UnlockSim.this) { |
| 968 | mHandler = new Handler() { |
| 969 | @Override |
| 970 | public void handleMessage(Message msg) { |
| 971 | AsyncResult ar = (AsyncResult) msg.obj; |
| 972 | switch (msg.what) { |
| 973 | case SUPPLY_PIN_COMPLETE: |
| 974 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 975 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 976 | mRetryCount = msg.arg1; |
| 977 | if (ar.exception != null) { |
| 978 | if (ar.exception instanceof CommandException && |
| 979 | ((CommandException)(ar.exception)).getCommandError() |
| 980 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 981 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 982 | } else { |
| 983 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 984 | } |
| 985 | } else { |
| 986 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 987 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 988 | mDone = true; |
| 989 | UnlockSim.this.notifyAll(); |
| 990 | } |
| 991 | break; |
| 992 | } |
| 993 | } |
| 994 | }; |
| 995 | UnlockSim.this.notifyAll(); |
| 996 | } |
| 997 | Looper.loop(); |
| 998 | } |
| 999 | |
| 1000 | /* |
| 1001 | * Use PIN or PUK to unlock SIM card |
| 1002 | * |
| 1003 | * If PUK is null, unlock SIM card with PIN |
| 1004 | * |
| 1005 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1006 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1007 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1008 | |
| 1009 | while (mHandler == null) { |
| 1010 | try { |
| 1011 | wait(); |
| 1012 | } catch (InterruptedException e) { |
| 1013 | Thread.currentThread().interrupt(); |
| 1014 | } |
| 1015 | } |
| 1016 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1017 | |
| 1018 | if (puk == null) { |
| 1019 | mSimCard.supplyPin(pin, callback); |
| 1020 | } else { |
| 1021 | mSimCard.supplyPuk(puk, pin, callback); |
| 1022 | } |
| 1023 | |
| 1024 | while (!mDone) { |
| 1025 | try { |
| 1026 | Log.d(LOG_TAG, "wait for done"); |
| 1027 | wait(); |
| 1028 | } catch (InterruptedException e) { |
| 1029 | // Restore the interrupted status |
| 1030 | Thread.currentThread().interrupt(); |
| 1031 | } |
| 1032 | } |
| 1033 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1034 | int[] resultArray = new int[2]; |
| 1035 | resultArray[0] = mResult; |
| 1036 | resultArray[1] = mRetryCount; |
| 1037 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1038 | } |
| 1039 | } |
| 1040 | |
| 1041 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1042 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1043 | |
| 1044 | } |
| 1045 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1046 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1047 | // No permission check needed here: this call is harmless, and it's |
| 1048 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1049 | // already intentionally exposed to 3rd parties.) |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1050 | getPhone(subId).updateServiceLocation(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | public boolean isRadioOn() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1054 | return isRadioOnForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1055 | } |
| 1056 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1057 | public boolean isRadioOnForSubscriber(int subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1058 | return getPhone(subId).getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1062 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1063 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1064 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1065 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1066 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1067 | enforceModifyPermission(); |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1068 | getPhone(subId).setRadioPower(!isRadioOnForSubscriber(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1072 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1073 | } |
| 1074 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1075 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1076 | enforceModifyPermission(); |
| 1077 | if ((getPhone(subId).getServiceState().getState() != |
| 1078 | ServiceState.STATE_POWER_OFF) != turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1079 | toggleRadioOnOffForSubscriber(subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1080 | } |
| 1081 | return true; |
| 1082 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1083 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1084 | public boolean needMobileRadioShutdown() { |
| 1085 | /* |
| 1086 | * If any of the Radios are available, it will need to be |
| 1087 | * shutdown. So return true if any Radio is available. |
| 1088 | */ |
| 1089 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1090 | Phone phone = PhoneFactory.getPhone(i); |
| 1091 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1092 | } |
| 1093 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1094 | return false; |
| 1095 | } |
| 1096 | |
| 1097 | public void shutdownMobileRadios() { |
| 1098 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1099 | logv("Shutting down Phone " + i); |
| 1100 | shutdownRadioUsingPhoneId(i); |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | private void shutdownRadioUsingPhoneId(int phoneId) { |
| 1105 | enforceModifyPermission(); |
| 1106 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1107 | if (phone != null && phone.isRadioAvailable()) { |
| 1108 | phone.shutdownRadio(); |
| 1109 | } |
| 1110 | } |
| 1111 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1112 | public boolean setRadioPower(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1113 | return setRadioPowerForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1114 | } |
| 1115 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1116 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1117 | enforceModifyPermission(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1118 | getPhone(subId).setRadioPower(turnOn); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1119 | return true; |
| 1120 | } |
| 1121 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1122 | // FIXME: subId version needed |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1123 | public boolean enableDataConnectivity() { |
| 1124 | enforceModifyPermission(); |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1125 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1126 | getPhone(subId).setDataEnabled(true); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1127 | return true; |
| 1128 | } |
| 1129 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1130 | // FIXME: subId version needed |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1131 | public boolean disableDataConnectivity() { |
| 1132 | enforceModifyPermission(); |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1133 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1134 | getPhone(subId).setDataEnabled(false); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1135 | return true; |
| 1136 | } |
| 1137 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1138 | // FIXME: subId version needed |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1139 | public boolean isDataConnectivityPossible() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1140 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1141 | return getPhone(subId).isDataConnectivityPossible(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1145 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1146 | } |
| 1147 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1148 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1149 | enforceModifyPermission(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1150 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1151 | } |
| 1152 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1153 | public int getCallState() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1154 | return getCallStateForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1155 | } |
| 1156 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1157 | public int getCallStateForSubscriber(int subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1158 | return DefaultPhoneNotifier.convertCallState(getPhone(subId).getState()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | public int getDataState() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1162 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1163 | return DefaultPhoneNotifier.convertDataState(phone.getDataConnectionState()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | public int getDataActivity() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1167 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1168 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | @Override |
| 1172 | public Bundle getCellLocation() { |
| 1173 | try { |
| 1174 | mApp.enforceCallingOrSelfPermission( |
| 1175 | android.Manifest.permission.ACCESS_FINE_LOCATION, null); |
| 1176 | } catch (SecurityException e) { |
| 1177 | // If we have ACCESS_FINE_LOCATION permission, skip the check for ACCESS_COARSE_LOCATION |
| 1178 | // A failure should throw the SecurityException from ACCESS_COARSE_LOCATION since this |
| 1179 | // is the weaker precondition |
| 1180 | mApp.enforceCallingOrSelfPermission( |
| 1181 | android.Manifest.permission.ACCESS_COARSE_LOCATION, null); |
| 1182 | } |
| 1183 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1184 | if (checkIfCallerIsSelfOrForegroundUser()) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1185 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1186 | Bundle data = new Bundle(); |
| 1187 | mPhone.getCellLocation().fillInNotifierBundle(data); |
| 1188 | return data; |
| 1189 | } else { |
| 1190 | if (DBG_LOC) log("getCellLocation: suppress non-active user"); |
| 1191 | return null; |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | @Override |
| 1196 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1197 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1198 | } |
| 1199 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1200 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1201 | mApp.enforceCallingOrSelfPermission( |
| 1202 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1203 | getPhone(subId).enableLocationUpdates(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | @Override |
| 1207 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1208 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1209 | } |
| 1210 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1211 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1212 | mApp.enforceCallingOrSelfPermission( |
| 1213 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1214 | getPhone(subId).disableLocationUpdates(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | @Override |
| 1218 | @SuppressWarnings("unchecked") |
| 1219 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 1220 | try { |
| 1221 | mApp.enforceCallingOrSelfPermission( |
| 1222 | android.Manifest.permission.ACCESS_FINE_LOCATION, null); |
| 1223 | } catch (SecurityException e) { |
| 1224 | // If we have ACCESS_FINE_LOCATION permission, skip the check |
| 1225 | // for ACCESS_COARSE_LOCATION |
| 1226 | // A failure should throw the SecurityException from |
| 1227 | // ACCESS_COARSE_LOCATION since this is the weaker precondition |
| 1228 | mApp.enforceCallingOrSelfPermission( |
| 1229 | android.Manifest.permission.ACCESS_COARSE_LOCATION, null); |
| 1230 | } |
| 1231 | |
| 1232 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), |
| 1233 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 1234 | return null; |
| 1235 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1236 | if (checkIfCallerIsSelfOrForegroundUser()) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1237 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
| 1238 | |
| 1239 | ArrayList<NeighboringCellInfo> cells = null; |
| 1240 | |
| 1241 | try { |
| 1242 | cells = (ArrayList<NeighboringCellInfo>) sendRequest( |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1243 | CMD_HANDLE_NEIGHBORING_CELL, null, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1244 | } catch (RuntimeException e) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1245 | Log.e(LOG_TAG, "getNeighboringCellInfo " + e); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1246 | } |
| 1247 | return cells; |
| 1248 | } else { |
| 1249 | if (DBG_LOC) log("getNeighboringCellInfo: suppress non-active user"); |
| 1250 | return null; |
| 1251 | } |
| 1252 | } |
| 1253 | |
| 1254 | |
| 1255 | @Override |
| 1256 | public List<CellInfo> getAllCellInfo() { |
| 1257 | try { |
| 1258 | mApp.enforceCallingOrSelfPermission( |
| 1259 | android.Manifest.permission.ACCESS_FINE_LOCATION, null); |
| 1260 | } catch (SecurityException e) { |
| 1261 | // If we have ACCESS_FINE_LOCATION permission, skip the check for ACCESS_COARSE_LOCATION |
| 1262 | // A failure should throw the SecurityException from ACCESS_COARSE_LOCATION since this |
| 1263 | // is the weaker precondition |
| 1264 | mApp.enforceCallingOrSelfPermission( |
| 1265 | android.Manifest.permission.ACCESS_COARSE_LOCATION, null); |
| 1266 | } |
| 1267 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1268 | if (checkIfCallerIsSelfOrForegroundUser()) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1269 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
| 1270 | return mPhone.getAllCellInfo(); |
| 1271 | } else { |
| 1272 | if (DBG_LOC) log("getAllCellInfo: suppress non-active user"); |
| 1273 | return null; |
| 1274 | } |
| 1275 | } |
| 1276 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1277 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1278 | public void setCellInfoListRate(int rateInMillis) { |
| 1279 | mPhone.setCellInfoListRate(rateInMillis); |
| 1280 | } |
| 1281 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1282 | // |
| 1283 | // Internal helper methods. |
| 1284 | // |
| 1285 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1286 | private static boolean checkIfCallerIsSelfOrForegroundUser() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1287 | boolean ok; |
| 1288 | |
| 1289 | boolean self = Binder.getCallingUid() == Process.myUid(); |
| 1290 | if (!self) { |
| 1291 | // Get the caller's user id then clear the calling identity |
| 1292 | // which will be restored in the finally clause. |
| 1293 | int callingUser = UserHandle.getCallingUserId(); |
| 1294 | long ident = Binder.clearCallingIdentity(); |
| 1295 | |
| 1296 | try { |
| 1297 | // With calling identity cleared the current user is the foreground user. |
| 1298 | int foregroundUser = ActivityManager.getCurrentUser(); |
| 1299 | ok = (foregroundUser == callingUser); |
| 1300 | if (DBG_LOC) { |
| 1301 | log("checkIfCallerIsSelfOrForegoundUser: foregroundUser=" + foregroundUser |
| 1302 | + " callingUser=" + callingUser + " ok=" + ok); |
| 1303 | } |
| 1304 | } catch (Exception ex) { |
| 1305 | if (DBG_LOC) loge("checkIfCallerIsSelfOrForegoundUser: Exception ex=" + ex); |
| 1306 | ok = false; |
| 1307 | } finally { |
| 1308 | Binder.restoreCallingIdentity(ident); |
| 1309 | } |
| 1310 | } else { |
| 1311 | if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: is self"); |
| 1312 | ok = true; |
| 1313 | } |
| 1314 | if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: ret=" + ok); |
| 1315 | return ok; |
| 1316 | } |
| 1317 | |
| 1318 | /** |
| 1319 | * Make sure the caller has the READ_PHONE_STATE permission. |
| 1320 | * |
| 1321 | * @throws SecurityException if the caller does not have the required permission |
| 1322 | */ |
| 1323 | private void enforceReadPermission() { |
| 1324 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, null); |
| 1325 | } |
| 1326 | |
| 1327 | /** |
| 1328 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 1329 | * |
| 1330 | * @throws SecurityException if the caller does not have the required permission |
| 1331 | */ |
| 1332 | private void enforceModifyPermission() { |
| 1333 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 1334 | } |
| 1335 | |
| 1336 | /** |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1337 | * Make sure either system app or the caller has carrier privilege. |
| 1338 | * |
| 1339 | * @throws SecurityException if the caller does not have the required permission/privilege |
| 1340 | */ |
| 1341 | private void enforceModifyPermissionOrCarrierPrivilege() { |
Shishir Agrawal | f1ac4c9 | 2014-07-14 13:54:28 -0700 | [diff] [blame] | 1342 | int permission = mApp.checkCallingOrSelfPermission( |
| 1343 | android.Manifest.permission.MODIFY_PHONE_STATE); |
| 1344 | if (permission == PackageManager.PERMISSION_GRANTED) { |
| 1345 | return; |
| 1346 | } |
| 1347 | |
| 1348 | log("No modify permission, check carrier privilege next."); |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 1349 | if (getCarrierPrivilegeStatus() != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Shishir Agrawal | f1ac4c9 | 2014-07-14 13:54:28 -0700 | [diff] [blame] | 1350 | loge("No Carrier Privilege."); |
| 1351 | throw new SecurityException("No modify permission or carrier privilege."); |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1352 | } |
| 1353 | } |
| 1354 | |
| 1355 | /** |
| 1356 | * Make sure the caller has carrier privilege. |
| 1357 | * |
| 1358 | * @throws SecurityException if the caller does not have the required permission |
| 1359 | */ |
| 1360 | private void enforceCarrierPrivilege() { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 1361 | if (getCarrierPrivilegeStatus() != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Shishir Agrawal | f1ac4c9 | 2014-07-14 13:54:28 -0700 | [diff] [blame] | 1362 | loge("No Carrier Privilege."); |
| 1363 | throw new SecurityException("No Carrier Privilege."); |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1364 | } |
| 1365 | } |
| 1366 | |
| 1367 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1368 | * Make sure the caller has the CALL_PHONE permission. |
| 1369 | * |
| 1370 | * @throws SecurityException if the caller does not have the required permission |
| 1371 | */ |
| 1372 | private void enforceCallPermission() { |
| 1373 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 1374 | } |
| 1375 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1376 | /** |
Gabriel Peal | 36ebb0d | 2014-03-20 09:20:43 -0700 | [diff] [blame] | 1377 | * Make sure the caller has the READ_PRIVILEGED_PHONE_STATE permission. |
| 1378 | * |
| 1379 | * @throws SecurityException if the caller does not have the required permission |
| 1380 | */ |
| 1381 | private void enforcePrivilegedPhoneStatePermission() { |
| 1382 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 1383 | null); |
| 1384 | } |
| 1385 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1386 | private String createTelUrl(String number) { |
| 1387 | if (TextUtils.isEmpty(number)) { |
| 1388 | return null; |
| 1389 | } |
| 1390 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1391 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1392 | } |
| 1393 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 1394 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1395 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 1396 | } |
| 1397 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1398 | private static void logv(String msg) { |
| 1399 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 1400 | } |
| 1401 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 1402 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1403 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 1404 | } |
| 1405 | |
| 1406 | public int getActivePhoneType() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1407 | return getActivePhoneTypeForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1410 | public int getActivePhoneTypeForSubscriber(int subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1411 | return getPhone(subId).getPhoneType(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1412 | } |
| 1413 | |
| 1414 | /** |
| 1415 | * Returns the CDMA ERI icon index to display |
| 1416 | */ |
| 1417 | public int getCdmaEriIconIndex() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1418 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1419 | |
| 1420 | } |
| 1421 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1422 | public int getCdmaEriIconIndexForSubscriber(int subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1423 | return getPhone(subId).getCdmaEriIconIndex(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | /** |
| 1427 | * Returns the CDMA ERI icon mode, |
| 1428 | * 0 - ON |
| 1429 | * 1 - FLASHING |
| 1430 | */ |
| 1431 | public int getCdmaEriIconMode() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1432 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1433 | } |
| 1434 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1435 | public int getCdmaEriIconModeForSubscriber(int subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1436 | return getPhone(subId).getCdmaEriIconMode(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | /** |
| 1440 | * Returns the CDMA ERI text, |
| 1441 | */ |
| 1442 | public String getCdmaEriText() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1443 | return getCdmaEriTextForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1444 | } |
| 1445 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1446 | public String getCdmaEriTextForSubscriber(int subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1447 | return getPhone(subId).getCdmaEriText(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1448 | } |
| 1449 | |
| 1450 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 1451 | * Returns the CDMA MDN. |
| 1452 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1453 | public String getCdmaMdn(int subId) { |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 1454 | enforceModifyPermissionOrCarrierPrivilege(); |
| 1455 | if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 1456 | return getPhone(subId).getLine1Number(); |
| 1457 | } else { |
| 1458 | return null; |
| 1459 | } |
| 1460 | } |
| 1461 | |
| 1462 | /** |
| 1463 | * Returns the CDMA MIN. |
| 1464 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1465 | public String getCdmaMin(int subId) { |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 1466 | enforceModifyPermissionOrCarrierPrivilege(); |
| 1467 | if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 1468 | return getPhone(subId).getCdmaMin(); |
| 1469 | } else { |
| 1470 | return null; |
| 1471 | } |
| 1472 | } |
| 1473 | |
| 1474 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1475 | * Returns true if CDMA provisioning needs to run. |
| 1476 | */ |
| 1477 | public boolean needsOtaServiceProvisioning() { |
| 1478 | return mPhone.needsOtaServiceProvisioning(); |
| 1479 | } |
| 1480 | |
| 1481 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1482 | * Sets the voice mail number of a given subId. |
| 1483 | */ |
| 1484 | @Override |
| 1485 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 1486 | enforceCarrierPrivilege(); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1487 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 1488 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 1489 | return success; |
| 1490 | } |
| 1491 | |
| 1492 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1493 | * Returns the unread count of voicemails |
| 1494 | */ |
| 1495 | public int getVoiceMessageCount() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1496 | return getVoiceMessageCountForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | /** |
| 1500 | * Returns the unread count of voicemails for a subId |
| 1501 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1502 | public int getVoiceMessageCountForSubscriber( int subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1503 | return getPhone(subId).getVoiceMessageCount(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1504 | } |
| 1505 | |
| 1506 | /** |
| 1507 | * Returns the data network type |
| 1508 | * |
| 1509 | * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}. |
| 1510 | */ |
| 1511 | @Override |
| 1512 | public int getNetworkType() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1513 | return getNetworkTypeForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1514 | } |
| 1515 | |
| 1516 | /** |
| 1517 | * Returns the network type for a subId |
| 1518 | */ |
| 1519 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1520 | public int getNetworkTypeForSubscriber(int subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1521 | return getPhone(subId).getServiceState().getDataNetworkType(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | /** |
| 1525 | * Returns the data network type |
| 1526 | */ |
| 1527 | @Override |
| 1528 | public int getDataNetworkType() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1529 | return getDataNetworkTypeForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1530 | } |
| 1531 | |
| 1532 | /** |
| 1533 | * Returns the data network type for a subId |
| 1534 | */ |
| 1535 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1536 | public int getDataNetworkTypeForSubscriber(int subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1537 | return getPhone(subId).getServiceState().getDataNetworkType(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | /** |
| 1541 | * Returns the data network type |
| 1542 | */ |
| 1543 | @Override |
| 1544 | public int getVoiceNetworkType() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1545 | return getVoiceNetworkTypeForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | /** |
| 1549 | * Returns the Voice network type for a subId |
| 1550 | */ |
| 1551 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1552 | public int getVoiceNetworkTypeForSubscriber(int subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1553 | return getPhone(subId).getServiceState().getVoiceNetworkType(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | /** |
| 1557 | * @return true if a ICC card is present |
| 1558 | */ |
| 1559 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1560 | // FIXME Make changes to pass defaultSimId of type int |
| 1561 | return hasIccCardUsingSlotId(getDefaultSubscription()); |
| 1562 | } |
| 1563 | |
| 1564 | /** |
| 1565 | * @return true if a ICC card is present for a slotId |
| 1566 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1567 | public boolean hasIccCardUsingSlotId(int slotId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1568 | return getPhone(slotId).getIccCard().hasIccCard(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | /** |
| 1572 | * Return if the current radio is LTE on CDMA. This |
| 1573 | * is a tri-state return value as for a period of time |
| 1574 | * the mode may be unknown. |
| 1575 | * |
| 1576 | * @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] | 1577 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1578 | */ |
| 1579 | public int getLteOnCdmaMode() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1580 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1581 | } |
| 1582 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1583 | public int getLteOnCdmaModeForSubscriber(int subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1584 | return getPhone(subId).getLteOnCdmaMode(); |
| 1585 | } |
| 1586 | |
| 1587 | public void setPhone(Phone phone) { |
| 1588 | mPhone = phone; |
| 1589 | } |
| 1590 | |
| 1591 | /** |
| 1592 | * {@hide} |
| 1593 | * Returns Default subId, 0 in the case of single standby. |
| 1594 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1595 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1596 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1597 | } |
| 1598 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1599 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1600 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1601 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 1602 | |
| 1603 | /** |
| 1604 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 1605 | */ |
| 1606 | public int getWhenToMakeWifiCalls() { |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 1607 | return Settings.System.getInt(mPhone.getContext().getContentResolver(), |
| 1608 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference()); |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 1609 | } |
| 1610 | |
| 1611 | /** |
| 1612 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 1613 | */ |
| 1614 | public void setWhenToMakeWifiCalls(int preference) { |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 1615 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
| 1616 | Settings.System.putInt(mPhone.getContext().getContentResolver(), |
| 1617 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 1618 | } |
| 1619 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 1620 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 1621 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 1622 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 1623 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 1624 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1625 | @Override |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1626 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID) { |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1627 | enforceModifyPermissionOrCarrierPrivilege(); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1628 | |
| 1629 | if (DBG) log("iccOpenLogicalChannel: " + AID); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1630 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest( |
| 1631 | CMD_OPEN_CHANNEL, AID); |
| 1632 | if (DBG) log("iccOpenLogicalChannel: " + response); |
| 1633 | return response; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1634 | } |
| 1635 | |
| 1636 | @Override |
| 1637 | public boolean iccCloseLogicalChannel(int channel) { |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1638 | enforceModifyPermissionOrCarrierPrivilege(); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1639 | |
| 1640 | if (DBG) log("iccCloseLogicalChannel: " + channel); |
| 1641 | if (channel < 0) { |
| 1642 | return false; |
| 1643 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1644 | Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1645 | if (DBG) log("iccCloseLogicalChannel: " + success); |
| 1646 | return success; |
| 1647 | } |
| 1648 | |
| 1649 | @Override |
| 1650 | public String iccTransmitApduLogicalChannel(int channel, int cla, |
| 1651 | int command, int p1, int p2, int p3, String data) { |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1652 | enforceModifyPermissionOrCarrierPrivilege(); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1653 | |
| 1654 | if (DBG) { |
| 1655 | log("iccTransmitApduLogicalChannel: chnl=" + channel + " cla=" + cla + |
| 1656 | " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + |
| 1657 | " data=" + data); |
| 1658 | } |
| 1659 | |
| 1660 | if (channel < 0) { |
| 1661 | return ""; |
| 1662 | } |
| 1663 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1664 | IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1665 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data)); |
| 1666 | if (DBG) log("iccTransmitApduLogicalChannel: " + response); |
| 1667 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1668 | // Append the returned status code to the end of the response payload. |
| 1669 | String s = Integer.toHexString( |
| 1670 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 1671 | if (response.payload != null) { |
| 1672 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 1673 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1674 | return s; |
| 1675 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1676 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 1677 | @Override |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1678 | public String iccTransmitApduBasicChannel(int cla, int command, int p1, int p2, |
| 1679 | int p3, String data) { |
| 1680 | enforceModifyPermissionOrCarrierPrivilege(); |
| 1681 | |
| 1682 | if (DBG) { |
| 1683 | log("iccTransmitApduBasicChannel: cla=" + cla + " cmd=" + command + " p1=" |
| 1684 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 1685 | } |
| 1686 | |
| 1687 | IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
| 1688 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data)); |
| 1689 | if (DBG) log("iccTransmitApduBasicChannel: " + response); |
| 1690 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1691 | // Append the returned status code to the end of the response payload. |
| 1692 | String s = Integer.toHexString( |
| 1693 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 1694 | if (response.payload != null) { |
| 1695 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 1696 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1697 | return s; |
| 1698 | } |
| 1699 | |
| 1700 | @Override |
| 1701 | public byte[] iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3, |
| 1702 | String filePath) { |
| 1703 | enforceModifyPermissionOrCarrierPrivilege(); |
| 1704 | |
| 1705 | if (DBG) { |
| 1706 | log("Exchange SIM_IO " + fileID + ":" + command + " " + |
| 1707 | p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 1708 | } |
| 1709 | |
| 1710 | IccIoResult response = |
| 1711 | (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO, |
Yong Jiang | 3edf378 | 2014-10-03 13:23:28 -0500 | [diff] [blame] | 1712 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath)); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1713 | |
| 1714 | if (DBG) { |
| 1715 | log("Exchange SIM_IO [R]" + response); |
| 1716 | } |
| 1717 | |
| 1718 | byte[] result = null; |
| 1719 | int length = 2; |
| 1720 | if (response.payload != null) { |
| 1721 | length = 2 + response.payload.length; |
| 1722 | result = new byte[length]; |
| 1723 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 1724 | } else { |
| 1725 | result = new byte[length]; |
| 1726 | } |
| 1727 | |
| 1728 | result[length - 1] = (byte) response.sw2; |
| 1729 | result[length - 2] = (byte) response.sw1; |
| 1730 | return result; |
| 1731 | } |
| 1732 | |
| 1733 | @Override |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 1734 | public String sendEnvelopeWithStatus(String content) { |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1735 | enforceModifyPermissionOrCarrierPrivilege(); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 1736 | |
| 1737 | IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content); |
| 1738 | if (response.payload == null) { |
| 1739 | return ""; |
| 1740 | } |
| 1741 | |
| 1742 | // Append the returned status code to the end of the response payload. |
| 1743 | String s = Integer.toHexString( |
| 1744 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 1745 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 1746 | return s; |
| 1747 | } |
| 1748 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1749 | /** |
| 1750 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 1751 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 1752 | * |
| 1753 | * @param itemID the ID of the item to read |
| 1754 | * @return the NV item as a String, or null on error. |
| 1755 | */ |
| 1756 | @Override |
| 1757 | public String nvReadItem(int itemID) { |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1758 | enforceModifyPermissionOrCarrierPrivilege(); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1759 | if (DBG) log("nvReadItem: item " + itemID); |
| 1760 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID); |
| 1761 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 1762 | return value; |
| 1763 | } |
| 1764 | |
| 1765 | /** |
| 1766 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 1767 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 1768 | * |
| 1769 | * @param itemID the ID of the item to read |
| 1770 | * @param itemValue the value to write, as a String |
| 1771 | * @return true on success; false on any failure |
| 1772 | */ |
| 1773 | @Override |
| 1774 | public boolean nvWriteItem(int itemID, String itemValue) { |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1775 | enforceModifyPermissionOrCarrierPrivilege(); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1776 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 1777 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
| 1778 | new Pair<Integer, String>(itemID, itemValue)); |
| 1779 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 1780 | return success; |
| 1781 | } |
| 1782 | |
| 1783 | /** |
| 1784 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 1785 | * Used for device configuration by some CDMA operators. |
| 1786 | * |
| 1787 | * @param preferredRoamingList byte array containing the new PRL |
| 1788 | * @return true on success; false on any failure |
| 1789 | */ |
| 1790 | @Override |
| 1791 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1792 | enforceModifyPermissionOrCarrierPrivilege(); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1793 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 1794 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 1795 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 1796 | return success; |
| 1797 | } |
| 1798 | |
| 1799 | /** |
| 1800 | * Perform the specified type of NV config reset. |
| 1801 | * Used for device configuration by some CDMA operators. |
| 1802 | * |
| 1803 | * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset) |
| 1804 | * @return true on success; false on any failure |
| 1805 | */ |
| 1806 | @Override |
| 1807 | public boolean nvResetConfig(int resetType) { |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1808 | enforceModifyPermissionOrCarrierPrivilege(); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1809 | if (DBG) log("nvResetConfig: type " + resetType); |
| 1810 | Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType); |
| 1811 | if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail")); |
| 1812 | return success; |
| 1813 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1814 | |
| 1815 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1816 | * {@hide} |
| 1817 | * Returns Default sim, 0 in the case of single standby. |
| 1818 | */ |
| 1819 | public int getDefaultSim() { |
| 1820 | //TODO Need to get it from Telephony Devcontroller |
| 1821 | return 0; |
| 1822 | } |
| 1823 | |
ram | 87fca6f | 2014-07-18 18:58:44 +0530 | [diff] [blame] | 1824 | public String[] getPcscfAddress(String apnType) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1825 | enforceReadPermission(); |
ram | 87fca6f | 2014-07-18 18:58:44 +0530 | [diff] [blame] | 1826 | return mPhone.getPcscfAddress(apnType); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1827 | } |
| 1828 | |
| 1829 | public void setImsRegistrationState(boolean registered) { |
| 1830 | enforceModifyPermission(); |
| 1831 | mPhone.setImsRegistrationState(registered); |
| 1832 | } |
| 1833 | |
| 1834 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 1835 | * Get the calculated preferred network type. |
| 1836 | * Used for debugging incorrect network type. |
| 1837 | * |
| 1838 | * @return the preferred network type, defined in RILConstants.java. |
| 1839 | */ |
| 1840 | @Override |
| 1841 | public int getCalculatedPreferredNetworkType() { |
| 1842 | enforceReadPermission(); |
Amit Mahajan | 43330e0 | 2014-11-18 11:54:45 -0800 | [diff] [blame] | 1843 | 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] | 1844 | } |
| 1845 | |
| 1846 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1847 | * Get the preferred network type. |
| 1848 | * Used for device configuration by some CDMA operators. |
| 1849 | * |
| 1850 | * @return the preferred network type, defined in RILConstants.java. |
| 1851 | */ |
| 1852 | @Override |
| 1853 | public int getPreferredNetworkType() { |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1854 | enforceModifyPermissionOrCarrierPrivilege(); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1855 | if (DBG) log("getPreferredNetworkType"); |
| 1856 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null); |
| 1857 | int networkType = (result != null ? result[0] : -1); |
| 1858 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 1859 | return networkType; |
| 1860 | } |
| 1861 | |
| 1862 | /** |
| 1863 | * Set the preferred network type. |
| 1864 | * Used for device configuration by some CDMA operators. |
| 1865 | * |
| 1866 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 1867 | * @return true on success; false on any failure. |
| 1868 | */ |
| 1869 | @Override |
| 1870 | public boolean setPreferredNetworkType(int networkType) { |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1871 | enforceModifyPermissionOrCarrierPrivilege(); |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 1872 | final int phoneSubId = mPhone.getSubId(); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1873 | if (DBG) log("setPreferredNetworkType: type " + networkType); |
| 1874 | Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType); |
| 1875 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 1876 | if (success) { |
| 1877 | Settings.Global.putInt(mPhone.getContext().getContentResolver(), |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 1878 | Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId, networkType); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 1879 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1880 | return success; |
| 1881 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 1882 | |
| 1883 | /** |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 1884 | * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning |
| 1885 | * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for |
| 1886 | * tethering. |
| 1887 | * |
| 1888 | * @return 0: Not required. 1: required. 2: Not set. |
| 1889 | * @hide |
| 1890 | */ |
| 1891 | @Override |
| 1892 | public int getTetherApnRequired() { |
| 1893 | enforceModifyPermissionOrCarrierPrivilege(); |
| 1894 | int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(), |
| 1895 | Settings.Global.TETHER_DUN_REQUIRED, 2); |
| 1896 | // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and |
| 1897 | // config_tether_apndata. |
| 1898 | if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) { |
| 1899 | dunRequired = 1; |
| 1900 | } |
| 1901 | return dunRequired; |
| 1902 | } |
| 1903 | |
| 1904 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 1905 | * Set mobile data enabled |
| 1906 | * Used by the user through settings etc to turn on/off mobile data |
| 1907 | * |
| 1908 | * @param enable {@code true} turn turn data on, else {@code false} |
| 1909 | */ |
| 1910 | @Override |
| 1911 | public void setDataEnabled(boolean enable) { |
| 1912 | enforceModifyPermission(); |
| 1913 | mPhone.setDataEnabled(enable); |
| 1914 | } |
| 1915 | |
| 1916 | /** |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 1917 | * Get whether mobile data is enabled. |
| 1918 | * |
| 1919 | * Note that this used to be available from ConnectivityService, gated by |
| 1920 | * ACCESS_NETWORK_STATE permission, so this will accept either that or |
| 1921 | * our MODIFY_PHONE_STATE. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 1922 | * |
| 1923 | * @return {@code true} if data is enabled else {@code false} |
| 1924 | */ |
| 1925 | @Override |
| 1926 | public boolean getDataEnabled() { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 1927 | try { |
| 1928 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 1929 | null); |
| 1930 | } catch (Exception e) { |
| 1931 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, |
| 1932 | null); |
| 1933 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 1934 | return mPhone.getDataEnabled(); |
| 1935 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 1936 | |
| 1937 | @Override |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 1938 | public int getCarrierPrivilegeStatus() { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 1939 | UiccCard card = UiccController.getInstance().getUiccCard(); |
| 1940 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 1941 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 1942 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 1943 | } |
| 1944 | return card.getCarrierPrivilegeStatusForCurrentTransaction( |
Shishir Agrawal | f1ac4c9 | 2014-07-14 13:54:28 -0700 | [diff] [blame] | 1945 | mPhone.getContext().getPackageManager()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 1946 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 1947 | |
| 1948 | @Override |
Shishir Agrawal | 6d5a285 | 2014-07-11 16:32:57 -0700 | [diff] [blame] | 1949 | public int checkCarrierPrivilegesForPackage(String pkgname) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 1950 | UiccCard card = UiccController.getInstance().getUiccCard(); |
| 1951 | if (card == null) { |
| 1952 | loge("checkCarrierPrivilegesForPackage: No UICC"); |
| 1953 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 1954 | } |
| 1955 | return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgname); |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 1956 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 1957 | |
| 1958 | @Override |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 1959 | public List<String> getCarrierPackageNamesForIntent(Intent intent) { |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 1960 | UiccCard card = UiccController.getInstance().getUiccCard(); |
| 1961 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 1962 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 1963 | return null ; |
| 1964 | } |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 1965 | return card.getCarrierPackageNamesForIntent( |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 1966 | mPhone.getContext().getPackageManager(), intent); |
| 1967 | } |
| 1968 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1969 | private String getIccId(int subId) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 1970 | UiccCard card = getPhone(subId).getUiccCard(); |
| 1971 | if (card == null) { |
| 1972 | loge("getIccId: No UICC"); |
| 1973 | return null; |
| 1974 | } |
| 1975 | String iccId = card.getIccId(); |
| 1976 | if (TextUtils.isEmpty(iccId)) { |
| 1977 | loge("getIccId: ICC ID is null or empty."); |
| 1978 | return null; |
| 1979 | } |
| 1980 | return iccId; |
| 1981 | } |
| 1982 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 1983 | @Override |
Shishir Agrawal | 495d7e1 | 2014-12-01 11:50:28 -0800 | [diff] [blame] | 1984 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, String number) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 1985 | enforceCarrierPrivilege(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 1986 | |
| 1987 | String iccId = getIccId(subId); |
Shishir Agrawal | 495d7e1 | 2014-12-01 11:50:28 -0800 | [diff] [blame] | 1988 | if (TextUtils.isEmpty(iccId)) { |
| 1989 | return false; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 1990 | } |
Shishir Agrawal | 495d7e1 | 2014-12-01 11:50:28 -0800 | [diff] [blame] | 1991 | |
| 1992 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 1993 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 1994 | if (alphaTag == null) { |
| 1995 | editor.remove(alphaTagPrefKey); |
| 1996 | } else { |
| 1997 | editor.putString(alphaTagPrefKey, alphaTag); |
| 1998 | } |
| 1999 | |
| 2000 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 2001 | if (number == null) { |
| 2002 | editor.remove(numberPrefKey); |
| 2003 | } else { |
| 2004 | editor.putString(numberPrefKey, number); |
| 2005 | } |
| 2006 | editor.commit(); |
| 2007 | return true; |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 2008 | } |
| 2009 | |
| 2010 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2011 | public String getLine1NumberForDisplay(int subId) { |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 2012 | enforceReadPermission(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 2013 | |
| 2014 | String iccId = getIccId(subId); |
| 2015 | if (iccId != null) { |
| 2016 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 2017 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 2018 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 2019 | return null; |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2023 | public String getLine1AlphaTagForDisplay(int subId) { |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 2024 | enforceReadPermission(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 2025 | |
| 2026 | String iccId = getIccId(subId); |
| 2027 | if (iccId != null) { |
| 2028 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 2029 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 2030 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 2031 | return null; |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 2032 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 2033 | |
| 2034 | @Override |
Shishir Agrawal | a3dfd75 | 2014-09-04 13:25:42 -0700 | [diff] [blame] | 2035 | public boolean setOperatorBrandOverride(String brand) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 2036 | enforceCarrierPrivilege(); |
Shishir Agrawal | a3dfd75 | 2014-09-04 13:25:42 -0700 | [diff] [blame] | 2037 | return mPhone.setOperatorBrandOverride(brand); |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 2038 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 2039 | |
| 2040 | @Override |
| 2041 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 2042 | enforceModifyPermission(); |
| 2043 | |
| 2044 | int returnValue = 0; |
| 2045 | try { |
| 2046 | AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
| 2047 | if(result.exception == null) { |
| 2048 | if (result.result != null) { |
| 2049 | byte[] responseData = (byte[])(result.result); |
| 2050 | if(responseData.length > oemResp.length) { |
| 2051 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 2052 | responseData.length + "bytes. Buffer Size is " + |
| 2053 | oemResp.length + "bytes."); |
| 2054 | } |
| 2055 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 2056 | returnValue = responseData.length; |
| 2057 | } |
| 2058 | } else { |
| 2059 | CommandException ex = (CommandException) result.exception; |
| 2060 | returnValue = ex.getCommandError().ordinal(); |
| 2061 | if(returnValue > 0) returnValue *= -1; |
| 2062 | } |
| 2063 | } catch (RuntimeException e) { |
| 2064 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 2065 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 2066 | if(returnValue > 0) returnValue *= -1; |
| 2067 | } |
| 2068 | |
| 2069 | return returnValue; |
| 2070 | } |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 2071 | |
| 2072 | @Override |
| 2073 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 2074 | try { |
| 2075 | ProxyController.getInstance().setRadioCapability(rafs); |
| 2076 | } catch (RuntimeException e) { |
| 2077 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 2078 | } |
| 2079 | } |
| 2080 | |
| 2081 | @Override |
| 2082 | public int getRadioAccessFamily(int phoneId) { |
| 2083 | return ProxyController.getInstance().getRadioAccessFamily(phoneId); |
| 2084 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 2085 | |
| 2086 | @Override |
| 2087 | public void enableVideoCalling(boolean enable) { |
| 2088 | enforceModifyPermission(); |
| 2089 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 2090 | editor.putBoolean(PREF_ENABLE_VIDEO_CALLING, enable); |
| 2091 | editor.commit(); |
| 2092 | } |
| 2093 | |
| 2094 | @Override |
| 2095 | public boolean isVideoCallingEnabled() { |
| 2096 | enforceReadPermission(); |
Andrew Lee | 77527ac | 2014-10-21 16:57:39 -0700 | [diff] [blame] | 2097 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 2098 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 2099 | // In the long run, we may instead need to check if there exists a connection service |
| 2100 | // which can support video calling. |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 2101 | return ImsManager.isVtEnabledByPlatform(mPhone.getContext()) |
| 2102 | && ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext()) |
| 2103 | && mTelephonySharedPreferences.getBoolean(PREF_ENABLE_VIDEO_CALLING, true); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 2104 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2105 | } |