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