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