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