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