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