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