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