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