blob: e7131fef86282edd589fd6276a5014f8f19d4b6e [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
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
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Ta-wei Yen87c49842016-05-13 21:19:52 -070021import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
22
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080025import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070026import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.content.Context;
28import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070029import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070030import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070031import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080032import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070033import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070034import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.net.Uri;
36import android.os.AsyncResult;
37import android.os.Binder;
38import android.os.Bundle;
39import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Looper;
42import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070044import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080045import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070046import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070048import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070049import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070051import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070052import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070053import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080054import android.provider.Settings;
Santos Cordon7a1885b2015-02-03 11:15:19 -080055import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080056import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070057import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070058import android.telephony.CarrierConfigManager;
Michele Berionne0963c862018-11-27 18:57:59 -080059import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070061import android.telephony.CellInfoGsm;
62import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070063import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070064import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070065import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070066import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080067import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070068import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080069import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070070import android.telephony.NetworkScanRequest;
Hall Liud892bec2018-11-30 14:51:45 -080071import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070072import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070073import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080075import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070076import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080077import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080078import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070079import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070080import android.telephony.TelephonyManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080081import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000082import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070083import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070084import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070085import android.telephony.cdma.CdmaCellLocation;
Jack Yu311536f2018-11-26 11:20:48 -080086import android.telephony.data.ApnSetting;
calvinpaneed9ae82018-11-01 19:43:06 +080087import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070088import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080089import android.telephony.ims.ProvisioningManager;
Brad Ebinger4c460712018-10-01 10:40:55 -070090import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080091import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070092import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080093import android.telephony.ims.aidl.IImsMmTelFeature;
94import android.telephony.ims.aidl.IImsRcsFeature;
95import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -070096import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080097import android.telephony.ims.feature.MmTelFeature;
98import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080099import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700100import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800101import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700102import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800103import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800104import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800105
Brad Ebinger4c460712018-10-01 10:40:55 -0700106import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700107import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800108import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700109import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700110import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700111import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800112import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700113import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700114import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115import com.android.internal.telephony.DefaultPhoneNotifier;
Hall Liud892bec2018-11-30 14:51:45 -0800116import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800118import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700119import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100120import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700121import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700122import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700124import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800125import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700126import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700127import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700128import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700129import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700130import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700131import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800132import com.android.internal.telephony.SmsApplication;
133import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800134import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800135import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700136import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700137import com.android.internal.telephony.uicc.IccIoResult;
138import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800139import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700140import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800141import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700142import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800143import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000144import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700145import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800146import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700147import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800148import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700149import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700150import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800151
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700152import java.io.FileDescriptor;
153import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800154import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800156import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800157import java.util.Collection;
sqian03bca152018-12-05 18:48:28 -0800158import java.util.HashMap;
Jake Hambye994d462014-02-03 13:10:13 -0800159import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100160import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800161import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162
163/**
164 * Implementation of the ITelephony interface.
165 */
Santos Cordon117fee72014-05-16 17:56:12 -0700166public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700167 private static final String LOG_TAG = "PhoneInterfaceManager";
168 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
169 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800170 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171
172 // Message codes used with mMainThreadHandler
173 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700174 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
175 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700176 private static final int CMD_OPEN_CHANNEL = 9;
177 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
178 private static final int CMD_CLOSE_CHANNEL = 11;
179 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800180 private static final int CMD_NV_READ_ITEM = 13;
181 private static final int EVENT_NV_READ_ITEM_DONE = 14;
182 private static final int CMD_NV_WRITE_ITEM = 15;
183 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
184 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
185 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700186 private static final int CMD_RESET_MODEM_CONFIG = 19;
187 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800188 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
189 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
190 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
191 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800192 private static final int CMD_SEND_ENVELOPE = 25;
193 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000194 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
195 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700196 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
197 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
198 private static final int CMD_EXCHANGE_SIM_IO = 31;
199 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800200 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
201 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700202 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
203 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700204 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
205 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700206 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
207 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
208 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
209 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700210 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
211 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
212 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
213 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700214 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800215 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
216 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000217 private static final int CMD_SWITCH_SLOTS = 50;
218 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700219 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
220 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
221 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
222 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
223 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
224 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
225 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
226 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700227 private static final int CMD_GET_ALL_CELL_INFO = 60;
228 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
229 private static final int CMD_GET_CELL_LOCATION = 62;
230 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700231 private static final int CMD_MODEM_REBOOT = 64;
232 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700233 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
234 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen509b5b72019-01-15 20:22:16 -0800235 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
236 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700237
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800238 // Parameters of select command.
239 private static final int SELECT_COMMAND = 0xA4;
240 private static final int SELECT_P1 = 0x04;
241 private static final int SELECT_P2 = 0;
242 private static final int SELECT_P3 = 0x10;
243
Pengquan Meng85728fb2018-03-12 16:31:21 -0700244 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
245 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
246 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
247
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700248 /** The singleton instance. */
249 private static PhoneInterfaceManager sInstance;
250
Wink Saville3ab207e2014-11-20 13:07:20 -0800251 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800252 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700253 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800254 private AppOpsManager mAppOps;
255 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800256 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800257 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700258 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700259
Derek Tan97ebb422014-09-05 16:55:38 -0700260 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
261 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800262 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800263 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700264
Derek Tan740e1672017-06-27 14:56:27 -0700265 // The AID of ISD-R.
266 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
267
yinxub1bed742017-04-17 11:45:04 -0700268 private NetworkScanRequestTracker mNetworkScanRequestTracker;
269
David Kelly5e06a7f2018-03-12 14:10:59 +0000270 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
271 private static final int MANUFACTURER_CODE_LENGTH = 8;
272
Derek Tan89e89d42014-07-08 17:00:10 -0700273 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700274 * A request object to use for transmitting data to an ICC.
275 */
276 private static final class IccAPDUArgument {
277 public int channel, cla, command, p1, p2, p3;
278 public String data;
279
280 public IccAPDUArgument(int channel, int cla, int command,
281 int p1, int p2, int p3, String data) {
282 this.channel = channel;
283 this.cla = cla;
284 this.command = command;
285 this.p1 = p1;
286 this.p2 = p2;
287 this.p3 = p3;
288 this.data = data;
289 }
290 }
291
292 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700293 * A request object to use for transmitting data to an ICC.
294 */
295 private static final class ManualNetworkSelectionArgument {
296 public OperatorInfo operatorInfo;
297 public boolean persistSelection;
298
299 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
300 this.operatorInfo = operatorInfo;
301 this.persistSelection = persistSelection;
302 }
303 }
304
305 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700306 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
307 * request after sending. The main thread will notify the request when it is complete.
308 */
309 private static final class MainThreadRequest {
310 /** The argument to use for the request */
311 public Object argument;
312 /** The result of the request that is run on the main thread */
313 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800314 // The subscriber id that this request applies to. Defaults to
315 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
316 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700317
Nathan Harold92bed182018-10-12 18:16:49 -0700318 // In cases where subId is unavailable, the caller needs to specify the phone.
319 public Phone phone;
320
vagdevie435a3e2018-08-15 16:01:53 -0700321 public WorkSource workSource;
322
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700323 public MainThreadRequest(Object argument) {
324 this.argument = argument;
325 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800326
Nathan Harold92bed182018-10-12 18:16:49 -0700327 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
328 this.argument = argument;
329 if (phone != null) {
330 this.phone = phone;
331 }
332 this.workSource = workSource;
333 }
334
vagdevie435a3e2018-08-15 16:01:53 -0700335 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800336 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800337 if (subId != null) {
338 this.subId = subId;
339 }
vagdevie435a3e2018-08-15 16:01:53 -0700340 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800341 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342 }
343
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800344 private static final class IncomingThirdPartyCallArgs {
345 public final ComponentName component;
346 public final String callId;
347 public final String callerDisplayName;
348
349 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
350 String callerDisplayName) {
351 this.component = component;
352 this.callId = callId;
353 this.callerDisplayName = callerDisplayName;
354 }
355 }
356
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357 /**
358 * A handler that processes messages on the main thread in the phone process. Since many
359 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
360 * inbound binder threads to the main thread in the phone process. The Binder thread
361 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
362 * on, which will be notified when the operation completes and will contain the result of the
363 * request.
364 *
365 * <p>If a MainThreadRequest object is provided in the msg.obj field,
366 * note that request.result must be set to something non-null for the calling thread to
367 * unblock.
368 */
369 private final class MainThreadHandler extends Handler {
370 @Override
371 public void handleMessage(Message msg) {
372 MainThreadRequest request;
373 Message onCompleted;
374 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800375 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700376 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800377 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700378
379 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700380 case CMD_HANDLE_USSD_REQUEST: {
381 request = (MainThreadRequest) msg.obj;
382 final Phone phone = getPhoneFromRequest(request);
383 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
384 String ussdRequest = ussdObject.first;
385 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700386
Pengquan Meng0c05b502018-09-06 09:59:22 -0700387 if (!isUssdApiAllowed(request.subId)) {
388 // Carrier does not support use of this API, return failure.
389 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
390 UssdResponse response = new UssdResponse(ussdRequest, null);
391 Bundle returnData = new Bundle();
392 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
393 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700394
Pengquan Meng0c05b502018-09-06 09:59:22 -0700395 request.result = true;
396 notifyRequester(request);
397 return;
398 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700399
Pengquan Meng0c05b502018-09-06 09:59:22 -0700400 try {
401 request.result = phone != null
402 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
403 } catch (CallStateException cse) {
404 request.result = false;
405 }
406 // Wake up the requesting thread
407 notifyRequester(request);
408 break;
pkanwar32d516d2016-10-14 19:37:38 -0700409 }
410
Yorke Lee716f67e2015-06-17 15:39:16 -0700411 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700412 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700413 final Phone phone = getPhoneFromRequest(request);
414 request.result = phone != null ?
415 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
416 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700418 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700419 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700420 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700421
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700422 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700423 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700424 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800425 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700426 if (uiccCard == null) {
427 loge("iccTransmitApduLogicalChannel: No UICC");
428 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700429 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700430 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700431 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
432 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700433 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700434 iccArgument.channel, iccArgument.cla, iccArgument.command,
435 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700436 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700437 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700438 break;
439
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700440 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700441 ar = (AsyncResult) msg.obj;
442 request = (MainThreadRequest) ar.userObj;
443 if (ar.exception == null && ar.result != null) {
444 request.result = ar.result;
445 } else {
446 request.result = new IccIoResult(0x6F, 0, (byte[])null);
447 if (ar.result == null) {
448 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800449 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700450 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800451 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700452 } else {
453 loge("iccTransmitApduLogicalChannel: Unknown exception");
454 }
455 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700456 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700457 break;
458
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700459 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
460 request = (MainThreadRequest) msg.obj;
461 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800462 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700463 if (uiccCard == null) {
464 loge("iccTransmitApduBasicChannel: No UICC");
465 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700466 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700467 } else {
468 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
469 request);
470 uiccCard.iccTransmitApduBasicChannel(
471 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
472 iccArgument.p3, iccArgument.data, onCompleted);
473 }
474 break;
475
476 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
477 ar = (AsyncResult) msg.obj;
478 request = (MainThreadRequest) ar.userObj;
479 if (ar.exception == null && ar.result != null) {
480 request.result = ar.result;
481 } else {
482 request.result = new IccIoResult(0x6F, 0, (byte[])null);
483 if (ar.result == null) {
484 loge("iccTransmitApduBasicChannel: Empty response");
485 } else if (ar.exception instanceof CommandException) {
486 loge("iccTransmitApduBasicChannel: CommandException: " +
487 ar.exception);
488 } else {
489 loge("iccTransmitApduBasicChannel: Unknown exception");
490 }
491 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700492 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700493 break;
494
495 case CMD_EXCHANGE_SIM_IO:
496 request = (MainThreadRequest) msg.obj;
497 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800498 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 if (uiccCard == null) {
500 loge("iccExchangeSimIO: No UICC");
501 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700502 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700503 } else {
504 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
505 request);
506 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
507 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
508 iccArgument.data, onCompleted);
509 }
510 break;
511
512 case EVENT_EXCHANGE_SIM_IO_DONE:
513 ar = (AsyncResult) msg.obj;
514 request = (MainThreadRequest) ar.userObj;
515 if (ar.exception == null && ar.result != null) {
516 request.result = ar.result;
517 } else {
518 request.result = new IccIoResult(0x6f, 0, (byte[])null);
519 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700520 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700521 break;
522
Derek Tan4d5e5c12014-02-04 11:54:58 -0800523 case CMD_SEND_ENVELOPE:
524 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800525 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700526 if (uiccCard == null) {
527 loge("sendEnvelopeWithStatus: No UICC");
528 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700529 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700530 } else {
531 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
532 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
533 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800534 break;
535
536 case EVENT_SEND_ENVELOPE_DONE:
537 ar = (AsyncResult) msg.obj;
538 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700539 if (ar.exception == null && ar.result != null) {
540 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800541 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700542 request.result = new IccIoResult(0x6F, 0, (byte[])null);
543 if (ar.result == null) {
544 loge("sendEnvelopeWithStatus: Empty response");
545 } else if (ar.exception instanceof CommandException) {
546 loge("sendEnvelopeWithStatus: CommandException: " +
547 ar.exception);
548 } else {
549 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
550 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800551 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700552 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800553 break;
554
Shishir Agrawal566b7612013-10-28 14:41:00 -0700555 case CMD_OPEN_CHANNEL:
556 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800557 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800558 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700559 if (uiccCard == null) {
560 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800561 request.result = new IccOpenLogicalChannelResponse(-1,
562 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700563 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700564 } else {
565 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800566 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
567 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700568 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 break;
570
571 case EVENT_OPEN_CHANNEL_DONE:
572 ar = (AsyncResult) msg.obj;
573 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700574 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700576 int[] result = (int[]) ar.result;
577 int channelId = result[0];
578 byte[] selectResponse = null;
579 if (result.length > 1) {
580 selectResponse = new byte[result.length - 1];
581 for (int i = 1; i < result.length; ++i) {
582 selectResponse[i - 1] = (byte) result[i];
583 }
584 }
585 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700586 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700587 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 if (ar.result == null) {
589 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700590 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700591 if (ar.exception != null) {
592 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
593 }
594
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700595 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700596 if (ar.exception instanceof CommandException) {
597 CommandException.Error error =
598 ((CommandException) (ar.exception)).getCommandError();
599 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700600 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700601 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700602 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700603 }
604 }
605 openChannelResp = new IccOpenLogicalChannelResponse(
606 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700608 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700609 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 break;
611
612 case CMD_CLOSE_CHANNEL:
613 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800614 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700615 if (uiccCard == null) {
616 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900617 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700618 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700619 } else {
620 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
621 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
622 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 break;
624
625 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800626 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
627 break;
628
629 case CMD_NV_READ_ITEM:
630 request = (MainThreadRequest) msg.obj;
631 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800632 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
633 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800634 break;
635
636 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 ar = (AsyncResult) msg.obj;
638 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800639 if (ar.exception == null && ar.result != null) {
640 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700641 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800642 request.result = "";
643 if (ar.result == null) {
644 loge("nvReadItem: Empty response");
645 } else if (ar.exception instanceof CommandException) {
646 loge("nvReadItem: CommandException: " +
647 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800649 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 }
651 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700652 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 break;
654
Jake Hambye994d462014-02-03 13:10:13 -0800655 case CMD_NV_WRITE_ITEM:
656 request = (MainThreadRequest) msg.obj;
657 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
658 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800659 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700660 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800661 break;
662
663 case EVENT_NV_WRITE_ITEM_DONE:
664 handleNullReturnEvent(msg, "nvWriteItem");
665 break;
666
667 case CMD_NV_WRITE_CDMA_PRL:
668 request = (MainThreadRequest) msg.obj;
669 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800670 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800671 break;
672
673 case EVENT_NV_WRITE_CDMA_PRL_DONE:
674 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
675 break;
676
chen xu1cc0abe2018-10-26 17:39:23 -0700677 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800678 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700679 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800680 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800681 break;
682
chen xu1cc0abe2018-10-26 17:39:23 -0700683 case EVENT_RESET_MODEM_CONFIG_DONE:
684 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800685 break;
686
Jake Hamby7c27be32014-03-03 13:25:59 -0800687 case CMD_GET_PREFERRED_NETWORK_TYPE:
688 request = (MainThreadRequest) msg.obj;
689 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700690 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800691 break;
692
693 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
694 ar = (AsyncResult) msg.obj;
695 request = (MainThreadRequest) ar.userObj;
696 if (ar.exception == null && ar.result != null) {
697 request.result = ar.result; // Integer
698 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800699 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800700 if (ar.result == null) {
701 loge("getPreferredNetworkType: Empty response");
702 } else if (ar.exception instanceof CommandException) {
703 loge("getPreferredNetworkType: CommandException: " +
704 ar.exception);
705 } else {
706 loge("getPreferredNetworkType: Unknown exception");
707 }
708 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700709 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800710 break;
711
712 case CMD_SET_PREFERRED_NETWORK_TYPE:
713 request = (MainThreadRequest) msg.obj;
714 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
715 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700716 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800717 break;
718
719 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
720 handleNullReturnEvent(msg, "setPreferredNetworkType");
721 break;
722
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000723 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
724 request = (MainThreadRequest)msg.obj;
725 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800726 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000727 break;
728
729 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
730 ar = (AsyncResult)msg.obj;
731 request = (MainThreadRequest)ar.userObj;
732 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700733 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000734 break;
735
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800736 case CMD_SET_VOICEMAIL_NUMBER:
737 request = (MainThreadRequest) msg.obj;
738 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
739 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800740 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
741 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800742 break;
743
744 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
745 handleNullReturnEvent(msg, "setVoicemailNumber");
746 break;
747
Stuart Scott54788802015-03-30 13:18:01 -0700748 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
749 request = (MainThreadRequest) msg.obj;
750 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
751 request);
752 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
753 break;
754
755 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
756 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
757 break;
758
Shishir Agrawal302c8692015-06-19 13:49:39 -0700759 case CMD_PERFORM_NETWORK_SCAN:
760 request = (MainThreadRequest) msg.obj;
761 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
762 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
763 break;
764
765 case EVENT_PERFORM_NETWORK_SCAN_DONE:
766 ar = (AsyncResult) msg.obj;
767 request = (MainThreadRequest) ar.userObj;
768 CellNetworkScanResult cellScanResult;
769 if (ar.exception == null && ar.result != null) {
770 cellScanResult = new CellNetworkScanResult(
771 CellNetworkScanResult.STATUS_SUCCESS,
772 (List<OperatorInfo>) ar.result);
773 } else {
774 if (ar.result == null) {
775 loge("getCellNetworkScanResults: Empty response");
776 }
777 if (ar.exception != null) {
778 loge("getCellNetworkScanResults: Exception: " + ar.exception);
779 }
780 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
781 if (ar.exception instanceof CommandException) {
782 CommandException.Error error =
783 ((CommandException) (ar.exception)).getCommandError();
784 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
785 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
786 } else if (error == CommandException.Error.GENERIC_FAILURE) {
787 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
788 }
789 }
790 cellScanResult = new CellNetworkScanResult(errorCode, null);
791 }
792 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700793 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700794 break;
795
796 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
797 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700798 ManualNetworkSelectionArgument selArg =
799 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700800 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
801 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700802 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
803 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700804 break;
805
806 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700807 ar = (AsyncResult) msg.obj;
808 request = (MainThreadRequest) ar.userObj;
809 if (ar.exception == null) {
810 request.result = true;
811 } else {
812 request.result = false;
813 loge("setNetworkSelectionModeManual " + ar.exception);
814 }
815 notifyRequester(request);
816 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700817 break;
818
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700819 case CMD_GET_MODEM_ACTIVITY_INFO:
820 request = (MainThreadRequest) msg.obj;
821 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800822 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700823 break;
824
825 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
826 ar = (AsyncResult) msg.obj;
827 request = (MainThreadRequest) ar.userObj;
828 if (ar.exception == null && ar.result != null) {
829 request.result = ar.result;
830 } else {
831 if (ar.result == null) {
832 loge("queryModemActivityInfo: Empty response");
833 } else if (ar.exception instanceof CommandException) {
834 loge("queryModemActivityInfo: CommandException: " +
835 ar.exception);
836 } else {
837 loge("queryModemActivityInfo: Unknown exception");
838 }
839 }
Amit Mahajand4766222016-01-28 15:28:28 -0800840 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
841 if (request.result == null) {
842 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
843 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700844 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700845 break;
846
Meng Wang1a7c35a2016-05-05 20:56:15 -0700847 case CMD_SET_ALLOWED_CARRIERS:
848 request = (MainThreadRequest) msg.obj;
Michele Berionne0963c862018-11-27 18:57:59 -0800849 CarrierRestrictionRules argument =
850 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700851 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne0963c862018-11-27 18:57:59 -0800852 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700853 break;
854
855 case EVENT_SET_ALLOWED_CARRIERS_DONE:
856 ar = (AsyncResult) msg.obj;
857 request = (MainThreadRequest) ar.userObj;
858 if (ar.exception == null && ar.result != null) {
859 request.result = ar.result;
860 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800861 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
862 if (ar.exception instanceof CommandException) {
863 loge("setAllowedCarriers: CommandException: " + ar.exception);
864 CommandException.Error error =
865 ((CommandException) (ar.exception)).getCommandError();
866 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
867 request.result =
868 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
869 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700870 } else {
871 loge("setAllowedCarriers: Unknown exception");
872 }
873 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700874 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700875 break;
876
877 case CMD_GET_ALLOWED_CARRIERS:
878 request = (MainThreadRequest) msg.obj;
879 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800880 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700881 break;
882
883 case EVENT_GET_ALLOWED_CARRIERS_DONE:
884 ar = (AsyncResult) msg.obj;
885 request = (MainThreadRequest) ar.userObj;
886 if (ar.exception == null && ar.result != null) {
887 request.result = ar.result;
888 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800889 request.result = new IllegalStateException(
890 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700891 if (ar.result == null) {
892 loge("getAllowedCarriers: Empty response");
893 } else if (ar.exception instanceof CommandException) {
894 loge("getAllowedCarriers: CommandException: " +
895 ar.exception);
896 } else {
897 loge("getAllowedCarriers: Unknown exception");
898 }
899 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700900 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700901 break;
902
Nathan Haroldb3014052017-01-25 15:57:32 -0800903 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
904 ar = (AsyncResult) msg.obj;
905 request = (MainThreadRequest) ar.userObj;
906 if (ar.exception == null && ar.result != null) {
907 request.result = ar.result;
908 } else {
909 request.result = new IllegalArgumentException(
910 "Failed to retrieve Forbidden Plmns");
911 if (ar.result == null) {
912 loge("getForbiddenPlmns: Empty response");
913 } else {
914 loge("getForbiddenPlmns: Unknown exception");
915 }
916 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700917 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800918 break;
919
920 case CMD_GET_FORBIDDEN_PLMNS:
921 request = (MainThreadRequest) msg.obj;
922 uiccCard = getUiccCardFromRequest(request);
923 if (uiccCard == null) {
924 loge("getForbiddenPlmns() UiccCard is null");
925 request.result = new IllegalArgumentException(
926 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700927 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800928 break;
929 }
930 Integer appType = (Integer) request.argument;
931 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
932 if (uiccApp == null) {
933 loge("getForbiddenPlmns() no app with specified type -- "
934 + appType);
935 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700936 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800937 break;
938 } else {
939 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
940 + " specified type -- " + appType);
941 }
942 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
943 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
944 onCompleted);
945 break;
946
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000947 case CMD_SWITCH_SLOTS:
948 request = (MainThreadRequest) msg.obj;
949 int[] physicalSlots = (int[]) request.argument;
950 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
951 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
952 break;
953
954 case EVENT_SWITCH_SLOTS_DONE:
955 ar = (AsyncResult) msg.obj;
956 request = (MainThreadRequest) ar.userObj;
957 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700958 notifyRequester(request);
959 break;
960 case CMD_GET_NETWORK_SELECTION_MODE:
961 request = (MainThreadRequest) msg.obj;
962 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
963 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
964 break;
965
966 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
967 ar = (AsyncResult) msg.obj;
968 request = (MainThreadRequest) ar.userObj;
969 if (ar.exception != null) {
970 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
971 } else {
972 int mode = ((int[]) ar.result)[0];
973 if (mode == 0) {
974 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
975 } else {
976 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
977 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000978 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700979 notifyRequester(request);
980 break;
981 case CMD_GET_CDMA_ROAMING_MODE:
982 request = (MainThreadRequest) msg.obj;
983 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
984 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
985 break;
986 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
987 ar = (AsyncResult) msg.obj;
988 request = (MainThreadRequest) ar.userObj;
989 if (ar.exception != null) {
990 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
991 } else {
992 request.result = ((int[]) ar.result)[0];
993 }
994 notifyRequester(request);
995 break;
996 case CMD_SET_CDMA_ROAMING_MODE:
997 request = (MainThreadRequest) msg.obj;
998 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
999 int mode = (int) request.argument;
1000 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1001 break;
1002 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1003 ar = (AsyncResult) msg.obj;
1004 request = (MainThreadRequest) ar.userObj;
1005 request.result = ar.exception == null;
1006 notifyRequester(request);
1007 break;
1008 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1009 request = (MainThreadRequest) msg.obj;
1010 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1011 int subscriptionMode = (int) request.argument;
1012 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1013 break;
1014 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1015 ar = (AsyncResult) msg.obj;
1016 request = (MainThreadRequest) ar.userObj;
1017 request.result = ar.exception == null;
1018 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001019 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001020 case CMD_GET_ALL_CELL_INFO:
1021 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001022 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001023 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001024 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001025 case EVENT_GET_ALL_CELL_INFO_DONE:
1026 ar = (AsyncResult) msg.obj;
1027 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001028 // If a timeout occurs, the response will be null
1029 request.result = (ar.exception == null && ar.result != null)
1030 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001031 synchronized (request) {
1032 request.notifyAll();
1033 }
1034 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001035 case CMD_REQUEST_CELL_INFO_UPDATE:
1036 request = (MainThreadRequest) msg.obj;
1037 request.phone.requestCellInfoUpdate(request.workSource,
1038 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1039 break;
1040 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
1043 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1044 try {
1045 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001046 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001047 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1048 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001049 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001050 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001051 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001052 } else {
1053 // use the result as returned
1054 cb.onCellInfo((List<CellInfo>) ar.result);
1055 }
1056 } catch (RemoteException re) {
1057 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1058 }
1059 break;
1060 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001061 request = (MainThreadRequest) msg.obj;
1062 WorkSource ws = (WorkSource) request.argument;
1063 Phone phone = getPhoneFromRequest(request);
1064 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1065 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001066 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001067 ar = (AsyncResult) msg.obj;
1068 request = (MainThreadRequest) ar.userObj;
1069 if (ar.exception == null) {
1070 request.result = ar.result;
1071 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001072 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001073 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1074 ? new CdmaCellLocation() : new GsmCellLocation();
1075 }
1076
1077 synchronized (request) {
1078 request.notifyAll();
1079 }
1080 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001081 case CMD_MODEM_REBOOT:
1082 request = (MainThreadRequest) msg.obj;
1083 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001084 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001085 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001086 case EVENT_CMD_MODEM_REBOOT_DONE:
1087 handleNullReturnEvent(msg, "rebootModem");
1088 break;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001089 case CMD_REQUEST_ENABLE_MODEM:
1090 request = (MainThreadRequest) msg.obj;
1091 boolean enable = (boolean) request.argument;
1092 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
1093 PhoneConfigurationManager.getInstance()
1094 .enablePhone(request.phone, enable, onCompleted);
1095 break;
1096 case EVENT_ENABLE_MODEM_DONE:
1097 ar = (AsyncResult) msg.obj;
1098 request = (MainThreadRequest) ar.userObj;
1099 request.result = (ar.exception == null);
1100 notifyRequester(request);
1101 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001102 default:
1103 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1104 break;
1105 }
1106 }
Jake Hambye994d462014-02-03 13:10:13 -08001107
Pengquan Meng0c05b502018-09-06 09:59:22 -07001108 private void notifyRequester(MainThreadRequest request) {
1109 synchronized (request) {
1110 request.notifyAll();
1111 }
1112 }
1113
Jake Hambye994d462014-02-03 13:10:13 -08001114 private void handleNullReturnEvent(Message msg, String command) {
1115 AsyncResult ar = (AsyncResult) msg.obj;
1116 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1117 if (ar.exception == null) {
1118 request.result = true;
1119 } else {
1120 request.result = false;
1121 if (ar.exception instanceof CommandException) {
1122 loge(command + ": CommandException: " + ar.exception);
1123 } else {
1124 loge(command + ": Unknown exception");
1125 }
1126 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001127 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001128 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001129 }
1130
1131 /**
1132 * Posts the specified command to be executed on the main thread,
1133 * waits for the request to complete, and returns the result.
1134 * @see #sendRequestAsync
1135 */
1136 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001137 return sendRequest(
1138 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001139 }
1140
1141 /**
1142 * Posts the specified command to be executed on the main thread,
1143 * waits for the request to complete, and returns the result.
1144 * @see #sendRequestAsync
1145 */
1146 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1147 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001148 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001149 }
1150
1151 /**
1152 * Posts the specified command to be executed on the main thread,
1153 * waits for the request to complete, and returns the result.
1154 * @see #sendRequestAsync
1155 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001156 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001157 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001158 }
1159
1160 /**
1161 * Posts the specified command to be executed on the main thread,
1162 * waits for the request to complete, and returns the result.
1163 * @see #sendRequestAsync
1164 */
Nathan Harold92bed182018-10-12 18:16:49 -07001165 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1166 return sendRequest(command, argument, subId, null, workSource);
1167 }
1168
1169 /**
1170 * Posts the specified command to be executed on the main thread,
1171 * waits for the request to complete, and returns the result.
1172 * @see #sendRequestAsync
1173 */
1174 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1175 return sendRequest(
1176 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1177 }
1178
1179 /**
1180 * Posts the specified command to be executed on the main thread,
1181 * waits for the request to complete, and returns the result.
1182 * @see #sendRequestAsync
1183 */
1184 private Object sendRequest(
1185 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001186 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1187 throw new RuntimeException("This method will deadlock if called from the main thread.");
1188 }
1189
Nathan Harold92bed182018-10-12 18:16:49 -07001190 MainThreadRequest request = null;
1191 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1192 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1193 } else if (phone != null) {
1194 request = new MainThreadRequest(argument, phone, workSource);
1195 } else {
1196 request = new MainThreadRequest(argument, subId, workSource);
1197 }
1198
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001199 Message msg = mMainThreadHandler.obtainMessage(command, request);
1200 msg.sendToTarget();
1201
1202 // Wait for the request to complete
1203 synchronized (request) {
1204 while (request.result == null) {
1205 try {
1206 request.wait();
1207 } catch (InterruptedException e) {
1208 // Do nothing, go back and wait until the request is complete
1209 }
1210 }
1211 }
1212 return request.result;
1213 }
1214
1215 /**
1216 * Asynchronous ("fire and forget") version of sendRequest():
1217 * Posts the specified command to be executed on the main thread, and
1218 * returns immediately.
1219 * @see #sendRequest
1220 */
1221 private void sendRequestAsync(int command) {
1222 mMainThreadHandler.sendEmptyMessage(command);
1223 }
1224
1225 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001226 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001227 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001228 */
1229 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001230 sendRequestAsync(command, argument, null, null);
1231 }
1232
1233 /**
1234 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1235 * @see {@link #sendRequest(int,Object)}
1236 */
1237 private void sendRequestAsync(
1238 int command, Object argument, Phone phone, WorkSource workSource) {
1239 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001240 Message msg = mMainThreadHandler.obtainMessage(command, request);
1241 msg.sendToTarget();
1242 }
1243
1244 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001245 * Initialize the singleton PhoneInterfaceManager instance.
1246 * This is only done once, at startup, from PhoneApp.onCreate().
1247 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001248 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001249 synchronized (PhoneInterfaceManager.class) {
1250 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001251 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001252 } else {
1253 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1254 }
1255 return sInstance;
1256 }
1257 }
1258
1259 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001260 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001261 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001262 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001263 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001264 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1265 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001266 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001267 mTelephonySharedPreferences =
1268 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001269 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001270 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001271
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001272 publish();
1273 }
1274
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001275 private Phone getDefaultPhone() {
1276 Phone thePhone = getPhone(getDefaultSubscription());
1277 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1278 }
1279
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001280 private void publish() {
1281 if (DBG) log("publish: " + this);
1282
1283 ServiceManager.addService("phone", this);
1284 }
1285
Stuart Scott584921c2015-01-15 17:10:34 -08001286 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001287 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001288 ? getDefaultPhone() : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001289 }
1290
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001291 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1292 Phone phone = getPhoneFromRequest(request);
1293 return phone == null ? null :
1294 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1295 }
1296
Wink Saville36469e72014-06-11 15:17:00 -07001297 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001298 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001299 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001300 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001301
1302 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001303 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001304 }
1305
Wink Savilleb564aae2014-10-23 10:18:09 -07001306 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001307 if (DBG) log("dial: " + number);
1308 // No permission check needed here: This is just a wrapper around the
1309 // ACTION_DIAL intent, which is available to any app since it puts up
1310 // the UI before it does anything.
1311
Malcolm Chend965c8b2018-02-28 15:00:40 -08001312 final long identity = Binder.clearCallingIdentity();
1313 try {
1314 String url = createTelUrl(number);
1315 if (url == null) {
1316 return;
1317 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001318
Malcolm Chend965c8b2018-02-28 15:00:40 -08001319 // PENDING: should we just silently fail if phone is offhook or ringing?
1320 PhoneConstants.State state = mCM.getState(subId);
1321 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1322 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1323 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1324 mApp.startActivity(intent);
1325 }
1326 } finally {
1327 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001328 }
1329 }
1330
1331 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001332 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001333 }
1334
Wink Savilleb564aae2014-10-23 10:18:09 -07001335 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001336 if (DBG) log("call: " + number);
1337
1338 // This is just a wrapper around the ACTION_CALL intent, but we still
1339 // need to do a permission check since we're calling startActivity()
1340 // from the context of the phone app.
1341 enforceCallPermission();
1342
1343 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1344 != AppOpsManager.MODE_ALLOWED) {
1345 return;
1346 }
1347
Malcolm Chend965c8b2018-02-28 15:00:40 -08001348 final long identity = Binder.clearCallingIdentity();
1349 try {
1350 String url = createTelUrl(number);
1351 if (url == null) {
1352 return;
1353 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001354
Malcolm Chend965c8b2018-02-28 15:00:40 -08001355 boolean isValid = false;
1356 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1357 if (slist != null) {
1358 for (SubscriptionInfo subInfoRecord : slist) {
1359 if (subInfoRecord.getSubscriptionId() == subId) {
1360 isValid = true;
1361 break;
1362 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001363 }
Wink Saville08874612014-08-31 19:19:58 -07001364 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001365 if (!isValid) {
1366 return;
1367 }
Wink Saville08874612014-08-31 19:19:58 -07001368
Malcolm Chend965c8b2018-02-28 15:00:40 -08001369 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1370 intent.putExtra(SUBSCRIPTION_KEY, subId);
1371 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1372 mApp.startActivity(intent);
1373 } finally {
1374 Binder.restoreCallingIdentity(identity);
1375 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001376 }
1377
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001379 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001380 }
1381
Wink Savilleb564aae2014-10-23 10:18:09 -07001382 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001383 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001384 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1385 }
1386
1387 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001388 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001389 }
1390
Wink Savilleb564aae2014-10-23 10:18:09 -07001391 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001392 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001393 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1394 }
1395
1396 /** {@hide} */
1397 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001398 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001399 }
1400
Wink Savilleb564aae2014-10-23 10:18:09 -07001401 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001402 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001403
1404 final long identity = Binder.clearCallingIdentity();
1405 try {
1406 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1407 checkSimPin.start();
1408 return checkSimPin.unlockSim(null, pin);
1409 } finally {
1410 Binder.restoreCallingIdentity(identity);
1411 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001412 }
1413
Wink Saville9de0f752013-10-22 19:04:03 -07001414 /** {@hide} */
1415 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001416 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001417 }
1418
Wink Savilleb564aae2014-10-23 10:18:09 -07001419 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001420 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001421
1422 final long identity = Binder.clearCallingIdentity();
1423 try {
1424 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1425 checkSimPuk.start();
1426 return checkSimPuk.unlockSim(puk, pin);
1427 } finally {
1428 Binder.restoreCallingIdentity(identity);
1429 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001430 }
1431
1432 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001433 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001434 * a synchronous one.
1435 */
1436 private static class UnlockSim extends Thread {
1437
1438 private final IccCard mSimCard;
1439
1440 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001441 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1442 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001443
1444 // For replies from SimCard interface
1445 private Handler mHandler;
1446
1447 // For async handler to identify request type
1448 private static final int SUPPLY_PIN_COMPLETE = 100;
1449
1450 public UnlockSim(IccCard simCard) {
1451 mSimCard = simCard;
1452 }
1453
1454 @Override
1455 public void run() {
1456 Looper.prepare();
1457 synchronized (UnlockSim.this) {
1458 mHandler = new Handler() {
1459 @Override
1460 public void handleMessage(Message msg) {
1461 AsyncResult ar = (AsyncResult) msg.obj;
1462 switch (msg.what) {
1463 case SUPPLY_PIN_COMPLETE:
1464 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1465 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001466 mRetryCount = msg.arg1;
1467 if (ar.exception != null) {
1468 if (ar.exception instanceof CommandException &&
1469 ((CommandException)(ar.exception)).getCommandError()
1470 == CommandException.Error.PASSWORD_INCORRECT) {
1471 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1472 } else {
1473 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1474 }
1475 } else {
1476 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1477 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001478 mDone = true;
1479 UnlockSim.this.notifyAll();
1480 }
1481 break;
1482 }
1483 }
1484 };
1485 UnlockSim.this.notifyAll();
1486 }
1487 Looper.loop();
1488 }
1489
1490 /*
1491 * Use PIN or PUK to unlock SIM card
1492 *
1493 * If PUK is null, unlock SIM card with PIN
1494 *
1495 * If PUK is not null, unlock SIM card with PUK and set PIN code
1496 */
Wink Saville9de0f752013-10-22 19:04:03 -07001497 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001498
1499 while (mHandler == null) {
1500 try {
1501 wait();
1502 } catch (InterruptedException e) {
1503 Thread.currentThread().interrupt();
1504 }
1505 }
1506 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1507
1508 if (puk == null) {
1509 mSimCard.supplyPin(pin, callback);
1510 } else {
1511 mSimCard.supplyPuk(puk, pin, callback);
1512 }
1513
1514 while (!mDone) {
1515 try {
1516 Log.d(LOG_TAG, "wait for done");
1517 wait();
1518 } catch (InterruptedException e) {
1519 // Restore the interrupted status
1520 Thread.currentThread().interrupt();
1521 }
1522 }
1523 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001524 int[] resultArray = new int[2];
1525 resultArray[0] = mResult;
1526 resultArray[1] = mRetryCount;
1527 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001528 }
1529 }
1530
1531 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001532 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001533
1534 }
1535
Wink Savilleb564aae2014-10-23 10:18:09 -07001536 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001537 // No permission check needed here: this call is harmless, and it's
1538 // needed for the ServiceState.requestStateUpdate() call (which is
1539 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001540 final long identity = Binder.clearCallingIdentity();
1541 try {
1542 final Phone phone = getPhone(subId);
1543 if (phone != null) {
1544 phone.updateServiceLocation();
1545 }
1546 } finally {
1547 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001548 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001549 }
1550
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001551 @Override
1552 public boolean isRadioOn(String callingPackage) {
1553 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001554 }
1555
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001556 @Override
1557 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001558 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001559 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001560 return false;
1561 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001562
1563 final long identity = Binder.clearCallingIdentity();
1564 try {
1565 return isRadioOnForSubscriber(subId);
1566 } finally {
1567 Binder.restoreCallingIdentity(identity);
1568 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001569 }
1570
1571 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001572 final long identity = Binder.clearCallingIdentity();
1573 try {
1574 final Phone phone = getPhone(subId);
1575 if (phone != null) {
1576 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1577 } else {
1578 return false;
1579 }
1580 } finally {
1581 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001583 }
1584
1585 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001586 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001587 }
Wink Saville36469e72014-06-11 15:17:00 -07001588
Wink Savilleb564aae2014-10-23 10:18:09 -07001589 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001590 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001591
1592 final long identity = Binder.clearCallingIdentity();
1593 try {
1594 final Phone phone = getPhone(subId);
1595 if (phone != null) {
1596 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1597 }
1598 } finally {
1599 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001600 }
Wink Saville36469e72014-06-11 15:17:00 -07001601 }
1602
1603 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001604 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001605 }
1606
Wink Savilleb564aae2014-10-23 10:18:09 -07001607 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001608 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001609
1610 final long identity = Binder.clearCallingIdentity();
1611 try {
1612 final Phone phone = getPhone(subId);
1613 if (phone == null) {
1614 return false;
1615 }
1616 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1617 toggleRadioOnOffForSubscriber(subId);
1618 }
1619 return true;
1620 } finally {
1621 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001622 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001623 }
Wink Saville36469e72014-06-11 15:17:00 -07001624
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001625 public boolean needMobileRadioShutdown() {
1626 /*
1627 * If any of the Radios are available, it will need to be
1628 * shutdown. So return true if any Radio is available.
1629 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001630 final long identity = Binder.clearCallingIdentity();
1631 try {
1632 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1633 Phone phone = PhoneFactory.getPhone(i);
1634 if (phone != null && phone.isRadioAvailable()) return true;
1635 }
1636 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1637 return false;
1638 } finally {
1639 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001640 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001641 }
1642
Malcolm Chend965c8b2018-02-28 15:00:40 -08001643 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001644 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001645 enforceModifyPermission();
1646
1647 final long identity = Binder.clearCallingIdentity();
1648 try {
1649 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1650 logv("Shutting down Phone " + i);
1651 shutdownRadioUsingPhoneId(i);
1652 }
1653 } finally {
1654 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001655 }
1656 }
1657
1658 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001659 Phone phone = PhoneFactory.getPhone(phoneId);
1660 if (phone != null && phone.isRadioAvailable()) {
1661 phone.shutdownRadio();
1662 }
1663 }
1664
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001665 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001666 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001667
1668 final long identity = Binder.clearCallingIdentity();
1669 try {
1670 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1671 if (defaultPhone != null) {
1672 defaultPhone.setRadioPower(turnOn);
1673 return true;
1674 } else {
1675 loge("There's no default phone.");
1676 return false;
1677 }
1678 } finally {
1679 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001680 }
Wink Saville36469e72014-06-11 15:17:00 -07001681 }
1682
Wink Savilleb564aae2014-10-23 10:18:09 -07001683 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001684 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001685
1686 final long identity = Binder.clearCallingIdentity();
1687 try {
1688 final Phone phone = getPhone(subId);
1689 if (phone != null) {
1690 phone.setRadioPower(turnOn);
1691 return true;
1692 } else {
1693 return false;
1694 }
1695 } finally {
1696 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001697 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001698 }
1699
Wink Saville36469e72014-06-11 15:17:00 -07001700 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001701 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001702 public boolean enableDataConnectivity() {
1703 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001704
1705 final long identity = Binder.clearCallingIdentity();
1706 try {
1707 int subId = mSubscriptionController.getDefaultDataSubId();
1708 final Phone phone = getPhone(subId);
1709 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001710 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001711 return true;
1712 } else {
1713 return false;
1714 }
1715 } finally {
1716 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001717 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001718 }
1719
Wink Saville36469e72014-06-11 15:17:00 -07001720 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001721 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001722 public boolean disableDataConnectivity() {
1723 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001724
1725 final long identity = Binder.clearCallingIdentity();
1726 try {
1727 int subId = mSubscriptionController.getDefaultDataSubId();
1728 final Phone phone = getPhone(subId);
1729 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001730 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001731 return true;
1732 } else {
1733 return false;
1734 }
1735 } finally {
1736 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001737 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001738 }
1739
Sanket Padawe356d7632015-06-22 14:03:32 -07001740 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001741 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001742 final long identity = Binder.clearCallingIdentity();
1743 try {
1744 final Phone phone = getPhone(subId);
1745 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001746 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001747 } else {
1748 return false;
1749 }
1750 } finally {
1751 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001752 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001753 }
1754
1755 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001756 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001757 }
1758
pkanwarae03a6b2016-11-06 20:37:09 -08001759 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001760 enforceCallPermission();
1761
1762 final long identity = Binder.clearCallingIdentity();
1763 try {
1764 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1765 return;
1766 }
1767 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1768 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1769 } finally {
1770 Binder.restoreCallingIdentity(identity);
1771 }
pkanwar32d516d2016-10-14 19:37:38 -07001772 };
1773
Wink Savilleb564aae2014-10-23 10:18:09 -07001774 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001775 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001776
1777 final long identity = Binder.clearCallingIdentity();
1778 try {
1779 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1780 return false;
1781 }
1782 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1783 } finally {
1784 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001785 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001786 }
1787
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001789 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001790 }
1791
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001792 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001793 final long identity = Binder.clearCallingIdentity();
1794 try {
1795 Phone phone = PhoneFactory.getPhone(slotIndex);
1796 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1797 PhoneConstantConversions.convertCallState(phone.getState());
1798 } finally {
1799 Binder.restoreCallingIdentity(identity);
1800 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001801 }
1802
Sanket Padawe356d7632015-06-22 14:03:32 -07001803 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001804 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001805 final long identity = Binder.clearCallingIdentity();
1806 try {
1807 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1808 if (phone != null) {
1809 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1810 } else {
1811 return PhoneConstantConversions.convertDataState(
1812 PhoneConstants.DataState.DISCONNECTED);
1813 }
1814 } finally {
1815 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001816 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001817 }
1818
Sanket Padawe356d7632015-06-22 14:03:32 -07001819 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001820 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001821 final long identity = Binder.clearCallingIdentity();
1822 try {
1823 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1824 if (phone != null) {
1825 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1826 } else {
1827 return TelephonyManager.DATA_ACTIVITY_NONE;
1828 }
1829 } finally {
1830 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001831 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832 }
1833
1834 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001835 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001836 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001837 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001838 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
1839 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001840 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001841 }
1842
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001843 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001844 final long identity = Binder.clearCallingIdentity();
1845 try {
1846 if (DBG_LOC) log("getCellLocation: is active user");
1847 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001848 int subId = mSubscriptionController.getDefaultDataSubId();
1849 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1850 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001851 return data;
1852 } finally {
1853 Binder.restoreCallingIdentity(identity);
1854 }
Svetoslav64fad262015-04-14 14:35:21 -07001855 }
1856
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001857 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001858 public String getNetworkCountryIsoForPhone(int phoneId) {
1859 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1860 // registered cell info, so return a NULL country instead.
1861 final long identity = Binder.clearCallingIdentity();
1862 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001863 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1864 // Get default phone in this case.
1865 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1866 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001867 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001868 // Todo: fix this when we can get the actual cellular network info when the device
1869 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001870 if (TelephonyManager.NETWORK_TYPE_IWLAN
1871 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1872 return "";
1873 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001874 Phone phone = PhoneFactory.getPhone(phoneId);
1875 if (phone != null) {
1876 ServiceStateTracker sst = phone.getServiceStateTracker();
1877 if (sst != null) {
1878 LocaleTracker lt = sst.getLocaleTracker();
1879 if (lt != null) {
1880 return lt.getCurrentCountry();
1881 }
1882 }
1883 }
1884 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001885 } finally {
1886 Binder.restoreCallingIdentity(identity);
1887 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001888 }
1889
1890 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001892 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001893 }
1894
Sanket Padawe356d7632015-06-22 14:03:32 -07001895 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001896 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 mApp.enforceCallingOrSelfPermission(
1898 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001899
1900 final long identity = Binder.clearCallingIdentity();
1901 try {
1902 final Phone phone = getPhone(subId);
1903 if (phone != null) {
1904 phone.enableLocationUpdates();
1905 }
1906 } finally {
1907 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001908 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001909 }
1910
1911 @Override
1912 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001913 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001914 }
1915
Sanket Padawe356d7632015-06-22 14:03:32 -07001916 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001917 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001918 mApp.enforceCallingOrSelfPermission(
1919 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001920
1921 final long identity = Binder.clearCallingIdentity();
1922 try {
1923 final Phone phone = getPhone(subId);
1924 if (phone != null) {
1925 phone.disableLocationUpdates();
1926 }
1927 } finally {
1928 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001929 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001930 }
1931
Nathan Harold31d7ff32018-10-15 20:20:30 -07001932 /**
1933 * Returns the target SDK version number for a given package name.
1934 *
1935 * @return target SDK if the package is found or INT_MAX.
1936 */
1937 private int getTargetSdk(String packageName) {
1938 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001939 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1940 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001941 if (ai != null) return ai.targetSdkVersion;
1942 } catch (PackageManager.NameNotFoundException unexpected) {
1943 }
1944 return Integer.MAX_VALUE;
1945 }
1946
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001947 @Override
1948 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001949 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1950 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001951 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1952 throw new SecurityException(
1953 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1954 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001955
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1957 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1958 return null;
1959 }
Svetoslav64fad262015-04-14 14:35:21 -07001960
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001961 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001962
Nathan Haroldf180aac2018-06-01 18:43:55 -07001963 List<CellInfo> info = getAllCellInfo(callingPackage);
1964 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001965
Nathan Haroldf180aac2018-06-01 18:43:55 -07001966 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1967 for (CellInfo ci : info) {
1968 if (ci instanceof CellInfoGsm) {
1969 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1970 } else if (ci instanceof CellInfoWcdma) {
1971 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1972 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001973 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001974 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001975 }
1976
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001977 private List<CellInfo> getCachedCellInfo() {
1978 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1979 for (Phone phone : PhoneFactory.getPhones()) {
1980 List<CellInfo> info = phone.getAllCellInfo();
1981 if (info != null) cellInfos.addAll(info);
1982 }
1983 return cellInfos;
1984 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001985
1986 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001987 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001988 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001989 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001990 if (!LocationAccessPolicy.canAccessCellLocation(mApp,
Svet Ganov4af66282018-03-07 19:57:05 -08001991 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001992 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001993 }
1994
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001995 final int targetSdk = getTargetSdk(callingPackage);
1996 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1997 return getCachedCellInfo();
1998 }
1999
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002000 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002001 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002002 final long identity = Binder.clearCallingIdentity();
2003 try {
2004 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2005 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002006 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002007 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002008 if (info != null) cellInfos.addAll(info);
2009 }
2010 return cellInfos;
2011 } finally {
2012 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002013 }
2014 }
2015
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002016 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002017 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2018 requestCellInfoUpdateInternal(
2019 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2020 }
2021
2022 @Override
2023 public void requestCellInfoUpdateWithWorkSource(
2024 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2025 enforceModifyPermission();
2026 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2027 }
2028
2029 private void requestCellInfoUpdateInternal(
2030 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002031 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002032 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002033 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
2034 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002035 return;
2036 }
2037
2038 final Phone phone = getPhone(subId);
2039 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2040
2041 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2042 }
2043
2044 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002045 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002046 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002047 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002048
2049 final long identity = Binder.clearCallingIdentity();
2050 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002051 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002052 } finally {
2053 Binder.restoreCallingIdentity(identity);
2054 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002055 }
2056
Shishir Agrawala9f32182016-04-12 12:00:16 -07002057 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002058 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002059 Phone phone = PhoneFactory.getPhone(slotIndex);
2060 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002061 return null;
2062 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002063 int subId = phone.getSubId();
2064 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2065 mApp, subId, callingPackage, "getImeiForSlot")) {
2066 return null;
2067 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002068
2069 final long identity = Binder.clearCallingIdentity();
2070 try {
2071 return phone.getImei();
2072 } finally {
2073 Binder.restoreCallingIdentity(identity);
2074 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002075 }
2076
2077 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002078 public String getTypeAllocationCodeForSlot(int slotIndex) {
2079 Phone phone = PhoneFactory.getPhone(slotIndex);
2080 String tac = null;
2081 if (phone != null) {
2082 String imei = phone.getImei();
2083 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2084 }
2085 return tac;
2086 }
2087
2088 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002089 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002090 Phone phone = PhoneFactory.getPhone(slotIndex);
2091 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002092 return null;
2093 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002094
Jeff Davidson913390f2018-02-23 17:11:49 -08002095 int subId = phone.getSubId();
2096 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2097 mApp, subId, callingPackage, "getMeidForSlot")) {
2098 return null;
2099 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002100
2101 final long identity = Binder.clearCallingIdentity();
2102 try {
2103 return phone.getMeid();
2104 } finally {
2105 Binder.restoreCallingIdentity(identity);
2106 }
Jack Yu2af8d712017-03-15 17:14:14 -07002107 }
2108
2109 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002110 public String getManufacturerCodeForSlot(int slotIndex) {
2111 Phone phone = PhoneFactory.getPhone(slotIndex);
2112 String manufacturerCode = null;
2113 if (phone != null) {
2114 String meid = phone.getMeid();
2115 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2116 }
2117 return manufacturerCode;
2118 }
2119
2120 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002121 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002122 Phone phone = PhoneFactory.getPhone(slotIndex);
2123 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002124 return null;
2125 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002126 int subId = phone.getSubId();
2127 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2128 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2129 return null;
2130 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002131
2132 final long identity = Binder.clearCallingIdentity();
2133 try {
2134 return phone.getDeviceSvn();
2135 } finally {
2136 Binder.restoreCallingIdentity(identity);
2137 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002138 }
2139
fionaxu43304da2017-11-27 22:51:16 -08002140 @Override
2141 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002142 final long identity = Binder.clearCallingIdentity();
2143 try {
2144 final Phone phone = getPhone(subId);
2145 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2146 } finally {
2147 Binder.restoreCallingIdentity(identity);
2148 }
fionaxu43304da2017-11-27 22:51:16 -08002149 }
2150
2151 @Override
2152 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002153 final long identity = Binder.clearCallingIdentity();
2154 try {
2155 final Phone phone = getPhone(subId);
2156 return phone == null ? null : phone.getCarrierName();
2157 } finally {
2158 Binder.restoreCallingIdentity(identity);
2159 }
fionaxu43304da2017-11-27 22:51:16 -08002160 }
2161
calvinpaneed9ae82018-11-01 19:43:06 +08002162 @Override
chen xuc93cc282018-11-04 17:17:00 -08002163 public int getSubscriptionPreciseCarrierId(int subId) {
2164 final long identity = Binder.clearCallingIdentity();
2165 try {
2166 final Phone phone = getPhone(subId);
2167 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2168 : phone.getPreciseCarrierId();
2169 } finally {
2170 Binder.restoreCallingIdentity(identity);
2171 }
2172 }
2173
2174 @Override
2175 public String getSubscriptionPreciseCarrierName(int subId) {
2176 final long identity = Binder.clearCallingIdentity();
2177 try {
2178 final Phone phone = getPhone(subId);
2179 return phone == null ? null : phone.getPreciseCarrierName();
2180 } finally {
2181 Binder.restoreCallingIdentity(identity);
2182 }
2183 }
2184
chen xu02581692018-11-11 19:03:44 -08002185 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002186 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2187 if (!isSubscriptionMccMnc) {
2188 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2189 }
chen xu02581692018-11-11 19:03:44 -08002190 final Phone phone = PhoneFactory.getPhone(slotIndex);
2191 if (phone == null) {
2192 return TelephonyManager.UNKNOWN_CARRIER_ID;
2193 }
2194 final long identity = Binder.clearCallingIdentity();
2195 try {
2196 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2197 } finally {
2198 Binder.restoreCallingIdentity(identity);
2199 }
2200 }
2201
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002202 //
2203 // Internal helper methods.
2204 //
2205
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002206 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002207 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2208 *
2209 * @throws SecurityException if the caller does not have the required permission
2210 */
2211 private void enforceModifyPermission() {
2212 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2213 }
2214
2215 /**
2216 * Make sure the caller has the CALL_PHONE permission.
2217 *
2218 * @throws SecurityException if the caller does not have the required permission
2219 */
2220 private void enforceCallPermission() {
2221 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2222 }
2223
Stuart Scott8eef64f2015-04-08 15:13:54 -07002224 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002225 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002226 "ConnectivityService");
2227 }
2228
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002229 private String createTelUrl(String number) {
2230 if (TextUtils.isEmpty(number)) {
2231 return null;
2232 }
2233
Jake Hambye994d462014-02-03 13:10:13 -08002234 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235 }
2236
Ihab Awadf9e92732013-12-05 18:02:52 -08002237 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002238 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2239 }
2240
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002241 private static void logv(String msg) {
2242 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2243 }
2244
Ihab Awadf9e92732013-12-05 18:02:52 -08002245 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002246 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2247 }
2248
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002249 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002250 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002251 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002252 }
2253
Sanket Padawe356d7632015-06-22 14:03:32 -07002254 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002255 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002256 final long identity = Binder.clearCallingIdentity();
2257 try {
2258 final Phone phone = PhoneFactory.getPhone(slotIndex);
2259 if (phone == null) {
2260 return PhoneConstants.PHONE_TYPE_NONE;
2261 } else {
2262 return phone.getPhoneType();
2263 }
2264 } finally {
2265 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002266 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 }
2268
2269 /**
2270 * Returns the CDMA ERI icon index to display
2271 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002272 @Override
2273 public int getCdmaEriIconIndex(String callingPackage) {
2274 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002275 }
2276
Sanket Padawe356d7632015-06-22 14:03:32 -07002277 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002278 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002279 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002280 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002281 return -1;
2282 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002283
2284 final long identity = Binder.clearCallingIdentity();
2285 try {
2286 final Phone phone = getPhone(subId);
2287 if (phone != null) {
2288 return phone.getCdmaEriIconIndex();
2289 } else {
2290 return -1;
2291 }
2292 } finally {
2293 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002294 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295 }
2296
2297 /**
2298 * Returns the CDMA ERI icon mode,
2299 * 0 - ON
2300 * 1 - FLASHING
2301 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002302 @Override
2303 public int getCdmaEriIconMode(String callingPackage) {
2304 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002305 }
2306
Sanket Padawe356d7632015-06-22 14:03:32 -07002307 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002308 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002309 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002310 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002311 return -1;
2312 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002313
2314 final long identity = Binder.clearCallingIdentity();
2315 try {
2316 final Phone phone = getPhone(subId);
2317 if (phone != null) {
2318 return phone.getCdmaEriIconMode();
2319 } else {
2320 return -1;
2321 }
2322 } finally {
2323 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002324 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002325 }
2326
2327 /**
2328 * Returns the CDMA ERI text,
2329 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002330 @Override
2331 public String getCdmaEriText(String callingPackage) {
2332 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002333 }
2334
Sanket Padawe356d7632015-06-22 14:03:32 -07002335 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002336 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002337 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002338 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002339 return null;
2340 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002341
2342 final long identity = Binder.clearCallingIdentity();
2343 try {
2344 final Phone phone = getPhone(subId);
2345 if (phone != null) {
2346 return phone.getCdmaEriText();
2347 } else {
2348 return null;
2349 }
2350 } finally {
2351 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002352 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 }
2354
2355 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002356 * Returns the CDMA MDN.
2357 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002358 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002359 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2361 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002362
2363 final long identity = Binder.clearCallingIdentity();
2364 try {
2365 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002366 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002367 return phone.getLine1Number();
2368 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002369 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002370 return null;
2371 }
2372 } finally {
2373 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002374 }
2375 }
2376
2377 /**
2378 * Returns the CDMA MIN.
2379 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002380 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002381 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2383 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002384
2385 final long identity = Binder.clearCallingIdentity();
2386 try {
2387 final Phone phone = getPhone(subId);
2388 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2389 return phone.getCdmaMin();
2390 } else {
2391 return null;
2392 }
2393 } finally {
2394 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002395 }
2396 }
2397
Hall Liud892bec2018-11-30 14:51:45 -08002398 @Override
2399 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2400 INumberVerificationCallback callback, String callingPackage) {
2401 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2402 != PERMISSION_GRANTED) {
2403 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2404 }
2405 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2406
2407 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2408 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2409 throw new SecurityException("Calling package must be configured in the device config");
2410 }
2411
2412 if (range == null) {
2413 throw new NullPointerException("Range must be non-null");
2414 }
2415
2416 timeoutMillis = Math.min(timeoutMillis,
2417 TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS);
2418
2419 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2420 }
2421
Junda Liuca05d5d2014-08-14 22:36:34 -07002422 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002423 * Returns true if CDMA provisioning needs to run.
2424 */
2425 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002426 final long identity = Binder.clearCallingIdentity();
2427 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002428 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002429 } finally {
2430 Binder.restoreCallingIdentity(identity);
2431 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432 }
2433
2434 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002435 * Sets the voice mail number of a given subId.
2436 */
2437 @Override
2438 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002439 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002440
2441 final long identity = Binder.clearCallingIdentity();
2442 try {
2443 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2444 new Pair<String, String>(alphaTag, number), new Integer(subId));
2445 return success;
2446 } finally {
2447 Binder.restoreCallingIdentity(identity);
2448 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002449 }
2450
Ta-wei Yen87c49842016-05-13 21:19:52 -07002451 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002452 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2453 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002454 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002455 if (!TextUtils.equals(callingPackage, systemDialer)) {
2456 throw new SecurityException("caller must be system dialer");
2457 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002458
2459 final long identity = Binder.clearCallingIdentity();
2460 try {
2461 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2462 if (phoneAccountHandle == null) {
2463 return null;
2464 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002465 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002466 } finally {
2467 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002468 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002469 }
2470
2471 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002472 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002473 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002474 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002475 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002476 return null;
2477 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002478
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002479 final long identity = Binder.clearCallingIdentity();
2480 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002481 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002482 } finally {
2483 Binder.restoreCallingIdentity(identity);
2484 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002485 }
2486
2487 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002488 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2489 VisualVoicemailSmsFilterSettings settings) {
2490 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002491
2492 final long identity = Binder.clearCallingIdentity();
2493 try {
2494 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002495 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002496 } finally {
2497 Binder.restoreCallingIdentity(identity);
2498 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002499 }
2500
2501 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002502 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2503 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002504
2505 final long identity = Binder.clearCallingIdentity();
2506 try {
2507 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002508 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002509 } finally {
2510 Binder.restoreCallingIdentity(identity);
2511 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002512 }
2513
2514 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002515 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2516 String callingPackage, int subId) {
2517 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002518
2519 final long identity = Binder.clearCallingIdentity();
2520 try {
2521 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002522 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002523 } finally {
2524 Binder.restoreCallingIdentity(identity);
2525 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002526 }
2527
2528 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002529 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002530 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002531
2532 final long identity = Binder.clearCallingIdentity();
2533 try {
2534 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002535 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002536 } finally {
2537 Binder.restoreCallingIdentity(identity);
2538 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002539 }
2540
2541 @Override
2542 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2543 String number, int port, String text, PendingIntent sentIntent) {
2544 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002545 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002546 enforceSendSmsPermission();
2547 // Make the calls as the phone process.
2548 final long identity = Binder.clearCallingIdentity();
2549 try {
2550 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2551 if (port == 0) {
2552 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2553 sentIntent, null, false);
2554 } else {
2555 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2556 smsManager.sendDataMessageWithSelfPermissions(number, null,
2557 (short) port, data, sentIntent, null);
2558 }
2559 } finally {
2560 Binder.restoreCallingIdentity(identity);
2561 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002562 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002563 /**
fionaxu0152e512016-11-14 13:36:14 -08002564 * Sets the voice activation state of a given subId.
2565 */
2566 @Override
2567 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002568 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2569 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002570
2571 final long identity = Binder.clearCallingIdentity();
2572 try {
2573 final Phone phone = getPhone(subId);
2574 if (phone != null) {
2575 phone.setVoiceActivationState(activationState);
2576 } else {
2577 loge("setVoiceActivationState fails with invalid subId: " + subId);
2578 }
2579 } finally {
2580 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002581 }
2582 }
2583
2584 /**
2585 * Sets the data activation state of a given subId.
2586 */
2587 @Override
2588 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002589 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2590 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002591
2592 final long identity = Binder.clearCallingIdentity();
2593 try {
2594 final Phone phone = getPhone(subId);
2595 if (phone != null) {
2596 phone.setDataActivationState(activationState);
2597 } else {
2598 loge("setVoiceActivationState fails with invalid subId: " + subId);
2599 }
2600 } finally {
2601 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002602 }
2603 }
2604
2605 /**
2606 * Returns the voice activation state of a given subId.
2607 */
2608 @Override
2609 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002610 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002611
fionaxu0152e512016-11-14 13:36:14 -08002612 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002613 final long identity = Binder.clearCallingIdentity();
2614 try {
2615 if (phone != null) {
2616 return phone.getVoiceActivationState();
2617 } else {
2618 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2619 }
2620 } finally {
2621 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002622 }
2623 }
2624
2625 /**
2626 * Returns the data activation state of a given subId.
2627 */
2628 @Override
2629 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002630 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002631
fionaxu0152e512016-11-14 13:36:14 -08002632 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002633 final long identity = Binder.clearCallingIdentity();
2634 try {
2635 if (phone != null) {
2636 return phone.getDataActivationState();
2637 } else {
2638 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2639 }
2640 } finally {
2641 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002642 }
2643 }
2644
2645 /**
Wink Saville36469e72014-06-11 15:17:00 -07002646 * Returns the unread count of voicemails for a subId
2647 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002648 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002649 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2650 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2651 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2652 return 0;
2653 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002654 final long identity = Binder.clearCallingIdentity();
2655 try {
2656 final Phone phone = getPhone(subId);
2657 if (phone != null) {
2658 return phone.getVoiceMessageCount();
2659 } else {
2660 return 0;
2661 }
2662 } finally {
2663 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002664 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002665 }
2666
2667 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002668 * returns true, if the device is in a state where both voice and data
2669 * are supported simultaneously. This can change based on location or network condition.
2670 */
2671 @Override
2672 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002673 final long identity = Binder.clearCallingIdentity();
2674 try {
2675 final Phone phone = getPhone(subId);
2676 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2677 } finally {
2678 Binder.restoreCallingIdentity(identity);
2679 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002680 }
2681
2682 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002683 * Send the dialer code if called from the current default dialer or the caller has
2684 * carrier privilege.
2685 * @param inputCode The dialer code to send
2686 */
2687 @Override
2688 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002689 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002690 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002691 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2692 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002693 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002694 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2695 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002696 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002697
2698 final long identity = Binder.clearCallingIdentity();
2699 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002700 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002701 } finally {
2702 Binder.restoreCallingIdentity(identity);
2703 }
fionaxu235cc5e2017-03-06 22:25:57 -08002704 }
2705
2706 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002707 * Returns the data network type.
2708 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002709 *
2710 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2711 */
2712 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002713 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002714 final long identity = Binder.clearCallingIdentity();
2715 try {
2716 final Phone phone = getPhone(getDefaultSubscription());
2717 if (phone != null) {
2718 return phone.getServiceState().getDataNetworkType();
2719 } else {
2720 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2721 }
2722 } finally {
2723 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002724 }
Wink Saville36469e72014-06-11 15:17:00 -07002725 }
2726
Pengquan Meng0c05b502018-09-06 09:59:22 -07002727 @Override
2728 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002729 if (!isActiveSubscription(subId)) {
2730 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2731 }
2732
Pengquan Meng0c05b502018-09-06 09:59:22 -07002733 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2734 }
2735
Brad Ebinger4c460712018-10-01 10:40:55 -07002736 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002737 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2738 throws RemoteException {
2739 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002740 final long token = Binder.clearCallingIdentity();
2741 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002742 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002743 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002744 .addRegistrationCallbackForSubscription(c, subId);
2745 } finally {
2746 Binder.restoreCallingIdentity(token);
2747 }
2748 }
2749
2750 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002751 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2752 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002753 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2754 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2755 }
2756 Binder.withCleanCallingIdentity(() -> {
2757 try {
2758 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002759 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002760 .removeRegistrationCallbackForSubscription(c, subId);
2761 } catch (IllegalArgumentException e) {
2762 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2763 + "is inactive, ignoring unregister.");
2764 // If the subscription is no longer active, just return, since the callback
2765 // will already have been removed internally.
2766 }
2767 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002768 }
2769
2770 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002771 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2772 throws RemoteException {
2773 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002774 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2775 final long token = Binder.clearCallingIdentity();
2776 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002777 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002778 .addCapabilitiesCallbackForSubscription(c, subId);
2779 } finally {
2780 Binder.restoreCallingIdentity(token);
2781 }
2782 }
2783
2784 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002785 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2786 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002787
2788 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2789 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2790 }
2791 Binder.withCleanCallingIdentity(() -> {
2792 try {
2793 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002794 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002795 .removeCapabilitiesCallbackForSubscription(c, subId);
2796 } catch (IllegalArgumentException e) {
2797 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2798 + "is inactive, ignoring unregister.");
2799 // If the subscription is no longer active, just return, since the callback
2800 // will already have been removed internally.
2801 }
2802 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002803 }
2804
2805 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002806 public boolean isCapable(int subId, int capability, int regTech) {
2807 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002808 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2809 final long token = Binder.clearCallingIdentity();
2810 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002811 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002812 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2813 } catch (ImsException e) {
2814 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2815 return false;
2816 } finally {
2817 Binder.restoreCallingIdentity(token);
2818 }
2819 }
2820
2821 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002822 public boolean isAvailable(int subId, int capability, int regTech) {
2823 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002824 final long token = Binder.clearCallingIdentity();
2825 try {
2826 Phone phone = getPhone(subId);
2827 if (phone == null) return false;
2828 return phone.isImsCapabilityAvailable(capability, regTech);
2829 } finally {
2830 Binder.restoreCallingIdentity(token);
2831 }
2832 }
2833
2834 @Override
2835 public boolean isAdvancedCallingSettingEnabled(int subId) {
2836 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2837 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2838 final long token = Binder.clearCallingIdentity();
2839 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002840 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002841 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2842 } finally {
2843 Binder.restoreCallingIdentity(token);
2844 }
2845 }
2846
2847 @Override
2848 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2849 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2850 "setAdvancedCallingSetting");
2851 final long identity = Binder.clearCallingIdentity();
2852 try {
2853 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002854 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002855 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2856 } finally {
2857 Binder.restoreCallingIdentity(identity);
2858 }
2859 }
2860
2861 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002862 public boolean isVtSettingEnabled(int subId) {
2863 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002864 final long identity = Binder.clearCallingIdentity();
2865 try {
2866 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002867 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002868 getSlotIndexOrException(subId)).isVtEnabledByUser();
2869 } finally {
2870 Binder.restoreCallingIdentity(identity);
2871 }
2872 }
2873
2874 @Override
2875 public void setVtSetting(int subId, boolean isEnabled) {
2876 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2877 "setVtSetting");
2878 final long identity = Binder.clearCallingIdentity();
2879 try {
2880 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002881 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002882 } finally {
2883 Binder.restoreCallingIdentity(identity);
2884 }
2885 }
2886
2887 @Override
2888 public boolean isVoWiFiSettingEnabled(int subId) {
2889 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2890 final long identity = Binder.clearCallingIdentity();
2891 try {
2892 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002893 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002894 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2895 } finally {
2896 Binder.restoreCallingIdentity(identity);
2897 }
2898 }
2899
2900 @Override
2901 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2902 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2903 "setVoWiFiSetting");
2904 final long identity = Binder.clearCallingIdentity();
2905 try {
2906 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002907 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002908 } finally {
2909 Binder.restoreCallingIdentity(identity);
2910 }
2911 }
2912
2913 @Override
2914 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2915 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2916 final long identity = Binder.clearCallingIdentity();
2917 try {
2918 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002919 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002920 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2921 } finally {
2922 Binder.restoreCallingIdentity(identity);
2923 }
2924 }
2925
2926 @Override
2927 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2928 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2929 "setVoWiFiRoamingSetting");
2930 final long identity = Binder.clearCallingIdentity();
2931 try {
2932 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002933 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002934 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2935 } finally {
2936 Binder.restoreCallingIdentity(identity);
2937 }
2938 }
2939
2940 @Override
2941 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2943 "setVoWiFiNonPersistent");
2944 final long identity = Binder.clearCallingIdentity();
2945 try {
2946 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08002947 boolean isRoaming = TelephonyManager.from(
2948 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002949 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08002950 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger4c460712018-10-01 10:40:55 -07002951 } finally {
2952 Binder.restoreCallingIdentity(identity);
2953 }
2954 }
2955
2956 @Override
2957 public int getVoWiFiModeSetting(int subId) {
2958 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2959 final long identity = Binder.clearCallingIdentity();
2960 try {
2961 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002962 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002963 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2964 } finally {
2965 Binder.restoreCallingIdentity(identity);
2966 }
2967 }
2968
2969 @Override
2970 public void setVoWiFiModeSetting(int subId, int mode) {
2971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2972 "setVoWiFiModeSetting");
2973 final long identity = Binder.clearCallingIdentity();
2974 try {
2975 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002976 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002977 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2978 } finally {
2979 Binder.restoreCallingIdentity(identity);
2980 }
2981 }
2982
2983 @Override
2984 public int getVoWiFiRoamingModeSetting(int subId) {
2985 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2986 final long identity = Binder.clearCallingIdentity();
2987 try {
2988 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002989 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002990 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2991 } finally {
2992 Binder.restoreCallingIdentity(identity);
2993 }
2994 }
2995
2996 @Override
2997 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2998 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2999 "setVoWiFiRoamingModeSetting");
3000 final long identity = Binder.clearCallingIdentity();
3001 try {
3002 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003003 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003004 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3005 } finally {
3006 Binder.restoreCallingIdentity(identity);
3007 }
3008 }
3009
3010 @Override
3011 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3013 "setRttCapabilityEnabled");
3014 final long identity = Binder.clearCallingIdentity();
3015 try {
3016 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003017 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003018 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3019 } finally {
3020 Binder.restoreCallingIdentity(identity);
3021 }
3022 }
3023
3024 @Override
3025 public boolean isTtyOverVolteEnabled(int subId) {
3026 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3027 final long identity = Binder.clearCallingIdentity();
3028 try {
3029 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003030 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003031 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3032 } finally {
3033 Binder.restoreCallingIdentity(identity);
3034 }
3035 }
3036
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003037 @Override
3038 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3039 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3040 final long identity = Binder.clearCallingIdentity();
3041 try {
3042 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003043 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003044 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003045 } finally {
3046 Binder.restoreCallingIdentity(identity);
3047 }
3048 }
3049
3050 @Override
3051 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3052 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3053 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003054 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3055 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3056 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003057 try {
3058 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003059 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003060 .removeProvisioningCallbackForSubscription(callback, subId);
3061 } catch (IllegalArgumentException e) {
3062 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3063 + "is inactive, ignoring unregister.");
3064 // If the subscription is no longer active, just return, since the callback will already
3065 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003066 } finally {
3067 Binder.restoreCallingIdentity(identity);
3068 }
3069 }
3070
3071 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003072 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3073 boolean isProvisioned) {
3074 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3075 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3076 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3077 }
3078 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3079 "setProvisioningStatusForCapability");
3080 final long identity = Binder.clearCallingIdentity();
3081 try {
3082 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3083 Phone phone = getPhone(subId);
3084 if (phone == null) {
3085 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3086 + subId);
3087 return;
3088 }
3089 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3090 return;
3091 }
3092
3093 // this capability requires provisioning, route to the correct API.
3094 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3095 switch (capability) {
3096 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3097 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3098 ims.setVolteProvisioned(isProvisioned);
3099 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3100 ims.setWfcProvisioned(isProvisioned);
3101 }
3102 break;
3103 }
3104 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3105 // There is currently no difference in VT provisioning type.
3106 ims.setVtProvisioned(isProvisioned);
3107 break;
3108 }
3109 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3110 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3111 // change the capability of the feature instead if needed.
3112 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3113 == isProvisioned) {
3114 // No change in provisioning.
3115 return;
3116 }
3117 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3118 try {
3119 ims.changeMmTelCapability(capability, tech, isProvisioned);
3120 } catch (ImsException e) {
3121 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3122 + ", Exception" + e.getMessage());
3123 }
3124 break;
3125 }
3126 default: {
3127 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3128 + capability + "', which does not require provisioning.");
3129 }
3130 }
3131
3132 } finally {
3133 Binder.restoreCallingIdentity(identity);
3134 }
3135 }
3136
3137 @Override
3138 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3139 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3140 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3141 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3142 }
3143 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3144 final long identity = Binder.clearCallingIdentity();
3145 try {
3146 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3147 Phone phone = getPhone(subId);
3148 if (phone == null) {
3149 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3150 + subId);
3151 // We will fail with "true" as the provisioning status because this is the default
3152 // if we do not require provisioning.
3153 return true;
3154 }
3155
3156 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3157 return true;
3158 }
3159
3160 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3161 switch (capability) {
3162 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3163 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3164 return ims.isVolteProvisionedOnDevice();
3165 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3166 return ims.isWfcProvisionedOnDevice();
3167 }
3168 // This should never happen, since we are checking tech above to make sure it
3169 // is either LTE or IWLAN.
3170 throw new IllegalArgumentException("Invalid radio technology for voice "
3171 + "capability.");
3172 }
3173 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3174 // There is currently no difference in VT provisioning type.
3175 return ims.isVtProvisionedOnDevice();
3176 }
3177 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3178 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3179 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3180 }
3181 default: {
3182 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3183 + capability + "', which does not require provisioning.");
3184 }
3185 }
3186
3187 } finally {
3188 Binder.restoreCallingIdentity(identity);
3189 }
3190 }
3191
3192 @Override
3193 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3194 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3195 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3196 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3197 }
3198 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3199 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3200 return (provisionedBits & capability) > 0;
3201 }
3202
3203 @Override
3204 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3205 boolean isProvisioned) {
3206 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3207 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3208 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3209 }
3210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3211 "setProvisioningStatusForCapability");
3212 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3213 // If the current provisioning status for capability already matches isProvisioned,
3214 // do nothing.
3215 if (((provisionedBits & capability) > 0) == isProvisioned) {
3216 return;
3217 }
3218 if (isProvisioned) {
3219 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3220 } else {
3221 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3222 }
3223 }
3224
3225 /**
3226 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3227 * technology. The bitfield should mirror the bitfield defined by
3228 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3229 */
3230 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3231 String key = getMmTelProvisioningKey(subId, tech);
3232 // Default is no capabilities are provisioned.
3233 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3234 }
3235
3236 /**
3237 * Sets the MmTel capability provisioning bitfield (defined by
3238 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3239 * technology specified.
3240 *
3241 * Note: This is a synchronous command and should not be called on UI thread.
3242 */
3243 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3244 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3245 String key = getMmTelProvisioningKey(subId, tech);
3246 editor.putInt(key, newField);
3247 editor.commit();
3248 }
3249
3250 private static String getMmTelProvisioningKey(int subId, int tech) {
3251 // resulting key is provision_ims_mmtel_{subId}_{tech}
3252 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3253 }
3254
3255 /**
3256 * Query CarrierConfig to see if the specified capability requires provisioning for the
3257 * carrier associated with the subscription id.
3258 */
3259 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3260 int capability) {
3261 CarrierConfigManager configManager = new CarrierConfigManager(context);
3262 PersistableBundle c = configManager.getConfigForSubId(subId);
3263 boolean requireUtProvisioning = c.getBoolean(
3264 // By default, this config is true (even if there is no SIM). We also check to make
3265 // sure the subscription needs provisioning here, so we do not need to check for
3266 // the no-SIM case, where we would normally shortcut this to false.
3267 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3268 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3269 false);
3270 boolean requireVoiceVtProvisioning = c.getBoolean(
3271 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3272
3273 // First check to make sure that the capability requires provisioning.
3274 switch (capability) {
3275 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3276 // intentional fallthrough
3277 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3278 if (requireVoiceVtProvisioning) {
3279 // Voice and Video requires provisioning
3280 return true;
3281 }
3282 break;
3283 }
3284 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3285 if (requireUtProvisioning) {
3286 // UT requires provisioning
3287 return true;
3288 }
3289 break;
3290 }
3291 }
3292 return false;
3293 }
3294
3295 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003296 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003297 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3298 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3299 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003300 enforceReadPrivilegedPermission("getImsProvisioningInt");
3301 final long identity = Binder.clearCallingIdentity();
3302 try {
3303 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003304 int slotId = getSlotIndex(subId);
3305 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3306 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3307 + subId + "' for key:" + key);
3308 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3309 }
3310 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003311 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003312 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3313 + subId + "' for key:" + key);
3314 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003315 } finally {
3316 Binder.restoreCallingIdentity(identity);
3317 }
3318 }
3319
3320 @Override
3321 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003322 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3323 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3324 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003325 enforceReadPrivilegedPermission("getImsProvisioningString");
3326 final long identity = Binder.clearCallingIdentity();
3327 try {
3328 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003329 int slotId = getSlotIndex(subId);
3330 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3331 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3332 + subId + "' for key:" + key);
3333 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3334 }
3335 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003336 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003337 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3338 + subId + "' for key:" + key);
3339 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003340 } finally {
3341 Binder.restoreCallingIdentity(identity);
3342 }
3343 }
3344
3345 @Override
3346 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003347 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3348 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3349 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003350 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3351 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003352 final long identity = Binder.clearCallingIdentity();
3353 try {
3354 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003355 int slotId = getSlotIndex(subId);
3356 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3357 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3358 + subId + "' for key:" + key);
3359 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3360 }
3361 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003362 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003363 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3364 + "' for key:" + key);
3365 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003366 } finally {
3367 Binder.restoreCallingIdentity(identity);
3368 }
3369 }
3370
3371 @Override
3372 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003373 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3374 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3375 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3377 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003378 final long identity = Binder.clearCallingIdentity();
3379 try {
3380 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003381 int slotId = getSlotIndex(subId);
3382 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3383 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3384 + subId + "' for key:" + key);
3385 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3386 }
3387 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003388 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003389 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3390 + "' for key:" + key);
3391 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003392 } finally {
3393 Binder.restoreCallingIdentity(identity);
3394 }
3395 }
3396
Brad Ebinger4c460712018-10-01 10:40:55 -07003397 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3398 int slotId = SubscriptionManager.getSlotIndex(subId);
3399 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3400 throw new IllegalArgumentException("Invalid Subscription Id.");
3401 }
3402 return slotId;
3403 }
3404
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003405 private int getSlotIndex(int subId) {
3406 int slotId = SubscriptionManager.getSlotIndex(subId);
3407 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3408 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3409 }
3410 return slotId;
3411 }
3412
Wink Saville36469e72014-06-11 15:17:00 -07003413 /**
3414 * Returns the network type for a subId
3415 */
3416 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003417 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003418 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003419 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003420 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3421 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003422
Malcolm Chend965c8b2018-02-28 15:00:40 -08003423 final long identity = Binder.clearCallingIdentity();
3424 try {
3425 final Phone phone = getPhone(subId);
3426 if (phone != null) {
3427 return phone.getServiceState().getDataNetworkType();
3428 } else {
3429 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3430 }
3431 } finally {
3432 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003433 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003434 }
3435
3436 /**
3437 * Returns the data network type
3438 */
3439 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003440 public int getDataNetworkType(String callingPackage) {
3441 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003442 }
3443
3444 /**
3445 * Returns the data network type for a subId
3446 */
3447 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003448 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003449 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003450 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003451 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3452 }
3453
Malcolm Chend965c8b2018-02-28 15:00:40 -08003454 final long identity = Binder.clearCallingIdentity();
3455 try {
3456 final Phone phone = getPhone(subId);
3457 if (phone != null) {
3458 return phone.getServiceState().getDataNetworkType();
3459 } else {
3460 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3461 }
3462 } finally {
3463 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003464 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003465 }
3466
3467 /**
Wink Saville36469e72014-06-11 15:17:00 -07003468 * Returns the Voice network type for a subId
3469 */
3470 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003471 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003472 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003473 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003474 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3475 }
3476
Malcolm Chend965c8b2018-02-28 15:00:40 -08003477 final long identity = Binder.clearCallingIdentity();
3478 try {
3479 final Phone phone = getPhone(subId);
3480 if (phone != null) {
3481 return phone.getServiceState().getVoiceNetworkType();
3482 } else {
3483 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3484 }
3485 } finally {
3486 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003487 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003488 }
3489
3490 /**
3491 * @return true if a ICC card is present
3492 */
3493 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003494 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003495 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3496 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003497 }
3498
3499 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003500 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003501 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003502 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003503 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003504 final long identity = Binder.clearCallingIdentity();
3505 try {
3506 final Phone phone = PhoneFactory.getPhone(slotIndex);
3507 if (phone != null) {
3508 return phone.getIccCard().hasIccCard();
3509 } else {
3510 return false;
3511 }
3512 } finally {
3513 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003514 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003515 }
3516
3517 /**
3518 * Return if the current radio is LTE on CDMA. This
3519 * is a tri-state return value as for a period of time
3520 * the mode may be unknown.
3521 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003522 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003523 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003524 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003525 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003526 @Override
3527 public int getLteOnCdmaMode(String callingPackage) {
3528 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003529 }
3530
Sanket Padawe356d7632015-06-22 14:03:32 -07003531 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003532 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003533 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003534 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003535 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3536 }
3537
Malcolm Chend965c8b2018-02-28 15:00:40 -08003538 final long identity = Binder.clearCallingIdentity();
3539 try {
3540 final Phone phone = getPhone(subId);
3541 if (phone == null) {
3542 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3543 } else {
3544 return phone.getLteOnCdmaMode();
3545 }
3546 } finally {
3547 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003548 }
Wink Saville36469e72014-06-11 15:17:00 -07003549 }
3550
Wink Saville36469e72014-06-11 15:17:00 -07003551 /**
3552 * {@hide}
3553 * Returns Default subId, 0 in the case of single standby.
3554 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003555 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003556 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003557 }
3558
Shishir Agrawala9f32182016-04-12 12:00:16 -07003559 private int getSlotForDefaultSubscription() {
3560 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3561 }
3562
Wink Savilleb564aae2014-10-23 10:18:09 -07003563 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003564 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003565 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003566
Pengquan Meng466e2482018-09-21 15:54:48 -07003567 private boolean isActiveSubscription(int subId) {
3568 return mSubscriptionController.isActiveSubId(subId);
3569 }
3570
Ihab Awadf2177b72013-11-25 13:33:23 -08003571 /**
3572 * @see android.telephony.TelephonyManager.WifiCallingChoices
3573 */
3574 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003575 final long identity = Binder.clearCallingIdentity();
3576 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003577 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003578 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3579 getWhenToMakeWifiCallsDefaultPreference());
3580 } finally {
3581 Binder.restoreCallingIdentity(identity);
3582 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003583 }
3584
3585 /**
3586 * @see android.telephony.TelephonyManager.WifiCallingChoices
3587 */
3588 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003589 final long identity = Binder.clearCallingIdentity();
3590 try {
3591 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003592 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003593 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3594 } finally {
3595 Binder.restoreCallingIdentity(identity);
3596 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003597 }
3598
Sailesh Nepald1e68152013-12-12 19:08:02 -08003599 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003600 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003601 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003602 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003603
Shishir Agrawal566b7612013-10-28 14:41:00 -07003604 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003605 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3606 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003607 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3608 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003609 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003610
Malcolm Chend965c8b2018-02-28 15:00:40 -08003611 final long identity = Binder.clearCallingIdentity();
3612 try {
3613 if (TextUtils.equals(ISDR_AID, aid)) {
3614 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003615 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3616 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003617 if (bestComponent == null
3618 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3619 loge("The calling package is not allowed to access ISD-R.");
3620 throw new SecurityException(
3621 "The calling package is not allowed to access ISD-R.");
3622 }
Derek Tan740e1672017-06-27 14:56:27 -07003623 }
Derek Tan740e1672017-06-27 14:56:27 -07003624
Malcolm Chend965c8b2018-02-28 15:00:40 -08003625 if (DBG) {
3626 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3627 }
3628 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3629 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3630 if (DBG) log("iccOpenLogicalChannel: " + response);
3631 return response;
3632 } finally {
3633 Binder.restoreCallingIdentity(identity);
3634 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003635 }
3636
3637 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003638 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003639 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3640 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003641
Malcolm Chend965c8b2018-02-28 15:00:40 -08003642 final long identity = Binder.clearCallingIdentity();
3643 try {
3644 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3645 if (channel < 0) {
3646 return false;
3647 }
3648 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3649 if (DBG) log("iccCloseLogicalChannel: " + success);
3650 return success;
3651 } finally {
3652 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003653 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003654 }
3655
3656 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003657 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003658 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3660 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003661
Malcolm Chend965c8b2018-02-28 15:00:40 -08003662 final long identity = Binder.clearCallingIdentity();
3663 try {
3664 if (DBG) {
3665 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3666 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3667 + p3 + " data=" + data);
3668 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003669
Malcolm Chend965c8b2018-02-28 15:00:40 -08003670 if (channel < 0) {
3671 return "";
3672 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003673
Malcolm Chend965c8b2018-02-28 15:00:40 -08003674 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3675 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3676 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003677
Malcolm Chend965c8b2018-02-28 15:00:40 -08003678 // Append the returned status code to the end of the response payload.
3679 String s = Integer.toHexString(
3680 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3681 if (response.payload != null) {
3682 s = IccUtils.bytesToHexString(response.payload) + s;
3683 }
3684 return s;
3685 } finally {
3686 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003687 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003688 }
Jake Hambye994d462014-02-03 13:10:13 -08003689
Evan Charltonc66da362014-05-16 14:06:40 -07003690 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003691 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3692 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3694 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003695 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003696
Malcolm Chend965c8b2018-02-28 15:00:40 -08003697 final long identity = Binder.clearCallingIdentity();
3698 try {
3699 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3700 && TextUtils.equals(ISDR_AID, data)) {
3701 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003702 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3703 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003704 if (bestComponent == null
3705 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3706 loge("The calling package is not allowed to select ISD-R.");
3707 throw new SecurityException(
3708 "The calling package is not allowed to select ISD-R.");
3709 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003710 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003711
Malcolm Chend965c8b2018-02-28 15:00:40 -08003712 if (DBG) {
3713 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3714 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3715 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003716
Malcolm Chend965c8b2018-02-28 15:00:40 -08003717 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3718 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3719 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003720
Malcolm Chend965c8b2018-02-28 15:00:40 -08003721 // Append the returned status code to the end of the response payload.
3722 String s = Integer.toHexString(
3723 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3724 if (response.payload != null) {
3725 s = IccUtils.bytesToHexString(response.payload) + s;
3726 }
3727 return s;
3728 } finally {
3729 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003730 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003731 }
3732
3733 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003734 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003735 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003736 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3737 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003738
Malcolm Chend965c8b2018-02-28 15:00:40 -08003739 final long identity = Binder.clearCallingIdentity();
3740 try {
3741 if (DBG) {
3742 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3743 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3744 }
3745
3746 IccIoResult response =
3747 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3748 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3749 subId);
3750
3751 if (DBG) {
3752 log("Exchange SIM_IO [R]" + response);
3753 }
3754
3755 byte[] result = null;
3756 int length = 2;
3757 if (response.payload != null) {
3758 length = 2 + response.payload.length;
3759 result = new byte[length];
3760 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3761 } else {
3762 result = new byte[length];
3763 }
3764
3765 result[length - 1] = (byte) response.sw2;
3766 result[length - 2] = (byte) response.sw1;
3767 return result;
3768 } finally {
3769 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003770 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003771 }
3772
Nathan Haroldb3014052017-01-25 15:57:32 -08003773 /**
3774 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3775 * on a particular subscription
3776 */
sqianb6e41952018-03-12 14:54:01 -07003777 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3778 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3779 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3780 return null;
3781 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003782
3783 final long identity = Binder.clearCallingIdentity();
3784 try {
3785 if (appType != TelephonyManager.APPTYPE_USIM
3786 && appType != TelephonyManager.APPTYPE_SIM) {
3787 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3788 return null;
3789 }
3790 Object response = sendRequest(
3791 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3792 if (response instanceof String[]) {
3793 return (String[]) response;
3794 }
3795 // Response is an Exception of some kind,
3796 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003797 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003798 } finally {
3799 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003800 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003801 }
3802
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003803 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003804 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003805 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3806 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003807
Malcolm Chend965c8b2018-02-28 15:00:40 -08003808 final long identity = Binder.clearCallingIdentity();
3809 try {
3810 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3811 if (response.payload == null) {
3812 return "";
3813 }
Evan Charltonc66da362014-05-16 14:06:40 -07003814
Malcolm Chend965c8b2018-02-28 15:00:40 -08003815 // Append the returned status code to the end of the response payload.
3816 String s = Integer.toHexString(
3817 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3818 s = IccUtils.bytesToHexString(response.payload) + s;
3819 return s;
3820 } finally {
3821 Binder.restoreCallingIdentity(identity);
3822 }
Evan Charltonc66da362014-05-16 14:06:40 -07003823 }
3824
Jake Hambye994d462014-02-03 13:10:13 -08003825 /**
3826 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3827 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3828 *
3829 * @param itemID the ID of the item to read
3830 * @return the NV item as a String, or null on error.
3831 */
3832 @Override
3833 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003834 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3836 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003837
3838 final long identity = Binder.clearCallingIdentity();
3839 try {
3840 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003841 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003842 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3843 return value;
3844 } finally {
3845 Binder.restoreCallingIdentity(identity);
3846 }
Jake Hambye994d462014-02-03 13:10:13 -08003847 }
3848
3849 /**
3850 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3851 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3852 *
3853 * @param itemID the ID of the item to read
3854 * @param itemValue the value to write, as a String
3855 * @return true on success; false on any failure
3856 */
3857 @Override
3858 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003859 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003860 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3861 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003862
3863 final long identity = Binder.clearCallingIdentity();
3864 try {
3865 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3866 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003867 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003868 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3869 return success;
3870 } finally {
3871 Binder.restoreCallingIdentity(identity);
3872 }
Jake Hambye994d462014-02-03 13:10:13 -08003873 }
3874
3875 /**
3876 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3877 * Used for device configuration by some CDMA operators.
3878 *
3879 * @param preferredRoamingList byte array containing the new PRL
3880 * @return true on success; false on any failure
3881 */
3882 @Override
3883 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003884 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3885 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003886
3887 final long identity = Binder.clearCallingIdentity();
3888 try {
3889 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3890 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3891 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3892 return success;
3893 } finally {
3894 Binder.restoreCallingIdentity(identity);
3895 }
Jake Hambye994d462014-02-03 13:10:13 -08003896 }
3897
3898 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003899 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003900 * Used for device configuration by some CDMA operators.
3901 *
chen xu1cc0abe2018-10-26 17:39:23 -07003902 * @param slotIndex - device slot.
3903 *
Jake Hambye994d462014-02-03 13:10:13 -08003904 * @return true on success; false on any failure
3905 */
3906 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003907 public boolean resetModemConfig(int slotIndex) {
3908 Phone phone = PhoneFactory.getPhone(slotIndex);
3909 if (phone != null) {
3910 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3911 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003912
chen xu1cc0abe2018-10-26 17:39:23 -07003913 final long identity = Binder.clearCallingIdentity();
3914 try {
3915 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3916 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3917 return success;
3918 } finally {
3919 Binder.restoreCallingIdentity(identity);
3920 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003921 }
chen xu1cc0abe2018-10-26 17:39:23 -07003922 return false;
3923 }
3924
3925 /**
3926 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3927 *
3928 * @param slotIndex - device slot.
3929 *
3930 * @return true on success; false on any failure
3931 */
3932 @Override
3933 public boolean rebootModem(int slotIndex) {
3934 Phone phone = PhoneFactory.getPhone(slotIndex);
3935 if (phone != null) {
3936 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3937 mApp, phone.getSubId(), "rebootModem");
3938
3939 final long identity = Binder.clearCallingIdentity();
3940 try {
3941 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3942 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3943 return success;
3944 } finally {
3945 Binder.restoreCallingIdentity(identity);
3946 }
3947 }
3948 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003949 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003950
Svet Ganovb320e182015-04-16 12:30:10 -07003951 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003952 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003953 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003954 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003955 return new String[0];
3956 }
3957
Malcolm Chend965c8b2018-02-28 15:00:40 -08003958 final long identity = Binder.clearCallingIdentity();
3959 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003960 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003961 } finally {
3962 Binder.restoreCallingIdentity(identity);
3963 }
Wink Saville36469e72014-06-11 15:17:00 -07003964 }
3965
Brad Ebinger51f743a2017-01-23 13:50:20 -08003966 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003967 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3968 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003969 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003970 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003971 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003972
3973 final long identity = Binder.clearCallingIdentity();
3974 try {
3975 PhoneFactory.getImsResolver().enableIms(slotId);
3976 } finally {
3977 Binder.restoreCallingIdentity(identity);
3978 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003979 }
3980
3981 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003982 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3983 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003984 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003985 public void disableIms(int slotId) {
3986 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003987
3988 final long identity = Binder.clearCallingIdentity();
3989 try {
3990 PhoneFactory.getImsResolver().disableIms(slotId);
3991 } finally {
3992 Binder.restoreCallingIdentity(identity);
3993 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003994 }
3995
3996 /**
3997 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3998 * feature or {@link null} if the service is not available. If the feature is available, the
3999 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4000 */
4001 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004002 IImsServiceFeatureCallback callback) {
4003 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004004
4005 final long identity = Binder.clearCallingIdentity();
4006 try {
4007 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
4008 } finally {
4009 Binder.restoreCallingIdentity(identity);
4010 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004011 }
4012
4013 /**
4014 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4015 * feature during emergency calling or {@link null} if the service is not available. If the
4016 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4017 * listener for feature updates.
4018 */
4019 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4020 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004021
4022 final long identity = Binder.clearCallingIdentity();
4023 try {
4024 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
4025 } finally {
4026 Binder.restoreCallingIdentity(identity);
4027 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004028 }
4029
Brad Ebinger5f64b052017-12-14 14:26:15 -08004030 /**
4031 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
4032 * specified.
4033 */
4034 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4035 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004036
4037 final long identity = Binder.clearCallingIdentity();
4038 try {
4039 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
4040 } finally {
4041 Binder.restoreCallingIdentity(identity);
4042 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004043 }
4044
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004045 /**
4046 * Returns the {@link IImsConfig} structure associated with the slotId and feature
4047 * specified.
4048 */
4049 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4050 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004051
4052 final long identity = Binder.clearCallingIdentity();
4053 try {
4054 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
4055 } finally {
4056 Binder.restoreCallingIdentity(identity);
4057 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004058 }
4059
Brad Ebinger884c07b2018-02-15 16:17:40 -08004060 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004061 * Sets the ImsService Package Name that Telephony will bind to.
4062 *
4063 * @param slotId the slot ID that the ImsService should bind for.
4064 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4065 * ImsService is the device default ImsService.
4066 * @param packageName The package name of the application that contains the ImsService to bind
4067 * to.
4068 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4069 * @hide
4070 */
4071 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004072 int[] subIds = SubscriptionManager.getSubId(slotId);
4073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4074 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4075 "setImsService");
4076
Malcolm Chend965c8b2018-02-28 15:00:40 -08004077 final long identity = Binder.clearCallingIdentity();
4078 try {
4079 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
4080 isCarrierImsService, packageName);
4081 } finally {
4082 Binder.restoreCallingIdentity(identity);
4083 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004084 }
4085
4086 /**
4087 * Return the ImsService configuration.
4088 *
4089 * @param slotId The slot that the ImsService is associated with.
4090 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4091 * the device default.
4092 * @return the package name of the ImsService configuration.
4093 */
4094 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004095 int[] subIds = SubscriptionManager.getSubId(slotId);
4096 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4097 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4098 "getImsService");
4099
Malcolm Chend965c8b2018-02-28 15:00:40 -08004100 final long identity = Binder.clearCallingIdentity();
4101 try {
4102 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
4103 isCarrierImsService);
4104 } finally {
4105 Binder.restoreCallingIdentity(identity);
4106 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004107 }
4108
Wink Saville36469e72014-06-11 15:17:00 -07004109 public void setImsRegistrationState(boolean registered) {
4110 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004111
4112 final long identity = Binder.clearCallingIdentity();
4113 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004114 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004115 } finally {
4116 Binder.restoreCallingIdentity(identity);
4117 }
Wink Saville36469e72014-06-11 15:17:00 -07004118 }
4119
4120 /**
Stuart Scott54788802015-03-30 13:18:01 -07004121 * Set the network selection mode to automatic.
4122 *
4123 */
4124 @Override
4125 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004126 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4127 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004128
Pengquan Meng466e2482018-09-21 15:54:48 -07004129 if (!isActiveSubscription(subId)) {
4130 return;
4131 }
4132
Malcolm Chend965c8b2018-02-28 15:00:40 -08004133 final long identity = Binder.clearCallingIdentity();
4134 try {
4135 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4136 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4137 } finally {
4138 Binder.restoreCallingIdentity(identity);
4139 }
Stuart Scott54788802015-03-30 13:18:01 -07004140 }
4141
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004142 /**
4143 * Ask the radio to connect to the input network and change selection mode to manual.
4144 *
4145 * @param subId the id of the subscription.
4146 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4147 * the operator to attach to.
4148 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4149 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4150 * normal network selection next time.
4151 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004152 */
4153 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004154 public boolean setNetworkSelectionModeManual(
4155 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4157 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004158
4159 if (!isActiveSubscription(subId)) {
4160 return false;
4161 }
4162
Malcolm Chend965c8b2018-02-28 15:00:40 -08004163 final long identity = Binder.clearCallingIdentity();
4164 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004165 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004166 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004167 if (DBG) {
4168 log("setNetworkSelectionModeManual: subId: " + subId
4169 + " operator: " + operatorInfo);
4170 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004171 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4172 } finally {
4173 Binder.restoreCallingIdentity(identity);
4174 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004175 }
4176
4177 /**
4178 * Scans for available networks.
4179 */
4180 @Override
4181 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004182 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4183 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004184
Pengquan Meng0c05b502018-09-06 09:59:22 -07004185 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004186 try {
4187 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004188 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004189 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004190 } finally {
4191 Binder.restoreCallingIdentity(identity);
4192 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004193 }
4194
4195 /**
yinxub1bed742017-04-17 11:45:04 -07004196 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004197 *
yinxub1bed742017-04-17 11:45:04 -07004198 * @param subId id of the subscription
4199 * @param request contains the radio access networks with bands/channels to scan
4200 * @param messenger callback messenger for scan results or errors
4201 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004202 * @return the id of the requested scan which can be used to stop the scan.
4203 */
4204 @Override
4205 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
4206 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004207 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4208 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004209
4210 final long identity = Binder.clearCallingIdentity();
4211 try {
4212 return mNetworkScanRequestTracker.startNetworkScan(
4213 request, messenger, binder, getPhone(subId));
4214 } finally {
4215 Binder.restoreCallingIdentity(identity);
4216 }
yinxu504e1392017-04-12 16:03:22 -07004217 }
4218
4219 /**
4220 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004221 *
4222 * @param subId id of the subscription
4223 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004224 */
4225 @Override
4226 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004227 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4228 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004229
4230 final long identity = Binder.clearCallingIdentity();
4231 try {
4232 mNetworkScanRequestTracker.stopNetworkScan(scanId);
4233 } finally {
4234 Binder.restoreCallingIdentity(identity);
4235 }
yinxu504e1392017-04-12 16:03:22 -07004236 }
4237
4238 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004239 * Get the calculated preferred network type.
4240 * Used for debugging incorrect network type.
4241 *
4242 * @return the preferred network type, defined in RILConstants.java.
4243 */
4244 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004245 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004246 final Phone defaultPhone = getDefaultPhone();
4247 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4248 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004249 return RILConstants.PREFERRED_NETWORK_MODE;
4250 }
4251
Malcolm Chend965c8b2018-02-28 15:00:40 -08004252 final long identity = Binder.clearCallingIdentity();
4253 try {
4254 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004255 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004256 } finally {
4257 Binder.restoreCallingIdentity(identity);
4258 }
Junda Liu84d15a22014-07-02 11:21:04 -07004259 }
4260
4261 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004262 * Get the preferred network type.
4263 * Used for device configuration by some CDMA operators.
4264 *
4265 * @return the preferred network type, defined in RILConstants.java.
4266 */
4267 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004268 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004269 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4270 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004271
4272 final long identity = Binder.clearCallingIdentity();
4273 try {
4274 if (DBG) log("getPreferredNetworkType");
4275 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4276 int networkType = (result != null ? result[0] : -1);
4277 if (DBG) log("getPreferredNetworkType: " + networkType);
4278 return networkType;
4279 } finally {
4280 Binder.restoreCallingIdentity(identity);
4281 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004282 }
4283
4284 /**
4285 * Set the preferred network type.
4286 * Used for device configuration by some CDMA operators.
4287 *
4288 * @param networkType the preferred network type, defined in RILConstants.java.
4289 * @return true on success; false on any failure.
4290 */
4291 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004292 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004293 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4294 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004295
4296 final long identity = Binder.clearCallingIdentity();
4297 try {
4298 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4299 Boolean success = (Boolean) sendRequest(
4300 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4301 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4302 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004303 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004304 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4305 }
4306 return success;
4307 } finally {
4308 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004309 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004310 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004311
4312 /**
Junda Liu475951f2014-11-07 16:45:03 -08004313 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07004314 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08004315 * tethering.
4316 *
4317 * @return 0: Not required. 1: required. 2: Not set.
4318 * @hide
4319 */
4320 @Override
4321 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004322 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004323
4324 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004325 final Phone defaultPhone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004326 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004327 int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004328 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07004329 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004330 if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004331 dunRequired = 1;
4332 }
4333 return dunRequired;
4334 } finally {
4335 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004336 }
Junda Liu475951f2014-11-07 16:45:03 -08004337 }
4338
4339 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004340 * Set mobile data enabled
4341 * Used by the user through settings etc to turn on/off mobile data
4342 *
4343 * @param enable {@code true} turn turn data on, else {@code false}
4344 */
4345 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004346 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4348 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004349
4350 final long identity = Binder.clearCallingIdentity();
4351 try {
4352 int phoneId = mSubscriptionController.getPhoneId(subId);
4353 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4354 Phone phone = PhoneFactory.getPhone(phoneId);
4355 if (phone != null) {
4356 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004357 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004358 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004359 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004360 }
4361 } finally {
4362 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004363 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004364 }
4365
4366 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004367 * Get the user enabled state of Mobile Data.
4368 *
4369 * TODO: remove and use isUserDataEnabled.
4370 * This can't be removed now because some vendor codes
4371 * calls through ITelephony directly while they should
4372 * use TelephonyManager.
4373 *
4374 * @return true on enabled
4375 */
4376 @Override
4377 public boolean getDataEnabled(int subId) {
4378 return isUserDataEnabled(subId);
4379 }
4380
4381 /**
4382 * Get whether mobile data is enabled per user setting.
4383 *
4384 * There are other factors deciding whether mobile data is actually enabled, but they are
4385 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004386 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004387 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004388 *
4389 * @return {@code true} if data is enabled else {@code false}
4390 */
4391 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004392 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004393 try {
4394 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4395 null);
4396 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004397 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4398 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004399 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004400
4401 final long identity = Binder.clearCallingIdentity();
4402 try {
4403 int phoneId = mSubscriptionController.getPhoneId(subId);
4404 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4405 Phone phone = PhoneFactory.getPhone(phoneId);
4406 if (phone != null) {
4407 boolean retVal = phone.isUserDataEnabled();
4408 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4409 return retVal;
4410 } else {
4411 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4412 return false;
4413 }
4414 } finally {
4415 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004416 }
4417 }
4418
4419 /**
4420 * Get whether mobile data is enabled.
4421 *
4422 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4423 * whether mobile data is actually enabled.
4424 *
4425 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4426 *
4427 * @return {@code true} if data is enabled else {@code false}
4428 */
4429 @Override
4430 public boolean isDataEnabled(int subId) {
4431 try {
4432 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4433 null);
4434 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004435 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4436 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004437 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004438
4439 final long identity = Binder.clearCallingIdentity();
4440 try {
4441 int phoneId = mSubscriptionController.getPhoneId(subId);
4442 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4443 Phone phone = PhoneFactory.getPhone(phoneId);
4444 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004445 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004446 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4447 return retVal;
4448 } else {
4449 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4450 return false;
4451 }
4452 } finally {
4453 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004454 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004455 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004456
4457 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004458 public int getCarrierPrivilegeStatus(int subId) {
4459 final Phone phone = getPhone(subId);
4460 if (phone == null) {
4461 loge("getCarrierPrivilegeStatus: Invalid subId");
4462 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4463 }
4464 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004465 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004466 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004467 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4468 }
4469 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004470 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004471 }
Junda Liu29340342014-07-10 15:23:27 -07004472
4473 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004474 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4475 final Phone phone = getPhone(subId);
4476 if (phone == null) {
4477 loge("getCarrierPrivilegeStatus: Invalid subId");
4478 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4479 }
4480 UiccProfile profile =
4481 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4482 if (profile == null) {
4483 loge("getCarrierPrivilegeStatus: No UICC");
4484 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4485 }
4486 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4487 }
4488
4489 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004490 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004491 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004492 if (TextUtils.isEmpty(pkgName))
4493 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004494 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004495 if (card == null) {
4496 loge("checkCarrierPrivilegesForPackage: No UICC");
4497 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4498 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004499 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4500 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004501 }
4502
4503 @Override
4504 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004505 if (TextUtils.isEmpty(pkgName))
4506 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004507 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4508 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4509 UiccCard card = UiccController.getInstance().getUiccCard(i);
4510 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004511 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004512 continue;
4513 }
4514
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004515 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004516 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4517 break;
4518 }
4519 }
4520
4521 return result;
Junda Liu29340342014-07-10 15:23:27 -07004522 }
Derek Tan89e89d42014-07-08 17:00:10 -07004523
4524 @Override
Junda Liue64de782015-04-16 17:19:16 -07004525 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4526 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4527 loge("phoneId " + phoneId + " is not valid.");
4528 return null;
4529 }
4530 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004531 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004532 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004533 return null ;
4534 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004535 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004536 }
4537
Amith Yamasani6e118872016-02-19 12:53:51 -08004538 @Override
4539 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004540 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004541 List<String> privilegedPackages = new ArrayList<>();
4542 List<PackageInfo> packages = null;
4543 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4544 UiccCard card = UiccController.getInstance().getUiccCard(i);
4545 if (card == null) {
4546 // No UICC in that slot.
4547 continue;
4548 }
4549 if (card.hasCarrierPrivilegeRules()) {
4550 if (packages == null) {
4551 // Only check packages in user 0 for now
4552 packages = pm.getInstalledPackagesAsUser(
4553 PackageManager.MATCH_DISABLED_COMPONENTS
4554 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4555 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4556 }
4557 for (int p = packages.size() - 1; p >= 0; p--) {
4558 PackageInfo pkgInfo = packages.get(p);
4559 if (pkgInfo != null && pkgInfo.packageName != null
4560 && card.getCarrierPrivilegeStatus(pkgInfo)
4561 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4562 privilegedPackages.add(pkgInfo.packageName);
4563 }
4564 }
4565 }
4566 }
4567 return privilegedPackages;
4568 }
4569
Wink Savilleb564aae2014-10-23 10:18:09 -07004570 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004571 final Phone phone = getPhone(subId);
4572 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004573 if (card == null) {
4574 loge("getIccId: No UICC");
4575 return null;
4576 }
4577 String iccId = card.getIccId();
4578 if (TextUtils.isEmpty(iccId)) {
4579 loge("getIccId: ICC ID is null or empty.");
4580 return null;
4581 }
4582 return iccId;
4583 }
4584
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004585 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004586 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4587 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004588 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4589 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004590
Malcolm Chend965c8b2018-02-28 15:00:40 -08004591 final long identity = Binder.clearCallingIdentity();
4592 try {
4593 final String iccId = getIccId(subId);
4594 final Phone phone = getPhone(subId);
4595 if (phone == null) {
4596 return false;
4597 }
4598 final String subscriberId = phone.getSubscriberId();
4599
4600 if (DBG_MERGE) {
4601 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4602 + subscriberId + " to " + number);
4603 }
4604
4605 if (TextUtils.isEmpty(iccId)) {
4606 return false;
4607 }
4608
4609 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4610
4611 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4612 if (alphaTag == null) {
4613 editor.remove(alphaTagPrefKey);
4614 } else {
4615 editor.putString(alphaTagPrefKey, alphaTag);
4616 }
4617
4618 // Record both the line number and IMSI for this ICCID, since we need to
4619 // track all merged IMSIs based on line number
4620 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4621 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4622 if (number == null) {
4623 editor.remove(numberPrefKey);
4624 editor.remove(subscriberPrefKey);
4625 } else {
4626 editor.putString(numberPrefKey, number);
4627 editor.putString(subscriberPrefKey, subscriberId);
4628 }
4629
4630 editor.commit();
4631 return true;
4632 } finally {
4633 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004634 }
Derek Tan7226c842014-07-02 17:42:23 -07004635 }
4636
4637 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004638 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004639 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004640 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004641 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004642 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004643 return null;
4644 }
Derek Tan97ebb422014-09-05 16:55:38 -07004645
Malcolm Chend965c8b2018-02-28 15:00:40 -08004646 final long identity = Binder.clearCallingIdentity();
4647 try {
4648 String iccId = getIccId(subId);
4649 if (iccId != null) {
4650 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4651 if (DBG_MERGE) {
4652 log("getLine1NumberForDisplay returning "
4653 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4654 }
4655 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004656 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004657 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4658 return null;
4659 } finally {
4660 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004661 }
Derek Tan7226c842014-07-02 17:42:23 -07004662 }
4663
4664 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004665 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004666 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004667 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004668 return null;
4669 }
Derek Tan97ebb422014-09-05 16:55:38 -07004670
Malcolm Chend965c8b2018-02-28 15:00:40 -08004671 final long identity = Binder.clearCallingIdentity();
4672 try {
4673 String iccId = getIccId(subId);
4674 if (iccId != null) {
4675 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4676 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4677 }
4678 return null;
4679 } finally {
4680 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004681 }
Derek Tan7226c842014-07-02 17:42:23 -07004682 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004683
4684 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004685 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004686 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4687 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004688 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004689 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4690 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004691 return null;
4692 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004693
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004694 final long identity = Binder.clearCallingIdentity();
4695 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004696 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004697 final TelephonyManager tele = TelephonyManager.from(context);
4698 final SubscriptionManager sub = SubscriptionManager.from(context);
4699
4700 // Figure out what subscribers are currently active
4701 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4702 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4703 // the process, where TelephonyManager was instantiated.
4704 // Otherwise AppOps check will fail.
4705
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004706 final int[] subIds = sub.getActiveSubscriptionIdList();
4707 for (int subId : subIds) {
4708 activeSubscriberIds.add(tele.getSubscriberId(subId));
4709 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004710
4711 // First pass, find a number override for an active subscriber
4712 String mergeNumber = null;
4713 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4714 for (String key : prefs.keySet()) {
4715 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4716 final String subscriberId = (String) prefs.get(key);
4717 if (activeSubscriberIds.contains(subscriberId)) {
4718 final String iccId = key.substring(
4719 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4720 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4721 mergeNumber = (String) prefs.get(numberKey);
4722 if (DBG_MERGE) {
4723 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4724 + " for active subscriber " + subscriberId);
4725 }
4726 if (!TextUtils.isEmpty(mergeNumber)) {
4727 break;
4728 }
4729 }
4730 }
4731 }
4732
4733 // Shortcut when no active merged subscribers
4734 if (TextUtils.isEmpty(mergeNumber)) {
4735 return null;
4736 }
4737
4738 // Second pass, find all subscribers under that line override
4739 final ArraySet<String> result = new ArraySet<>();
4740 for (String key : prefs.keySet()) {
4741 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4742 final String number = (String) prefs.get(key);
4743 if (mergeNumber.equals(number)) {
4744 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4745 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4746 final String subscriberId = (String) prefs.get(subscriberKey);
4747 if (!TextUtils.isEmpty(subscriberId)) {
4748 result.add(subscriberId);
4749 }
4750 }
4751 }
4752 }
4753
4754 final String[] resultArray = result.toArray(new String[result.size()]);
4755 Arrays.sort(resultArray);
4756 if (DBG_MERGE) {
4757 Slog.d(LOG_TAG,
4758 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4759 }
4760 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004761 } finally {
4762 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004763 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004764 }
4765
4766 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004767 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004768 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4769 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004770
4771 final long identity = Binder.clearCallingIdentity();
4772 try {
4773 final Phone phone = getPhone(subId);
4774 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4775 } finally {
4776 Binder.restoreCallingIdentity(identity);
4777 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004778 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004779
4780 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004781 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004782 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4783 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004784 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004785
4786 final long identity = Binder.clearCallingIdentity();
4787 try {
4788 final Phone phone = getPhone(subId);
4789 if (phone == null) {
4790 return false;
4791 }
4792 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4793 cdmaNonRoamingList);
4794 } finally {
4795 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004796 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004797 }
4798
4799 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004800 @Deprecated
4801 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4802 enforceModifyPermission();
4803
4804 int returnValue = 0;
4805 try {
vagdevie435a3e2018-08-15 16:01:53 -07004806 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004807 if(result.exception == null) {
4808 if (result.result != null) {
4809 byte[] responseData = (byte[])(result.result);
4810 if(responseData.length > oemResp.length) {
4811 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4812 responseData.length + "bytes. Buffer Size is " +
4813 oemResp.length + "bytes.");
4814 }
4815 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4816 returnValue = responseData.length;
4817 }
4818 } else {
4819 CommandException ex = (CommandException) result.exception;
4820 returnValue = ex.getCommandError().ordinal();
4821 if(returnValue > 0) returnValue *= -1;
4822 }
4823 } catch (RuntimeException e) {
4824 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4825 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4826 if(returnValue > 0) returnValue *= -1;
4827 }
4828
4829 return returnValue;
4830 }
4831
4832 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004833 public void setRadioCapability(RadioAccessFamily[] rafs) {
4834 try {
4835 ProxyController.getInstance().setRadioCapability(rafs);
4836 } catch (RuntimeException e) {
4837 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4838 }
4839 }
4840
4841 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004842 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004843 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004844 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004845 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004846 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004847 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004848 final long identity = Binder.clearCallingIdentity();
4849 try {
chen xufeeed752018-10-26 14:17:57 -07004850 TelephonyPermissions
4851 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4852 mApp, phone.getSubId(), "getRadioAccessFamily");
4853 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004854 } finally {
4855 Binder.restoreCallingIdentity(identity);
4856 }
chen xufeeed752018-10-26 14:17:57 -07004857 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004858 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004859
4860 @Override
4861 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004862 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004863 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004864
4865 final long identity = Binder.clearCallingIdentity();
4866 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004867 ImsManager.getInstance(defaultPhone.getContext(),
4868 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004869 } finally {
4870 Binder.restoreCallingIdentity(identity);
4871 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004872 }
4873
4874 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004875 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004876 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004877 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004878 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004879 return false;
4880 }
Svet Ganovb320e182015-04-16 12:30:10 -07004881
Malcolm Chend965c8b2018-02-28 15:00:40 -08004882 final long identity = Binder.clearCallingIdentity();
4883 try {
4884 // Check the user preference and the system-level IMS setting. Even if the user has
4885 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4886 // In the long run, we may instead need to check if there exists a connection service
4887 // which can support video calling.
4888 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004889 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004890 return imsManager.isVtEnabledByPlatform()
4891 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4892 && imsManager.isVtEnabledByUser();
4893 } finally {
4894 Binder.restoreCallingIdentity(identity);
4895 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004896 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004897
Andrew Leea1239f22015-03-02 17:44:07 -08004898 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004899 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4900 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4901 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4902 return false;
4903 }
4904
4905 final long identity = Binder.clearCallingIdentity();
4906 try {
4907 CarrierConfigManager configManager =
4908 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004909 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004910 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4911 } finally {
4912 Binder.restoreCallingIdentity(identity);
4913 }
Andrew Leea1239f22015-03-02 17:44:07 -08004914 }
4915
4916 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004917 public boolean isWorldPhone(int subId, String callingPackage) {
4918 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4919 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4920 return false;
4921 }
4922
4923 final long identity = Binder.clearCallingIdentity();
4924 try {
4925 CarrierConfigManager configManager =
4926 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004927 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004928 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4929 } finally {
4930 Binder.restoreCallingIdentity(identity);
4931 }
Andrew Leea1239f22015-03-02 17:44:07 -08004932 }
4933
Andrew Lee9431b832015-03-09 18:46:45 -07004934 @Override
4935 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004936 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004937 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004938 }
4939
4940 @Override
4941 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004942 final long identity = Binder.clearCallingIdentity();
4943 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004944 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004945 } finally {
4946 Binder.restoreCallingIdentity(identity);
4947 }
Andrew Lee9431b832015-03-09 18:46:45 -07004948 }
4949
Hall Liuf6668912018-10-31 17:05:23 -07004950 /**
4951 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4952 * support for the feature and device firmware support.
4953 *
4954 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4955 */
4956 @Override
4957 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004958 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004959 final Phone phone = getPhone(subscriptionId);
4960 if (phone == null) {
4961 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
4962 return false;
4963 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004964 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004965 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004966 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4967 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004968 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004969 return isCarrierSupported && isDeviceSupported;
4970 } finally {
4971 Binder.restoreCallingIdentity(identity);
4972 }
Hall Liu98187582018-01-22 19:15:32 -08004973 }
4974
Hall Liuf6668912018-10-31 17:05:23 -07004975 /**
4976 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4977 * both also support RTT.
4978 */
4979 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004980 final long identity = Binder.clearCallingIdentity();
4981 try {
Hall Liuf6668912018-10-31 17:05:23 -07004982 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004983 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004984 } finally {
4985 Binder.restoreCallingIdentity(identity);
4986 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004987 }
4988
Sanket Padawe7310cc72015-01-14 09:53:20 -08004989 /**
4990 * Returns the unique device ID of phone, for example, the IMEI for
4991 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4992 *
4993 * <p>Requires Permission:
4994 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4995 */
4996 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004997 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004998 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004999 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005000 return null;
5001 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005002 int subId = phone.getSubId();
5003 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5004 mApp, subId, callingPackage, "getDeviceId")) {
5005 return null;
5006 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005007
5008 final long identity = Binder.clearCallingIdentity();
5009 try {
5010 return phone.getDeviceId();
5011 } finally {
5012 Binder.restoreCallingIdentity(identity);
5013 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005014 }
5015
Ping Sunc67b7c22016-03-02 19:16:45 +08005016 /**
5017 * {@hide}
5018 * Returns the IMS Registration Status on a particular subid
5019 *
5020 * @param subId
5021 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005022 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005023 Phone phone = getPhone(subId);
5024 if (phone != null) {
5025 return phone.isImsRegistered();
5026 } else {
5027 return false;
5028 }
5029 }
5030
Santos Cordon7a1885b2015-02-03 11:15:19 -08005031 @Override
5032 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005033 final long identity = Binder.clearCallingIdentity();
5034 try {
5035 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5036 } finally {
5037 Binder.restoreCallingIdentity(identity);
5038 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005039 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005040
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005041 /**
5042 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005043 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005044 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005045 final long identity = Binder.clearCallingIdentity();
5046 try {
5047 Phone phone = getPhone(subId);
5048 if (phone != null) {
5049 return phone.isWifiCallingEnabled();
5050 } else {
5051 return false;
5052 }
5053 } finally {
5054 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005055 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005056 }
5057
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005058 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005059 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005060 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005061 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005062 final long identity = Binder.clearCallingIdentity();
5063 try {
5064 Phone phone = getPhone(subId);
5065 if (phone != null) {
5066 return phone.isVideoEnabled();
5067 } else {
5068 return false;
5069 }
5070 } finally {
5071 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005072 }
5073 }
5074
5075 /**
5076 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5077 * defined in {@link ImsRegistrationImplBase}.
5078 */
5079 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005080 final long identity = Binder.clearCallingIdentity();
5081 try {
5082 Phone phone = getPhone(subId);
5083 if (phone != null) {
5084 return phone.getImsRegistrationTech();
5085 } else {
5086 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5087 }
5088 } finally {
5089 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005090 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005091 }
5092
Stuart Scott8eef64f2015-04-08 15:13:54 -07005093 @Override
5094 public void factoryReset(int subId) {
5095 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005096 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5097 return;
5098 }
5099
Svet Ganovcc087f82015-05-12 20:35:54 -07005100 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005101
Svet Ganovcc087f82015-05-12 20:35:54 -07005102 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005103 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5104 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005105 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005106 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005107 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005108 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5109 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005110 }
5111 } finally {
5112 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005113 }
5114 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005115
5116 @Override
5117 public String getLocaleFromDefaultSim() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005118 final long identity = Binder.clearCallingIdentity();
5119 try {
5120 // We query all subscriptions instead of just the active ones, because
5121 // this might be called early on in the provisioning flow when the
5122 // subscriptions potentially aren't active yet.
5123 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
5124 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01005125 return null;
5126 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005127
Malcolm Chend965c8b2018-02-28 15:00:40 -08005128 // This function may be called very early, say, from the setup wizard, at
5129 // which point we won't have a default subscription set. If that's the case
5130 // we just choose the first, which will be valid in "most cases".
5131 final int defaultSubId = getDefaultSubscription();
5132 SubscriptionInfo info = null;
5133 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5134 info = slist.get(0);
5135 } else {
5136 for (SubscriptionInfo item : slist) {
5137 if (item.getSubscriptionId() == defaultSubId) {
5138 info = item;
5139 break;
5140 }
5141 }
5142
5143 if (info == null) {
5144 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01005145 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005146 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005147
Malcolm Chend965c8b2018-02-28 15:00:40 -08005148 // Try and fetch the locale from the carrier properties or from the SIM language
5149 // preferences (EF-PL and EF-LI)...
5150 final int mcc = info.getMcc();
5151 final Phone defaultPhone = getPhone(info.getSubscriptionId());
5152 String simLanguage = null;
5153 if (defaultPhone != null) {
5154 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
5155 if (localeFromDefaultSim != null) {
5156 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5157 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
5158 return localeFromDefaultSim.toLanguageTag();
5159 } else {
5160 simLanguage = localeFromDefaultSim.getLanguage();
5161 }
5162 }
5163 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005164
Malcolm Chend965c8b2018-02-28 15:00:40 -08005165 // The SIM language preferences only store a language (e.g. fr = French), not an
5166 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5167 // the SIM and carrier preferences does not include a country we add the country
5168 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005169 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005170 if (mccLocale != null) {
5171 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
5172 return mccLocale.toLanguageTag();
5173 }
5174
5175 if (DBG) log("No locale found - returning null");
5176 return null;
5177 } finally {
5178 Binder.restoreCallingIdentity(identity);
5179 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005180 }
5181
5182 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005183 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005184 }
5185
Malcolm Chend965c8b2018-02-28 15:00:40 -08005186 /**
5187 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5188 */
5189 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005190 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005191 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005192
Chenjie Yu1ba97252018-01-11 18:16:20 -08005193 private final ModemActivityInfo mLastModemActivityInfo =
5194 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5195
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005196 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005197 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5198 * representing the state of the modem.
5199 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005200 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5201 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005202 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005203 */
5204 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005205 public void requestModemActivityInfo(ResultReceiver result) {
5206 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005207 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005208
5209 final long identity = Binder.clearCallingIdentity();
5210 try {
5211 ModemActivityInfo ret = null;
5212 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005213 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5214 CMD_GET_MODEM_ACTIVITY_INFO,
5215 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005216 if (isModemActivityInfoValid(info)) {
5217 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5218 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5219 mergedTxTimeMs[i] =
5220 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5221 }
5222 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5223 mLastModemActivityInfo.setSleepTimeMillis(
5224 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5225 mLastModemActivityInfo.setIdleTimeMillis(
5226 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5227 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5228 mLastModemActivityInfo.setRxTimeMillis(
5229 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5230 mLastModemActivityInfo.setEnergyUsed(
5231 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005232 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005233 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5234 mLastModemActivityInfo.getSleepTimeMillis(),
5235 mLastModemActivityInfo.getIdleTimeMillis(),
5236 mLastModemActivityInfo.getTxTimeMillis(),
5237 mLastModemActivityInfo.getRxTimeMillis(),
5238 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005239 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005240 Bundle bundle = new Bundle();
5241 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5242 result.send(0, bundle);
5243 } finally {
5244 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005245 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005246 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005247
Siddharth Rayf5d29552018-06-17 15:02:38 -07005248 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5249 // less than total activity duration.
5250 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5251 if (info == null) {
5252 return false;
5253 }
5254 int activityDurationMs =
5255 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5256 int totalTxTimeMs = 0;
5257 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5258 totalTxTimeMs += info.getTxTimeMillis()[i];
5259 }
5260 return (info.isValid()
5261 && (info.getSleepTimeMillis() <= activityDurationMs)
5262 && (info.getIdleTimeMillis() <= activityDurationMs)
5263 && (info.getRxTimeMillis() <= activityDurationMs)
5264 && (totalTxTimeMs <= activityDurationMs));
5265 }
5266
Jack Yu85bd38a2015-11-09 11:34:32 -08005267 /**
5268 * {@hide}
5269 * Returns the service state information on specified subscription.
5270 */
5271 @Override
5272 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005273 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005274 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005275 return null;
5276 }
5277
Malcolm Chend965c8b2018-02-28 15:00:40 -08005278 final long identity = Binder.clearCallingIdentity();
5279 try {
5280 final Phone phone = getPhone(subId);
5281 if (phone == null) {
5282 return null;
5283 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005284
Malcolm Chend965c8b2018-02-28 15:00:40 -08005285 return phone.getServiceState();
5286 } finally {
5287 Binder.restoreCallingIdentity(identity);
5288 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005289 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005290
5291 /**
5292 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5293 *
5294 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5295 * voicemail ringtone.
5296 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5297 * PhoneAccount.
5298 */
5299 @Override
5300 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005301 final long identity = Binder.clearCallingIdentity();
5302 try {
5303 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5304 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005305 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005306 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005307
Malcolm Chend965c8b2018-02-28 15:00:40 -08005308 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5309 } finally {
5310 Binder.restoreCallingIdentity(identity);
5311 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005312 }
5313
5314 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005315 * Sets the per-account voicemail ringtone.
5316 *
5317 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5318 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5319 *
5320 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5321 * voicemail ringtone.
5322 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5323 * PhoneAccount.
5324 */
5325 @Override
5326 public void setVoicemailRingtoneUri(String callingPackage,
5327 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005328 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005329 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5330 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005331 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005332 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5333 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5334 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005335 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005336
5337 final long identity = Binder.clearCallingIdentity();
5338 try {
5339 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5340 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005341 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005342 }
5343 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5344 } finally {
5345 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005346 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005347 }
5348
5349 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005350 * Returns whether vibration is set for voicemail notification in Phone settings.
5351 *
5352 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5353 * voicemail vibration setting.
5354 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5355 */
5356 @Override
5357 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005358 final long identity = Binder.clearCallingIdentity();
5359 try {
5360 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5361 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005362 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005363 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005364
Malcolm Chend965c8b2018-02-28 15:00:40 -08005365 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5366 } finally {
5367 Binder.restoreCallingIdentity(identity);
5368 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005369 }
5370
Youhan Wange64578a2016-05-02 15:32:42 -07005371 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005372 * Sets the per-account voicemail vibration.
5373 *
5374 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5375 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5376 *
5377 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5378 * voicemail vibration setting.
5379 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5380 * specific PhoneAccount.
5381 */
5382 @Override
5383 public void setVoicemailVibrationEnabled(String callingPackage,
5384 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005385 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005386 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5387 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005388 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005389 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5390 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5391 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005392 }
5393
Malcolm Chend965c8b2018-02-28 15:00:40 -08005394 final long identity = Binder.clearCallingIdentity();
5395 try {
5396 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5397 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005398 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005399 }
5400 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5401 } finally {
5402 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005403 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005404 }
5405
5406 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005407 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5408 *
5409 * @throws SecurityException if the caller does not have the required permission
5410 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005411 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005412 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005413 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005414 }
5415
5416 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005417 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5418 * permission.
5419 *
5420 * @throws SecurityException if the caller does not have the required permission
5421 */
5422 private void enforceSendSmsPermission() {
5423 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5424 }
5425
5426 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005427 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005428 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005429 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005430 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005431 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005432 final long identity = Binder.clearCallingIdentity();
5433 try {
5434 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005435 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005436 if (componentName == null) {
5437 throw new SecurityException(
5438 "Caller not current active visual voicemail package[null]");
5439 }
5440 String vvmPackage = componentName.getPackageName();
5441 if (!callingPackage.equals(vvmPackage)) {
5442 throw new SecurityException("Caller not current active visual voicemail package["
5443 + vvmPackage + "]");
5444 }
5445 } finally {
5446 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005447 }
5448 }
5449
5450 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005451 * Return the application ID for the app type.
5452 *
5453 * @param subId the subscription ID that this request applies to.
5454 * @param appType the uicc app type.
5455 * @return Application ID for specificied app type, or null if no uicc.
5456 */
5457 @Override
5458 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005459 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005460 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005461
5462 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005463 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005464 if (phone == null) {
5465 return null;
5466 }
5467 String aid = null;
5468 try {
5469 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5470 .getApplicationByType(appType).getAid();
5471 } catch (Exception e) {
5472 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5473 }
5474 return aid;
5475 } finally {
5476 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005477 }
Youhan Wange64578a2016-05-02 15:32:42 -07005478 }
5479
Youhan Wang4001d252016-05-11 10:29:41 -07005480 /**
5481 * Return the Electronic Serial Number.
5482 *
5483 * @param subId the subscription ID that this request applies to.
5484 * @return ESN or null if error.
5485 */
5486 @Override
5487 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005488 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005489 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005490
5491 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005492 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005493 if (phone == null) {
5494 return null;
5495 }
5496 String esn = null;
5497 try {
5498 esn = phone.getEsn();
5499 } catch (Exception e) {
5500 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5501 }
5502 return esn;
5503 } finally {
5504 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005505 }
Youhan Wang4001d252016-05-11 10:29:41 -07005506 }
5507
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005508 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005509 * Return the Preferred Roaming List Version.
5510 *
5511 * @param subId the subscription ID that this request applies to.
5512 * @return PRLVersion or null if error.
5513 */
5514 @Override
5515 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005516 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005517 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005518
5519 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005520 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005521 if (phone == null) {
5522 return null;
5523 }
5524 String cdmaPrlVersion = null;
5525 try {
5526 cdmaPrlVersion = phone.getCdmaPrlVersion();
5527 } catch (Exception e) {
5528 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5529 }
5530 return cdmaPrlVersion;
5531 } finally {
5532 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005533 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005534 }
5535
5536 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005537 * Get snapshot of Telephony histograms
5538 * @return List of Telephony histograms
5539 * @hide
5540 */
5541 @Override
5542 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005543 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5544 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005545
5546 final long identity = Binder.clearCallingIdentity();
5547 try {
5548 return RIL.getTelephonyRILTimingHistograms();
5549 } finally {
5550 Binder.restoreCallingIdentity(identity);
5551 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005552 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005553
5554 /**
5555 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005556 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5557 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005558 * Require system privileges. In the future we may add this to carrier APIs.
5559 *
Michele Berionne0963c862018-11-27 18:57:59 -08005560 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005561 */
5562 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005563 @TelephonyManager.SetCarrierRestrictionResult
5564 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005565 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005566 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005567
Michele Berionne0963c862018-11-27 18:57:59 -08005568 if (carrierRestrictionRules == null) {
5569 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005570 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005571
Malcolm Chend965c8b2018-02-28 15:00:40 -08005572 final long identity = Binder.clearCallingIdentity();
5573 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005574 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005575 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005576 } finally {
5577 Binder.restoreCallingIdentity(identity);
5578 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005579 }
5580
5581 /**
5582 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005583 * Get the allowed carrier list and the excluded carrier list, including the priority between
5584 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005585 * Require system privileges. In the future we may add this to carrier APIs.
5586 *
Michele Berionne0963c862018-11-27 18:57:59 -08005587 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005588 */
5589 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005590 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005591 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005592 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005593
5594 final long identity = Binder.clearCallingIdentity();
5595 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005596 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5597 if (response instanceof CarrierRestrictionRules) {
5598 return (CarrierRestrictionRules) response;
5599 }
5600 // Response is an Exception of some kind,
5601 // which is signalled to the user as a NULL retval
5602 return null;
5603 } catch (Exception e) {
5604 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5605 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005606 } finally {
5607 Binder.restoreCallingIdentity(identity);
5608 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005609 }
5610
fionaxu59545b42016-05-25 15:53:37 -07005611 /**
5612 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5613 * @param subId the subscription ID that this action applies to.
5614 * @param enabled control enable or disable metered apns.
5615 * {@hide}
5616 */
5617 @Override
5618 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5619 enforceModifyPermission();
5620 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005621
5622 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005623 if (phone == null) {
5624 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5625 return;
5626 }
5627 try {
5628 phone.carrierActionSetMeteredApnsEnabled(enabled);
5629 } catch (Exception e) {
5630 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005631 } finally {
5632 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005633 }
5634 }
5635
5636 /**
5637 * Action set from carrier signalling broadcast receivers to enable/disable radio
5638 * @param subId the subscription ID that this action applies to.
5639 * @param enabled control enable or disable radio.
5640 * {@hide}
5641 */
5642 @Override
5643 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5644 enforceModifyPermission();
5645 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005646
5647 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005648 if (phone == null) {
5649 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5650 return;
5651 }
5652 try {
5653 phone.carrierActionSetRadioEnabled(enabled);
5654 } catch (Exception e) {
5655 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005656 } finally {
5657 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005658 }
5659 }
5660
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005661 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005662 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5663 * network status based on which carrier apps could apply actions accordingly,
5664 * enable/disable default url handler for example.
5665 *
5666 * @param subId the subscription ID that this action applies to.
5667 * @param report control start/stop reporting the default network status.
5668 * {@hide}
5669 */
5670 @Override
5671 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5672 enforceModifyPermission();
5673 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005674
5675 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005676 if (phone == null) {
5677 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5678 return;
5679 }
5680 try {
5681 phone.carrierActionReportDefaultNetworkStatus(report);
5682 } catch (Exception e) {
5683 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005684 } finally {
5685 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005686 }
5687 }
5688
5689 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005690 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5691 * bug report is being generated.
5692 */
5693 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005694 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005695 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5696 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005697 writer.println("Permission Denial: can't dump Phone from pid="
5698 + Binder.getCallingPid()
5699 + ", uid=" + Binder.getCallingUid()
5700 + "without permission "
5701 + android.Manifest.permission.DUMP);
5702 return;
5703 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005704 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005705 }
Jack Yueb89b242016-06-22 13:27:47 -07005706
Brad Ebingerdac2f002018-04-03 15:17:52 -07005707 @Override
5708 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5709 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5710 throws RemoteException {
5711 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5712 }
5713
Jack Yueb89b242016-06-22 13:27:47 -07005714 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005715 * Get aggregated video call data usage since boot.
5716 *
5717 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5718 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005719 * {@hide}
5720 */
5721 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005722 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005723 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5724 null);
5725
Malcolm Chend965c8b2018-02-28 15:00:40 -08005726 final long identity = Binder.clearCallingIdentity();
5727 try {
5728 // NetworkStatsService keeps tracking the active network interface and identity. It
5729 // records the delta with the corresponding network identity.
5730 // We just return the total video call data usage snapshot since boot.
5731 Phone phone = getPhone(subId);
5732 if (phone != null) {
5733 return phone.getVtDataUsage(perUidStats);
5734 }
5735 return null;
5736 } finally {
5737 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005738 }
Jack Yueb89b242016-06-22 13:27:47 -07005739 }
Jack Yu75ab2952016-07-08 14:29:33 -07005740
5741 /**
5742 * Policy control of data connection. Usually used when data limit is passed.
5743 * @param enabled True if enabling the data, otherwise disabling.
5744 * @param subId Subscription index
5745 * {@hide}
5746 */
5747 @Override
5748 public void setPolicyDataEnabled(boolean enabled, int subId) {
5749 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005750
5751 final long identity = Binder.clearCallingIdentity();
5752 try {
5753 Phone phone = getPhone(subId);
5754 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08005755 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005756 }
5757 } finally {
5758 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005759 }
5760 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005761
5762 /**
5763 * Get Client request stats
5764 * @return List of Client Request Stats
5765 * @hide
5766 */
5767 @Override
5768 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005769 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005770 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005771 return null;
5772 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005773 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005774
Malcolm Chend965c8b2018-02-28 15:00:40 -08005775 final long identity = Binder.clearCallingIdentity();
5776 try {
5777 if (phone != null) {
5778 return phone.getClientRequestStats();
5779 }
5780
5781 return null;
5782 } finally {
5783 Binder.restoreCallingIdentity(identity);
5784 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005785 }
5786
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005787 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005788 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005789 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005790 }
Jack Yueb4124c2017-02-16 15:32:43 -08005791
5792 /**
Grace Chen70990072017-03-24 17:21:30 -07005793 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005794 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005795 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005796 * @param state State of SIM (power down, power up, pass through)
5797 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5798 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5799 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005800 *
5801 **/
5802 @Override
Grace Chen70990072017-03-24 17:21:30 -07005803 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005804 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005805 Phone phone = PhoneFactory.getPhone(slotIndex);
5806
vagdevie435a3e2018-08-15 16:01:53 -07005807 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5808
Malcolm Chend965c8b2018-02-28 15:00:40 -08005809 final long identity = Binder.clearCallingIdentity();
5810 try {
5811 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005812 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005813 }
5814 } finally {
5815 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005816 }
5817 }
Shuo Qiandd210312017-04-12 22:11:33 +00005818
Tyler Gunn65d45c22017-06-05 11:22:26 -07005819 private boolean isUssdApiAllowed(int subId) {
5820 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005821 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005822 if (configManager == null) {
5823 return false;
5824 }
5825 PersistableBundle pb = configManager.getConfigForSubId(subId);
5826 if (pb == null) {
5827 return false;
5828 }
5829 return pb.getBoolean(
5830 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5831 }
5832
Shuo Qiandd210312017-04-12 22:11:33 +00005833 /**
5834 * Check if phone is in emergency callback mode
5835 * @return true if phone is in emergency callback mode
5836 * @param subId sub id
5837 */
goneil9c5f4872017-12-05 14:07:56 -08005838 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005839 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005840 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005841 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005842
5843 final long identity = Binder.clearCallingIdentity();
5844 try {
5845 if (phone != null) {
5846 return phone.isInEcm();
5847 } else {
5848 return false;
5849 }
5850 } finally {
5851 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005852 }
5853 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005854
5855 /**
5856 * Get the current signal strength information for the given subscription.
5857 * Because this information is not updated when the device is in a low power state
5858 * it should not be relied-upon to be current.
5859 * @param subId Subscription index
5860 * @return the most recent cached signal strength info from the modem
5861 */
5862 @Override
5863 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005864 final long identity = Binder.clearCallingIdentity();
5865 try {
5866 Phone p = getPhone(subId);
5867 if (p == null) {
5868 return null;
5869 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005870
Malcolm Chend965c8b2018-02-28 15:00:40 -08005871 return p.getSignalStrength();
5872 } finally {
5873 Binder.restoreCallingIdentity(identity);
5874 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005875 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005876
Pengquan Meng9140aec2018-08-22 14:49:57 -07005877 /**
chen xu907e5a22018-10-11 13:21:04 -07005878 * Get the current modem radio state for the given slot.
5879 * @param slotIndex slot index.
5880 * @param callingPackage the name of the package making the call.
5881 * @return the current radio power state from the modem
5882 */
5883 @Override
5884 public int getRadioPowerState(int slotIndex, String callingPackage) {
5885 Phone phone = PhoneFactory.getPhone(slotIndex);
5886 if (phone != null) {
5887 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5888 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5889 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5890 }
5891
5892 final long identity = Binder.clearCallingIdentity();
5893 try {
5894 return phone.getRadioPowerState();
5895 } finally {
5896 Binder.restoreCallingIdentity(identity);
5897 }
5898 }
5899 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5900 }
5901
5902 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005903 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5904 *
5905 * <p>Requires one of the following permissions:
5906 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5907 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5908 * privileges.
5909 *
5910 * @param subId subscription id
5911 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5912 * {@code false}.
5913 */
5914 @Override
5915 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005916 boolean isEnabled = false;
5917 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005918 try {
5919 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005920 null /* message */);
5921 Phone phone = getPhone(subId);
5922 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005923 } catch (Exception e) {
5924 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5925 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005926 } finally {
5927 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005928 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005929 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005930 }
5931
5932
5933 /**
5934 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5935 *
5936 * <p> Requires permission:
5937 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5938 * privileges.
5939 *
5940 * @param subId subscription id
5941 * @param isEnabled {@code true} means enable, {@code false} means disable.
5942 */
5943 @Override
5944 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005945 final long identity = Binder.clearCallingIdentity();
5946 try {
5947 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5948 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005949
Pengquan Meng0c05b502018-09-06 09:59:22 -07005950 Phone phone = getPhone(subId);
5951 if (phone != null) {
5952 phone.setDataRoamingEnabled(isEnabled);
5953 }
5954 } finally {
5955 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005956 }
5957 }
5958
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005959 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005960 public boolean isManualNetworkSelectionAllowed(int subId) {
5961 boolean isAllowed = true;
5962 final long identity = Binder.clearCallingIdentity();
5963 try {
5964 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5965 mApp, subId, "isManualNetworkSelectionAllowed");
5966 Phone phone = getPhone(subId);
5967 if (phone != null) {
5968 isAllowed = phone.isCspPlmnEnabled();
5969 }
5970 } finally {
5971 Binder.restoreCallingIdentity(identity);
5972 }
5973 return isAllowed;
5974 }
5975
5976 @Override
Jordan Liu5aa07002018-12-18 15:44:48 -08005977 public UiccCardInfo[] getUiccCardsInfo() {
5978 enforceReadPrivilegedPermission("getUiccCardsInfo");
5979
5980 final long identity = Binder.clearCallingIdentity();
5981 try {
5982 ArrayList<UiccCardInfo> cards = UiccController.getInstance().getAllUiccCardInfos();
5983 return cards.toArray(new UiccCardInfo[cards.size()]);
5984 } finally {
5985 Binder.restoreCallingIdentity(identity);
5986 }
5987 }
5988
5989 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005990 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005991 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005992
Malcolm Chend965c8b2018-02-28 15:00:40 -08005993 final long identity = Binder.clearCallingIdentity();
5994 try {
5995 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5996 if (slots == null) {
5997 Rlog.i(LOG_TAG, "slots is null.");
5998 return null;
5999 }
6000
6001 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6002 for (int i = 0; i < slots.length; i++) {
6003 UiccSlot slot = slots[i];
6004 if (slot == null) {
6005 continue;
6006 }
6007
6008 String cardId;
6009 UiccCard card = slot.getUiccCard();
6010 if (card != null) {
6011 cardId = card.getCardId();
6012 } else {
6013 cardId = slot.getIccId();
6014 }
6015
6016 int cardState = 0;
6017 switch (slot.getCardState()) {
6018 case CARDSTATE_ABSENT:
6019 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6020 break;
6021 case CARDSTATE_PRESENT:
6022 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6023 break;
6024 case CARDSTATE_ERROR:
6025 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6026 break;
6027 case CARDSTATE_RESTRICTED:
6028 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6029 break;
6030 default:
6031 break;
6032
6033 }
6034
6035 infos[i] = new UiccSlotInfo(
6036 slot.isActive(),
6037 slot.isEuicc(),
6038 cardId,
6039 cardState,
6040 slot.getPhoneId(),
6041 slot.isExtendedApduSupported());
6042 }
6043 return infos;
6044 } finally {
6045 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006046 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006047 }
6048
6049 @Override
6050 public boolean switchSlots(int[] physicalSlots) {
6051 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006052
6053 final long identity = Binder.clearCallingIdentity();
6054 try {
6055 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6056 } finally {
6057 Binder.restoreCallingIdentity(identity);
6058 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006059 }
Jack Yu4c988042018-02-27 15:30:01 -08006060
6061 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006062 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
6063 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6064 mApp, subId, callingPackage, "getCardIdForDefaultEuicc")) {
6065 return TelephonyManager.INVALID_CARD_ID;
6066 }
6067
6068 final long identity = Binder.clearCallingIdentity();
6069 try {
6070 return UiccController.getInstance().getCardIdForDefaultEuicc();
6071 } finally {
6072 Binder.restoreCallingIdentity(identity);
6073 }
6074 }
6075
6076 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006077 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6078 enforceModifyPermission();
6079 final Phone phone = getPhone(subId);
6080 if (phone == null) {
6081 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6082 return;
6083 }
6084
Malcolm Chend965c8b2018-02-28 15:00:40 -08006085 final long identity = Binder.clearCallingIdentity();
6086 try {
6087 phone.setRadioIndicationUpdateMode(filters, mode);
6088 } finally {
6089 Binder.restoreCallingIdentity(identity);
6090 }
Jack Yu4c988042018-02-27 15:30:01 -08006091 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006092
6093 /**
goneil47ffb6e2018-04-06 15:40:58 -07006094 * A test API to reload the UICC profile.
6095 *
6096 * <p>Requires that the calling app has permission
6097 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6098 * @hide
6099 */
6100 @Override
6101 public void refreshUiccProfile(int subId) {
6102 enforceModifyPermission();
6103
6104 final long identity = Binder.clearCallingIdentity();
6105 try {
6106 Phone phone = getPhone(subId);
6107 if (phone == null) {
6108 return;
6109 }
6110 UiccCard uiccCard = phone.getUiccCard();
6111 if (uiccCard == null) {
6112 return;
6113 }
6114 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6115 if (uiccProfile == null) {
6116 return;
6117 }
6118 uiccProfile.refresh();
6119 } finally {
6120 Binder.restoreCallingIdentity(identity);
6121 }
6122 }
6123
6124 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006125 * Returns false if the mobile data is disabled by default, otherwise return true.
6126 */
6127 private boolean getDefaultDataEnabled() {
6128 return "true".equalsIgnoreCase(
6129 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6130 }
6131
6132 /**
6133 * Returns true if the data roaming is enabled by default, i.e the system property
6134 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6135 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6136 */
6137 private boolean getDefaultDataRoamingEnabled(int subId) {
6138 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006139 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006140 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6141 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6142 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6143 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6144 return isDataRoamingEnabled;
6145 }
6146
6147 /**
6148 * Returns the default network type for the given {@code subId}, if the default network type is
6149 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6150 */
6151 private int getDefaultNetworkType(int subId) {
6152 return Integer.parseInt(
6153 TelephonyManager.getTelephonyProperty(
6154 mSubscriptionController.getPhoneId(subId),
6155 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6156 String.valueOf(Phone.PREFERRED_NT_MODE)));
6157 }
fionaxua13278b2018-03-21 00:08:13 -07006158
6159 @Override
6160 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6161 gid1, String gid2, String plmn, String spn) {
6162 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006163
6164 final long identity = Binder.clearCallingIdentity();
6165 try {
6166 final Phone phone = getPhone(subId);
6167 if (phone == null) {
6168 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6169 return;
6170 }
6171 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6172 } finally {
6173 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006174 }
fionaxua13278b2018-03-21 00:08:13 -07006175 }
6176
6177 @Override
6178 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006179 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006180
6181 final long identity = Binder.clearCallingIdentity();
6182 try {
6183 final Phone phone = getPhone(subId);
6184 if (phone == null) {
6185 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6186 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6187 }
6188 return phone.getCarrierIdListVersion();
6189 } finally {
6190 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006191 }
fionaxua13278b2018-03-21 00:08:13 -07006192 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006193
6194 @Override
6195 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6196 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6197 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6198 return -1;
6199 }
6200
6201 final long identity = Binder.clearCallingIdentity();
6202 try {
6203 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6204 } finally {
6205 Binder.restoreCallingIdentity(identity);
6206 }
6207 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006208
6209 @Override
6210 public int getCdmaRoamingMode(int subId) {
6211 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6212 mApp, subId, "getCdmaRoamingMode");
6213
6214 final long identity = Binder.clearCallingIdentity();
6215 try {
6216 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6217 } finally {
6218 Binder.restoreCallingIdentity(identity);
6219 }
6220 }
6221
6222 @Override
6223 public boolean setCdmaRoamingMode(int subId, int mode) {
6224 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6225 mApp, subId, "setCdmaRoamingMode");
6226
6227 final long identity = Binder.clearCallingIdentity();
6228 try {
6229 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6230 } finally {
6231 Binder.restoreCallingIdentity(identity);
6232 }
6233 }
6234
6235 @Override
6236 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6237 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6238 mApp, subId, "setCdmaSubscriptionMode");
6239
6240 final long identity = Binder.clearCallingIdentity();
6241 try {
6242 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6243 } finally {
6244 Binder.restoreCallingIdentity(identity);
6245 }
6246 }
chen xu7ee67862018-10-30 22:27:10 -07006247
sqian2fff4a32018-11-05 14:18:37 -08006248 private void ensureUserRunning(int userId) {
6249 if (!mUserManager.isUserRunning(userId)) {
6250 throw new IllegalStateException("User " + userId + " does not exist or not running");
6251 }
6252 }
6253
6254 /**
6255 * Returns a list of SMS apps on a given user.
6256 *
6257 * Only the shell user (UID 2000 or 0) can call it.
6258 * Target user must be running.
6259 */
6260 @Override
6261 public String[] getSmsApps(int userId) {
6262 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6263 ensureUserRunning(userId);
6264
6265 final Collection<SmsApplicationData> apps =
6266 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6267
6268 String[] ret = new String[apps.size()];
6269 int i = 0;
6270 for (SmsApplicationData app : apps) {
6271 ret[i++] = app.mPackageName;
6272 }
6273 return ret;
6274 }
6275
6276 /**
6277 * Returns the default SMS app package name on a given user.
6278 *
6279 * Only the shell user (UID 2000 or 0) can call it.
6280 * Target user must be running.
6281 */
6282 @Override
6283 public String getDefaultSmsApp(int userId) {
6284 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6285 ensureUserRunning(userId);
6286
6287 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6288 /* updateIfNeeded= */ true, userId);
6289 return cn == null ? null : cn.getPackageName();
6290 }
6291
6292 /**
6293 * Set a package as the default SMS app on a given user.
6294 *
6295 * Only the shell user (UID 2000 or 0) can call it.
6296 * Target user must be running.
6297 */
6298 @Override
6299 public void setDefaultSmsApp(int userId, String packageName) {
6300 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6301 ensureUserRunning(userId);
6302
6303 boolean found = false;
6304 for (String pkg : getSmsApps(userId)) {
6305 if (TextUtils.equals(packageName, pkg)) {
6306 found = true;
6307 break;
6308 }
6309 }
6310 if (!found) {
6311 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6312 }
6313
6314 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6315 }
6316
chen xu7ee67862018-10-30 22:27:10 -07006317 @Override
sqian04b86072018-11-07 14:02:21 -08006318 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
6319 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006320 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6321 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
6322 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6323 }
6324 final long identity = Binder.clearCallingIdentity();
6325 try {
sqian991b35e2018-12-12 16:48:18 -08006326 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6327 for (Phone phone: PhoneFactory.getPhones()) {
6328 if (phone.getEmergencyNumberTracker() != null
6329 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6330 emergencyNumberListInternal.put(
6331 phone.getSubId(),
6332 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6333 }
sqian03bca152018-12-05 18:48:28 -08006334 }
sqian991b35e2018-12-12 16:48:18 -08006335 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006336 } finally {
6337 Binder.restoreCallingIdentity(identity);
6338 }
sqian04b86072018-11-07 14:02:21 -08006339 }
6340
6341 @Override
sqian03bca152018-12-05 18:48:28 -08006342 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
6343 final Phone defaultPhone = getDefaultPhone();
6344 if (!exactMatch) {
6345 TelephonyPermissions
6346 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6347 mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
6348 }
6349 final long identity = Binder.clearCallingIdentity();
6350 try {
sqian991b35e2018-12-12 16:48:18 -08006351 for (Phone phone: PhoneFactory.getPhones()) {
6352 if (phone.getEmergencyNumberTracker() != null
6353 && phone.getEmergencyNumberTracker() != null) {
6354 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6355 number, exactMatch)) {
6356 return true;
sqian03bca152018-12-05 18:48:28 -08006357 }
6358 }
sqian03bca152018-12-05 18:48:28 -08006359 }
6360 return false;
6361 } finally {
6362 Binder.restoreCallingIdentity(identity);
6363 }
6364 }
6365
sqian04b86072018-11-07 14:02:21 -08006366 @Override
chen xu7ee67862018-10-30 22:27:10 -07006367 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6368 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6369 Phone phone = getPhone(subId);
6370 if (phone == null) {
6371 return null;
6372 }
6373 final long identity = Binder.clearCallingIdentity();
6374 try {
6375 UiccProfile profile = UiccController.getInstance()
6376 .getUiccProfileForPhone(phone.getPhoneId());
6377 if (profile != null) {
6378 return profile.getCertsFromCarrierPrivilegeAccessRules();
6379 }
6380 } finally {
6381 Binder.restoreCallingIdentity(identity);
6382 }
6383 return null;
6384 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006385
6386 /**
6387 * Enable or disable a modem stack.
6388 */
6389 @Override
6390 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6391 enforceModifyPermission();
6392
6393 final long identity = Binder.clearCallingIdentity();
6394 try {
6395 Phone phone = PhoneFactory.getPhone(slotIndex);
6396 if (phone == null) {
6397 return false;
6398 } else {
6399 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6400 }
6401 } finally {
6402 Binder.restoreCallingIdentity(identity);
6403 }
6404 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006405}