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