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