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