blob: a3b30790e8f3c5753d4330561b9c9a87241d7c6b [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
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
changbetty363e8ac2019-12-06 18:16:37 +080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070038import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.net.Uri;
40import android.os.AsyncResult;
41import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080042import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.os.Bundle;
44import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070045import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.Looper;
47import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070048import android.os.Messenger;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080051import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070052import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070055import android.os.ShellCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070060import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080061import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070062import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090063import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080064import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080065import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070066import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070067import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080071import android.telephony.CellIdentityCdma;
72import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070074import android.telephony.CellInfoGsm;
75import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070076import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070077import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070078import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080079import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070080import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070082import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080083import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080084import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.RadioAccessSpecifier;
Meng Wang17815702020-01-08 18:00:39 -080087import com.android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080089import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080090import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080091import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070092import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080095import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000096import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070097import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebinger774ba362019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsMmTelFeature;
108import android.telephony.ims.aidl.IImsRcsFeature;
109import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700110import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800113import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800114import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800115import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800119import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800120import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800121
Andrew Lee312e8172014-10-23 17:01:36 -0700122import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800123import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700124import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700125import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700126import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800127import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700128import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700129import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800131import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700132import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800133import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800135import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700136import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700137import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700138import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700140import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800141import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700142import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700143import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700144import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700145import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700146import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700147import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700148import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700149import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800150import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800151import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700152import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800153import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700154import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800155import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700156import com.android.internal.telephony.imsphone.ImsPhone;
157import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800158import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900159import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700160import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800161import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700162import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800163import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700164import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800165import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700166import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800167import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000168import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800169import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700170import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800171import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700172import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700173import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800174import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700175import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700176import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800177
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700178import java.io.FileDescriptor;
179import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700180import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800181import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800182import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800183import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800184import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100185import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800186import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700187import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700189
190/**
191 * Implementation of the ITelephony interface.
192 */
Santos Cordon117fee72014-05-16 17:56:12 -0700193public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194 private static final String LOG_TAG = "PhoneInterfaceManager";
195 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
196 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800197 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198
199 // Message codes used with mMainThreadHandler
200 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700201 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
202 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700203 private static final int CMD_OPEN_CHANNEL = 9;
204 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
205 private static final int CMD_CLOSE_CHANNEL = 11;
206 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800207 private static final int CMD_NV_READ_ITEM = 13;
208 private static final int EVENT_NV_READ_ITEM_DONE = 14;
209 private static final int CMD_NV_WRITE_ITEM = 15;
210 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
211 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
212 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700213 private static final int CMD_RESET_MODEM_CONFIG = 19;
214 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800215 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
216 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
217 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
218 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800219 private static final int CMD_SEND_ENVELOPE = 25;
220 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000221 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
222 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700223 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
224 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
225 private static final int CMD_EXCHANGE_SIM_IO = 31;
226 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800227 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
228 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700229 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
230 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700231 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
232 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700233 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
234 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
235 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
236 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700237 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
238 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
239 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
240 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700241 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800242 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
243 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000244 private static final int CMD_SWITCH_SLOTS = 50;
245 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700246 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
247 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
248 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
249 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
250 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
251 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
252 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
253 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700254 private static final int CMD_GET_ALL_CELL_INFO = 60;
255 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
256 private static final int CMD_GET_CELL_LOCATION = 62;
257 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700258 private static final int CMD_MODEM_REBOOT = 64;
259 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700260 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
261 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800262 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
263 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700264 private static final int CMD_GET_MODEM_STATUS = 70;
265 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700266 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
267 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700268 private static final int CMD_ERASE_MODEM_CONFIG = 74;
269 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700270
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800271 // Parameters of select command.
272 private static final int SELECT_COMMAND = 0xA4;
273 private static final int SELECT_P1 = 0x04;
274 private static final int SELECT_P2 = 0;
275 private static final int SELECT_P3 = 0x10;
276
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700277 /** The singleton instance. */
278 private static PhoneInterfaceManager sInstance;
279
Wink Saville3ab207e2014-11-20 13:07:20 -0800280 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800281 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800282 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700283 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800284 private AppOpsManager mAppOps;
285 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800286 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800287 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700288 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700289
Derek Tan97ebb422014-09-05 16:55:38 -0700290 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
291 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800292 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800293 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700294
Michelecea4cf22018-12-21 15:00:11 -0800295 // String to store multi SIM allowed
296 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
297
Derek Tan740e1672017-06-27 14:56:27 -0700298 // The AID of ISD-R.
299 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
300
yinxub1bed742017-04-17 11:45:04 -0700301 private NetworkScanRequestTracker mNetworkScanRequestTracker;
302
David Kelly5e06a7f2018-03-12 14:10:59 +0000303 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
304 private static final int MANUFACTURER_CODE_LENGTH = 8;
305
Derek Tan89e89d42014-07-08 17:00:10 -0700306 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700307 * Experiment flag to enable erase modem config on reset network, default value is false
308 */
309 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
310 "reset_network_erase_modem_config_enabled";
311
312 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700313 * A request object to use for transmitting data to an ICC.
314 */
315 private static final class IccAPDUArgument {
316 public int channel, cla, command, p1, p2, p3;
317 public String data;
318
319 public IccAPDUArgument(int channel, int cla, int command,
320 int p1, int p2, int p3, String data) {
321 this.channel = channel;
322 this.cla = cla;
323 this.command = command;
324 this.p1 = p1;
325 this.p2 = p2;
326 this.p3 = p3;
327 this.data = data;
328 }
329 }
330
331 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700332 * A request object to use for transmitting data to an ICC.
333 */
334 private static final class ManualNetworkSelectionArgument {
335 public OperatorInfo operatorInfo;
336 public boolean persistSelection;
337
338 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
339 this.operatorInfo = operatorInfo;
340 this.persistSelection = persistSelection;
341 }
342 }
343
344 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700345 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
346 * request after sending. The main thread will notify the request when it is complete.
347 */
348 private static final class MainThreadRequest {
349 /** The argument to use for the request */
350 public Object argument;
351 /** The result of the request that is run on the main thread */
352 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800353 // The subscriber id that this request applies to. Defaults to
354 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
355 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356
Nathan Harold92bed182018-10-12 18:16:49 -0700357 // In cases where subId is unavailable, the caller needs to specify the phone.
358 public Phone phone;
359
vagdeviaf9a5b92018-08-15 16:01:53 -0700360 public WorkSource workSource;
361
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362 public MainThreadRequest(Object argument) {
363 this.argument = argument;
364 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800365
Nathan Harold92bed182018-10-12 18:16:49 -0700366 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
367 this.argument = argument;
368 if (phone != null) {
369 this.phone = phone;
370 }
371 this.workSource = workSource;
372 }
373
vagdeviaf9a5b92018-08-15 16:01:53 -0700374 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800375 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800376 if (subId != null) {
377 this.subId = subId;
378 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700379 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800380 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 }
382
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800383 private static final class IncomingThirdPartyCallArgs {
384 public final ComponentName component;
385 public final String callId;
386 public final String callerDisplayName;
387
388 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
389 String callerDisplayName) {
390 this.component = component;
391 this.callId = callId;
392 this.callerDisplayName = callerDisplayName;
393 }
394 }
395
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700396 /**
397 * A handler that processes messages on the main thread in the phone process. Since many
398 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
399 * inbound binder threads to the main thread in the phone process. The Binder thread
400 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
401 * on, which will be notified when the operation completes and will contain the result of the
402 * request.
403 *
404 * <p>If a MainThreadRequest object is provided in the msg.obj field,
405 * note that request.result must be set to something non-null for the calling thread to
406 * unblock.
407 */
408 private final class MainThreadHandler extends Handler {
409 @Override
410 public void handleMessage(Message msg) {
411 MainThreadRequest request;
412 Message onCompleted;
413 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800414 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700415 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800416 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417
418 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700419 case CMD_HANDLE_USSD_REQUEST: {
420 request = (MainThreadRequest) msg.obj;
421 final Phone phone = getPhoneFromRequest(request);
422 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
423 String ussdRequest = ussdObject.first;
424 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700425
Pengquan Menga1bb6272018-09-06 09:59:22 -0700426 if (!isUssdApiAllowed(request.subId)) {
427 // Carrier does not support use of this API, return failure.
428 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
429 UssdResponse response = new UssdResponse(ussdRequest, null);
430 Bundle returnData = new Bundle();
431 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
432 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700433
Pengquan Menga1bb6272018-09-06 09:59:22 -0700434 request.result = true;
435 notifyRequester(request);
436 return;
437 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700438
Pengquan Menga1bb6272018-09-06 09:59:22 -0700439 try {
440 request.result = phone != null
441 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
442 } catch (CallStateException cse) {
443 request.result = false;
444 }
445 // Wake up the requesting thread
446 notifyRequester(request);
447 break;
pkanwar32d516d2016-10-14 19:37:38 -0700448 }
449
Yorke Lee716f67e2015-06-17 15:39:16 -0700450 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700451 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700452 final Phone phone = getPhoneFromRequest(request);
453 request.result = phone != null ?
454 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
455 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700456 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700457 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700458 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700459 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700460
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700461 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700462 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700463 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800464 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700465 if (uiccCard == null) {
466 loge("iccTransmitApduLogicalChannel: No UICC");
467 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700468 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700469 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700470 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
471 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700472 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700473 iccArgument.channel, iccArgument.cla, iccArgument.command,
474 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700475 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700476 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700477 break;
478
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700479 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700480 ar = (AsyncResult) msg.obj;
481 request = (MainThreadRequest) ar.userObj;
482 if (ar.exception == null && ar.result != null) {
483 request.result = ar.result;
484 } else {
485 request.result = new IccIoResult(0x6F, 0, (byte[])null);
486 if (ar.result == null) {
487 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800488 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700489 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800490 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700491 } else {
492 loge("iccTransmitApduLogicalChannel: Unknown exception");
493 }
494 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700495 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700496 break;
497
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
499 request = (MainThreadRequest) msg.obj;
500 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800501 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700502 if (uiccCard == null) {
503 loge("iccTransmitApduBasicChannel: No UICC");
504 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700505 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700506 } else {
507 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
508 request);
509 uiccCard.iccTransmitApduBasicChannel(
510 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
511 iccArgument.p3, iccArgument.data, onCompleted);
512 }
513 break;
514
515 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
516 ar = (AsyncResult) msg.obj;
517 request = (MainThreadRequest) ar.userObj;
518 if (ar.exception == null && ar.result != null) {
519 request.result = ar.result;
520 } else {
521 request.result = new IccIoResult(0x6F, 0, (byte[])null);
522 if (ar.result == null) {
523 loge("iccTransmitApduBasicChannel: Empty response");
524 } else if (ar.exception instanceof CommandException) {
525 loge("iccTransmitApduBasicChannel: CommandException: " +
526 ar.exception);
527 } else {
528 loge("iccTransmitApduBasicChannel: Unknown exception");
529 }
530 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700531 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700532 break;
533
534 case CMD_EXCHANGE_SIM_IO:
535 request = (MainThreadRequest) msg.obj;
536 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800537 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700538 if (uiccCard == null) {
539 loge("iccExchangeSimIO: No UICC");
540 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700541 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700542 } else {
543 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
544 request);
545 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
546 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
547 iccArgument.data, onCompleted);
548 }
549 break;
550
551 case EVENT_EXCHANGE_SIM_IO_DONE:
552 ar = (AsyncResult) msg.obj;
553 request = (MainThreadRequest) ar.userObj;
554 if (ar.exception == null && ar.result != null) {
555 request.result = ar.result;
556 } else {
557 request.result = new IccIoResult(0x6f, 0, (byte[])null);
558 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700559 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700560 break;
561
Derek Tan4d5e5c12014-02-04 11:54:58 -0800562 case CMD_SEND_ENVELOPE:
563 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800564 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700565 if (uiccCard == null) {
566 loge("sendEnvelopeWithStatus: No UICC");
567 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700568 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700569 } else {
570 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
571 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
572 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800573 break;
574
575 case EVENT_SEND_ENVELOPE_DONE:
576 ar = (AsyncResult) msg.obj;
577 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700578 if (ar.exception == null && ar.result != null) {
579 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800580 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700581 request.result = new IccIoResult(0x6F, 0, (byte[])null);
582 if (ar.result == null) {
583 loge("sendEnvelopeWithStatus: Empty response");
584 } else if (ar.exception instanceof CommandException) {
585 loge("sendEnvelopeWithStatus: CommandException: " +
586 ar.exception);
587 } else {
588 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
589 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800590 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700591 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800592 break;
593
Shishir Agrawal566b7612013-10-28 14:41:00 -0700594 case CMD_OPEN_CHANNEL:
595 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800596 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800597 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700598 if (uiccCard == null) {
599 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800600 request.result = new IccOpenLogicalChannelResponse(-1,
601 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700602 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700603 } else {
604 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800605 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
606 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700607 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 break;
609
610 case EVENT_OPEN_CHANNEL_DONE:
611 ar = (AsyncResult) msg.obj;
612 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700613 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700615 int[] result = (int[]) ar.result;
616 int channelId = result[0];
617 byte[] selectResponse = null;
618 if (result.length > 1) {
619 selectResponse = new byte[result.length - 1];
620 for (int i = 1; i < result.length; ++i) {
621 selectResponse[i - 1] = (byte) result[i];
622 }
623 }
624 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700625 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 if (ar.result == null) {
628 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700629 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 if (ar.exception != null) {
631 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
632 }
633
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700634 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700635 if (ar.exception instanceof CommandException) {
636 CommandException.Error error =
637 ((CommandException) (ar.exception)).getCommandError();
638 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700639 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700640 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700641 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700642 }
643 }
644 openChannelResp = new IccOpenLogicalChannelResponse(
645 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700647 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700648 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 break;
650
651 case CMD_CLOSE_CHANNEL:
652 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800653 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700654 if (uiccCard == null) {
655 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900656 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700657 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700658 } else {
659 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
660 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
661 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 break;
663
664 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800665 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
666 break;
667
668 case CMD_NV_READ_ITEM:
669 request = (MainThreadRequest) msg.obj;
670 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800671 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
672 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800673 break;
674
675 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 ar = (AsyncResult) msg.obj;
677 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800678 if (ar.exception == null && ar.result != null) {
679 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800681 request.result = "";
682 if (ar.result == null) {
683 loge("nvReadItem: Empty response");
684 } else if (ar.exception instanceof CommandException) {
685 loge("nvReadItem: CommandException: " +
686 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800688 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 }
690 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700691 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 break;
693
Jake Hambye994d462014-02-03 13:10:13 -0800694 case CMD_NV_WRITE_ITEM:
695 request = (MainThreadRequest) msg.obj;
696 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
697 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800698 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700699 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800700 break;
701
702 case EVENT_NV_WRITE_ITEM_DONE:
703 handleNullReturnEvent(msg, "nvWriteItem");
704 break;
705
706 case CMD_NV_WRITE_CDMA_PRL:
707 request = (MainThreadRequest) msg.obj;
708 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800709 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800710 break;
711
712 case EVENT_NV_WRITE_CDMA_PRL_DONE:
713 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
714 break;
715
chen xu6dac5ab2018-10-26 17:39:23 -0700716 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800717 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700718 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800719 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800720 break;
721
chen xu6dac5ab2018-10-26 17:39:23 -0700722 case EVENT_RESET_MODEM_CONFIG_DONE:
723 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800724 break;
725
Jake Hamby7c27be32014-03-03 13:25:59 -0800726 case CMD_GET_PREFERRED_NETWORK_TYPE:
727 request = (MainThreadRequest) msg.obj;
728 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700729 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800730 break;
731
732 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
733 ar = (AsyncResult) msg.obj;
734 request = (MainThreadRequest) ar.userObj;
735 if (ar.exception == null && ar.result != null) {
736 request.result = ar.result; // Integer
737 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800738 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800739 if (ar.result == null) {
740 loge("getPreferredNetworkType: Empty response");
741 } else if (ar.exception instanceof CommandException) {
742 loge("getPreferredNetworkType: CommandException: " +
743 ar.exception);
744 } else {
745 loge("getPreferredNetworkType: Unknown exception");
746 }
747 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700748 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800749 break;
750
751 case CMD_SET_PREFERRED_NETWORK_TYPE:
752 request = (MainThreadRequest) msg.obj;
753 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
754 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700755 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800756 break;
757
758 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
759 handleNullReturnEvent(msg, "setPreferredNetworkType");
760 break;
761
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000762 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
763 request = (MainThreadRequest)msg.obj;
764 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800765 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000766 break;
767
768 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
769 ar = (AsyncResult)msg.obj;
770 request = (MainThreadRequest)ar.userObj;
771 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700772 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000773 break;
774
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800775 case CMD_SET_VOICEMAIL_NUMBER:
776 request = (MainThreadRequest) msg.obj;
777 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
778 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800779 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
780 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800781 break;
782
783 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
784 handleNullReturnEvent(msg, "setVoicemailNumber");
785 break;
786
Stuart Scott54788802015-03-30 13:18:01 -0700787 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
788 request = (MainThreadRequest) msg.obj;
789 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
790 request);
791 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
792 break;
793
794 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
795 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
796 break;
797
Shishir Agrawal302c8692015-06-19 13:49:39 -0700798 case CMD_PERFORM_NETWORK_SCAN:
799 request = (MainThreadRequest) msg.obj;
800 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
801 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
802 break;
803
804 case EVENT_PERFORM_NETWORK_SCAN_DONE:
805 ar = (AsyncResult) msg.obj;
806 request = (MainThreadRequest) ar.userObj;
807 CellNetworkScanResult cellScanResult;
808 if (ar.exception == null && ar.result != null) {
809 cellScanResult = new CellNetworkScanResult(
810 CellNetworkScanResult.STATUS_SUCCESS,
811 (List<OperatorInfo>) ar.result);
812 } else {
813 if (ar.result == null) {
814 loge("getCellNetworkScanResults: Empty response");
815 }
816 if (ar.exception != null) {
817 loge("getCellNetworkScanResults: Exception: " + ar.exception);
818 }
819 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
820 if (ar.exception instanceof CommandException) {
821 CommandException.Error error =
822 ((CommandException) (ar.exception)).getCommandError();
823 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
824 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
825 } else if (error == CommandException.Error.GENERIC_FAILURE) {
826 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
827 }
828 }
829 cellScanResult = new CellNetworkScanResult(errorCode, null);
830 }
831 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700832 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700833 break;
834
835 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
836 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700837 ManualNetworkSelectionArgument selArg =
838 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700839 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
840 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700841 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
842 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700843 break;
844
845 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700846 ar = (AsyncResult) msg.obj;
847 request = (MainThreadRequest) ar.userObj;
848 if (ar.exception == null) {
849 request.result = true;
850 } else {
851 request.result = false;
852 loge("setNetworkSelectionModeManual " + ar.exception);
853 }
854 notifyRequester(request);
855 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700856 break;
857
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700858 case CMD_GET_MODEM_ACTIVITY_INFO:
859 request = (MainThreadRequest) msg.obj;
860 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700861 if (defaultPhone != null) {
862 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
863 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700864 break;
865
866 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
867 ar = (AsyncResult) msg.obj;
868 request = (MainThreadRequest) ar.userObj;
869 if (ar.exception == null && ar.result != null) {
870 request.result = ar.result;
871 } else {
872 if (ar.result == null) {
873 loge("queryModemActivityInfo: Empty response");
874 } else if (ar.exception instanceof CommandException) {
875 loge("queryModemActivityInfo: CommandException: " +
876 ar.exception);
877 } else {
878 loge("queryModemActivityInfo: Unknown exception");
879 }
880 }
Amit Mahajand4766222016-01-28 15:28:28 -0800881 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
882 if (request.result == null) {
Chen Xu13851032019-09-10 18:49:52 -0700883 request.result = new ModemActivityInfo(0, 0, 0, null, 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800884 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700885 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700886 break;
887
Meng Wang1a7c35a2016-05-05 20:56:15 -0700888 case CMD_SET_ALLOWED_CARRIERS:
889 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800890 CarrierRestrictionRules argument =
891 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700892 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800893 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700894 break;
895
896 case EVENT_SET_ALLOWED_CARRIERS_DONE:
897 ar = (AsyncResult) msg.obj;
898 request = (MainThreadRequest) ar.userObj;
899 if (ar.exception == null && ar.result != null) {
900 request.result = ar.result;
901 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800902 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
903 if (ar.exception instanceof CommandException) {
904 loge("setAllowedCarriers: CommandException: " + ar.exception);
905 CommandException.Error error =
906 ((CommandException) (ar.exception)).getCommandError();
907 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
908 request.result =
909 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
910 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700911 } else {
912 loge("setAllowedCarriers: Unknown exception");
913 }
914 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700915 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700916 break;
917
918 case CMD_GET_ALLOWED_CARRIERS:
919 request = (MainThreadRequest) msg.obj;
920 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800921 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700922 break;
923
924 case EVENT_GET_ALLOWED_CARRIERS_DONE:
925 ar = (AsyncResult) msg.obj;
926 request = (MainThreadRequest) ar.userObj;
927 if (ar.exception == null && ar.result != null) {
928 request.result = ar.result;
929 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800930 request.result = new IllegalStateException(
931 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700932 if (ar.result == null) {
933 loge("getAllowedCarriers: Empty response");
934 } else if (ar.exception instanceof CommandException) {
935 loge("getAllowedCarriers: CommandException: " +
936 ar.exception);
937 } else {
938 loge("getAllowedCarriers: Unknown exception");
939 }
940 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700941 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700942 break;
943
Nathan Haroldb3014052017-01-25 15:57:32 -0800944 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
945 ar = (AsyncResult) msg.obj;
946 request = (MainThreadRequest) ar.userObj;
947 if (ar.exception == null && ar.result != null) {
948 request.result = ar.result;
949 } else {
950 request.result = new IllegalArgumentException(
951 "Failed to retrieve Forbidden Plmns");
952 if (ar.result == null) {
953 loge("getForbiddenPlmns: Empty response");
954 } else {
955 loge("getForbiddenPlmns: Unknown exception");
956 }
957 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700958 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800959 break;
960
961 case CMD_GET_FORBIDDEN_PLMNS:
962 request = (MainThreadRequest) msg.obj;
963 uiccCard = getUiccCardFromRequest(request);
964 if (uiccCard == null) {
965 loge("getForbiddenPlmns() UiccCard is null");
966 request.result = new IllegalArgumentException(
967 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700968 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800969 break;
970 }
971 Integer appType = (Integer) request.argument;
972 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
973 if (uiccApp == null) {
974 loge("getForbiddenPlmns() no app with specified type -- "
975 + appType);
976 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700977 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800978 break;
979 } else {
980 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
981 + " specified type -- " + appType);
982 }
983 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
984 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
985 onCompleted);
986 break;
987
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000988 case CMD_SWITCH_SLOTS:
989 request = (MainThreadRequest) msg.obj;
990 int[] physicalSlots = (int[]) request.argument;
991 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
992 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
993 break;
994
995 case EVENT_SWITCH_SLOTS_DONE:
996 ar = (AsyncResult) msg.obj;
997 request = (MainThreadRequest) ar.userObj;
998 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700999 notifyRequester(request);
1000 break;
1001 case CMD_GET_NETWORK_SELECTION_MODE:
1002 request = (MainThreadRequest) msg.obj;
1003 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1004 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1005 break;
1006
1007 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1008 ar = (AsyncResult) msg.obj;
1009 request = (MainThreadRequest) ar.userObj;
1010 if (ar.exception != null) {
1011 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1012 } else {
1013 int mode = ((int[]) ar.result)[0];
1014 if (mode == 0) {
1015 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1016 } else {
1017 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1018 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001019 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001020 notifyRequester(request);
1021 break;
1022 case CMD_GET_CDMA_ROAMING_MODE:
1023 request = (MainThreadRequest) msg.obj;
1024 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1025 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1026 break;
1027 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1028 ar = (AsyncResult) msg.obj;
1029 request = (MainThreadRequest) ar.userObj;
1030 if (ar.exception != null) {
1031 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1032 } else {
1033 request.result = ((int[]) ar.result)[0];
1034 }
1035 notifyRequester(request);
1036 break;
1037 case CMD_SET_CDMA_ROAMING_MODE:
1038 request = (MainThreadRequest) msg.obj;
1039 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1040 int mode = (int) request.argument;
1041 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1042 break;
1043 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1044 ar = (AsyncResult) msg.obj;
1045 request = (MainThreadRequest) ar.userObj;
1046 request.result = ar.exception == null;
1047 notifyRequester(request);
1048 break;
1049 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1050 request = (MainThreadRequest) msg.obj;
1051 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1052 int subscriptionMode = (int) request.argument;
1053 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1054 break;
1055 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1056 ar = (AsyncResult) msg.obj;
1057 request = (MainThreadRequest) ar.userObj;
1058 request.result = ar.exception == null;
1059 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001060 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001061 case CMD_GET_ALL_CELL_INFO:
1062 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001063 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001064 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001065 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001066 case EVENT_GET_ALL_CELL_INFO_DONE:
1067 ar = (AsyncResult) msg.obj;
1068 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001069 // If a timeout occurs, the response will be null
1070 request.result = (ar.exception == null && ar.result != null)
1071 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001072 synchronized (request) {
1073 request.notifyAll();
1074 }
1075 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001076 case CMD_REQUEST_CELL_INFO_UPDATE:
1077 request = (MainThreadRequest) msg.obj;
1078 request.phone.requestCellInfoUpdate(request.workSource,
1079 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1080 break;
1081 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1082 ar = (AsyncResult) msg.obj;
1083 request = (MainThreadRequest) ar.userObj;
1084 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1085 try {
1086 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001087 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001088 cb.onError(
1089 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1090 ar.exception.getClass().getName(),
1091 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001092 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001093 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001094 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001095 } else {
1096 // use the result as returned
1097 cb.onCellInfo((List<CellInfo>) ar.result);
1098 }
1099 } catch (RemoteException re) {
1100 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1101 }
1102 break;
1103 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001104 request = (MainThreadRequest) msg.obj;
1105 WorkSource ws = (WorkSource) request.argument;
1106 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001107 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001108 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001109 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001110 ar = (AsyncResult) msg.obj;
1111 request = (MainThreadRequest) ar.userObj;
1112 if (ar.exception == null) {
1113 request.result = ar.result;
1114 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001115 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001116 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001117 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001118 }
1119
1120 synchronized (request) {
1121 request.notifyAll();
1122 }
1123 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001124 case CMD_MODEM_REBOOT:
1125 request = (MainThreadRequest) msg.obj;
1126 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001127 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001128 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001129 case EVENT_CMD_MODEM_REBOOT_DONE:
1130 handleNullReturnEvent(msg, "rebootModem");
1131 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001132 case CMD_REQUEST_ENABLE_MODEM:
1133 request = (MainThreadRequest) msg.obj;
1134 boolean enable = (boolean) request.argument;
1135 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001136 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001137 PhoneConfigurationManager.getInstance()
1138 .enablePhone(request.phone, enable, onCompleted);
1139 break;
1140 case EVENT_ENABLE_MODEM_DONE:
1141 ar = (AsyncResult) msg.obj;
1142 request = (MainThreadRequest) ar.userObj;
1143 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001144 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001145 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001146 if ((boolean) request.result) {
1147 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1148 updateModemStateMetrics();
1149 } else {
1150 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1151 + ar.exception);
1152 }
1153 notifyRequester(request);
1154 break;
1155 case CMD_GET_MODEM_STATUS:
1156 request = (MainThreadRequest) msg.obj;
1157 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1158 PhoneConfigurationManager.getInstance()
1159 .getPhoneStatusFromModem(request.phone, onCompleted);
1160 break;
1161 case EVENT_GET_MODEM_STATUS_DONE:
1162 ar = (AsyncResult) msg.obj;
1163 request = (MainThreadRequest) ar.userObj;
1164 int id = request.phone.getPhoneId();
1165 if (ar.exception == null && ar.result != null) {
1166 request.result = ar.result;
1167 //update the cache as modem status has changed
1168 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1169 (boolean) request.result);
1170 } else {
1171 // Return true if modem status cannot be retrieved. For most cases,
1172 // modem status is on. And for older version modems, GET_MODEM_STATUS
1173 // and disable modem are not supported. Modem is always on.
1174 // TODO: this should be fixed in R to support a third
1175 // status UNKNOWN b/131631629
1176 request.result = true;
1177 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1178 + ar.exception);
1179 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001180 notifyRequester(request);
1181 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001182 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1183 ar = (AsyncResult) msg.obj;
1184 request = (MainThreadRequest) ar.userObj;
1185 if (ar.exception == null && ar.result != null) {
1186 request.result = ar.result;
1187 } else {
1188 request.result = -1;
1189 loge("Failed to set Forbidden Plmns");
1190 if (ar.result == null) {
1191 loge("setForbidenPlmns: Empty response");
1192 } else if (ar.exception != null) {
1193 loge("setForbiddenPlmns: Exception: " + ar.exception);
1194 request.result = -1;
1195 } else {
1196 loge("setForbiddenPlmns: Unknown exception");
1197 }
1198 }
1199 notifyRequester(request);
1200 break;
1201 case CMD_SET_FORBIDDEN_PLMNS:
1202 request = (MainThreadRequest) msg.obj;
1203 uiccCard = getUiccCardFromRequest(request);
1204 if (uiccCard == null) {
1205 loge("setForbiddenPlmns: UiccCard is null");
1206 request.result = -1;
1207 notifyRequester(request);
1208 break;
1209 }
1210 Pair<Integer, List<String>> setFplmnsArgs =
1211 (Pair<Integer, List<String>>) request.argument;
1212 appType = setFplmnsArgs.first;
1213 List<String> fplmns = setFplmnsArgs.second;
1214 uiccApp = uiccCard.getApplicationByType(appType);
1215 if (uiccApp == null) {
1216 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1217 request.result = -1;
1218 loge("Failed to get UICC App");
1219 notifyRequester(request);
1220 } else {
1221 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1222 ((SIMRecords) uiccApp.getIccRecords())
1223 .setForbiddenPlmns(onCompleted, fplmns);
1224 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001225 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001226 case CMD_ERASE_MODEM_CONFIG:
1227 request = (MainThreadRequest) msg.obj;
1228 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1229 defaultPhone.eraseModemConfig(onCompleted);
1230 break;
1231 case EVENT_ERASE_MODEM_CONFIG_DONE:
1232 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001233 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001234 default:
1235 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1236 break;
1237 }
1238 }
Jake Hambye994d462014-02-03 13:10:13 -08001239
Pengquan Menga1bb6272018-09-06 09:59:22 -07001240 private void notifyRequester(MainThreadRequest request) {
1241 synchronized (request) {
1242 request.notifyAll();
1243 }
1244 }
1245
Jake Hambye994d462014-02-03 13:10:13 -08001246 private void handleNullReturnEvent(Message msg, String command) {
1247 AsyncResult ar = (AsyncResult) msg.obj;
1248 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1249 if (ar.exception == null) {
1250 request.result = true;
1251 } else {
1252 request.result = false;
1253 if (ar.exception instanceof CommandException) {
1254 loge(command + ": CommandException: " + ar.exception);
1255 } else {
1256 loge(command + ": Unknown exception");
1257 }
1258 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001259 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001260 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001261 }
1262
1263 /**
1264 * Posts the specified command to be executed on the main thread,
1265 * waits for the request to complete, and returns the result.
1266 * @see #sendRequestAsync
1267 */
1268 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001269 return sendRequest(
1270 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001271 }
1272
1273 /**
1274 * Posts the specified command to be executed on the main thread,
1275 * waits for the request to complete, and returns the result.
1276 * @see #sendRequestAsync
1277 */
1278 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1279 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001280 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001281 }
1282
1283 /**
1284 * Posts the specified command to be executed on the main thread,
1285 * waits for the request to complete, and returns the result.
1286 * @see #sendRequestAsync
1287 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001288 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001289 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001290 }
1291
1292 /**
1293 * Posts the specified command to be executed on the main thread,
1294 * waits for the request to complete, and returns the result.
1295 * @see #sendRequestAsync
1296 */
Nathan Harold92bed182018-10-12 18:16:49 -07001297 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1298 return sendRequest(command, argument, subId, null, workSource);
1299 }
1300
1301 /**
1302 * Posts the specified command to be executed on the main thread,
1303 * waits for the request to complete, and returns the result.
1304 * @see #sendRequestAsync
1305 */
1306 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1307 return sendRequest(
1308 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1309 }
1310
1311 /**
1312 * Posts the specified command to be executed on the main thread,
1313 * waits for the request to complete, and returns the result.
1314 * @see #sendRequestAsync
1315 */
1316 private Object sendRequest(
1317 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001318 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1319 throw new RuntimeException("This method will deadlock if called from the main thread.");
1320 }
1321
Nathan Harold92bed182018-10-12 18:16:49 -07001322 MainThreadRequest request = null;
1323 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1324 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1325 } else if (phone != null) {
1326 request = new MainThreadRequest(argument, phone, workSource);
1327 } else {
1328 request = new MainThreadRequest(argument, subId, workSource);
1329 }
1330
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331 Message msg = mMainThreadHandler.obtainMessage(command, request);
1332 msg.sendToTarget();
1333
1334 // Wait for the request to complete
1335 synchronized (request) {
1336 while (request.result == null) {
1337 try {
1338 request.wait();
1339 } catch (InterruptedException e) {
1340 // Do nothing, go back and wait until the request is complete
1341 }
1342 }
1343 }
1344 return request.result;
1345 }
1346
1347 /**
1348 * Asynchronous ("fire and forget") version of sendRequest():
1349 * Posts the specified command to be executed on the main thread, and
1350 * returns immediately.
1351 * @see #sendRequest
1352 */
1353 private void sendRequestAsync(int command) {
1354 mMainThreadHandler.sendEmptyMessage(command);
1355 }
1356
1357 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001358 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001359 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001360 */
1361 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001362 sendRequestAsync(command, argument, null, null);
1363 }
1364
1365 /**
1366 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1367 * @see {@link #sendRequest(int,Object)}
1368 */
1369 private void sendRequestAsync(
1370 int command, Object argument, Phone phone, WorkSource workSource) {
1371 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001372 Message msg = mMainThreadHandler.obtainMessage(command, request);
1373 msg.sendToTarget();
1374 }
1375
1376 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377 * Initialize the singleton PhoneInterfaceManager instance.
1378 * This is only done once, at startup, from PhoneApp.onCreate().
1379 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001380 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001381 synchronized (PhoneInterfaceManager.class) {
1382 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001383 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001384 } else {
1385 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1386 }
1387 return sInstance;
1388 }
1389 }
1390
1391 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001392 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001393 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001394 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001395 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001396 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001397 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1398 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001399 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001400 mTelephonySharedPreferences =
1401 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001402 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001403 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001404
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001405 publish();
1406 }
1407
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001408 private Phone getDefaultPhone() {
1409 Phone thePhone = getPhone(getDefaultSubscription());
1410 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1411 }
1412
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001413 private void publish() {
1414 if (DBG) log("publish: " + this);
1415
1416 ServiceManager.addService("phone", this);
1417 }
1418
Stuart Scott584921c2015-01-15 17:10:34 -08001419 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001420 if (request.phone != null) {
1421 return request.phone;
1422 } else {
1423 return getPhoneFromSubId(request.subId);
1424 }
1425 }
1426
1427 private Phone getPhoneFromSubId(int subId) {
1428 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1429 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001430 }
1431
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001432 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1433 Phone phone = getPhoneFromRequest(request);
1434 return phone == null ? null :
1435 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1436 }
1437
Wink Saville36469e72014-06-11 15:17:00 -07001438 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001439 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001440 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001441 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001442
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001443 private void sendEraseModemConfig(Phone phone) {
1444 if (phone != null) {
1445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1446 mApp, phone.getSubId(), "eraseModemConfig");
1447 final long identity = Binder.clearCallingIdentity();
1448 try {
1449 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1450 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1451 } finally {
1452 Binder.restoreCallingIdentity(identity);
1453 }
1454 }
1455 }
1456
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001457 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001458 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001459 }
1460
Wink Savilleb564aae2014-10-23 10:18:09 -07001461 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001462 if (DBG) log("dial: " + number);
1463 // No permission check needed here: This is just a wrapper around the
1464 // ACTION_DIAL intent, which is available to any app since it puts up
1465 // the UI before it does anything.
1466
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001467 final long identity = Binder.clearCallingIdentity();
1468 try {
1469 String url = createTelUrl(number);
1470 if (url == null) {
1471 return;
1472 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001473
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001474 // PENDING: should we just silently fail if phone is offhook or ringing?
1475 PhoneConstants.State state = mCM.getState(subId);
1476 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1477 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1478 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1479 mApp.startActivity(intent);
1480 }
1481 } finally {
1482 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001483 }
1484 }
1485
1486 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001487 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001488 }
1489
Wink Savilleb564aae2014-10-23 10:18:09 -07001490 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001491 if (DBG) log("call: " + number);
1492
1493 // This is just a wrapper around the ACTION_CALL intent, but we still
1494 // need to do a permission check since we're calling startActivity()
1495 // from the context of the phone app.
1496 enforceCallPermission();
1497
Jordan Liu1617b712019-07-10 15:06:26 -07001498 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001499 != AppOpsManager.MODE_ALLOWED) {
1500 return;
1501 }
1502
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001503 final long identity = Binder.clearCallingIdentity();
1504 try {
1505 String url = createTelUrl(number);
1506 if (url == null) {
1507 return;
1508 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001509
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001510 boolean isValid = false;
1511 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1512 if (slist != null) {
1513 for (SubscriptionInfo subInfoRecord : slist) {
1514 if (subInfoRecord.getSubscriptionId() == subId) {
1515 isValid = true;
1516 break;
1517 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001518 }
Wink Saville08874612014-08-31 19:19:58 -07001519 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001520 if (!isValid) {
1521 return;
1522 }
Wink Saville08874612014-08-31 19:19:58 -07001523
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001524 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1525 intent.putExtra(SUBSCRIPTION_KEY, subId);
1526 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1527 mApp.startActivity(intent);
1528 } finally {
1529 Binder.restoreCallingIdentity(identity);
1530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001531 }
1532
Wink Savilleb564aae2014-10-23 10:18:09 -07001533 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001534 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001535 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1536 }
1537
Wink Savilleb564aae2014-10-23 10:18:09 -07001538 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001539 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001540 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1541 }
1542
Wink Savilleb564aae2014-10-23 10:18:09 -07001543 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001544 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001545
1546 final long identity = Binder.clearCallingIdentity();
1547 try {
1548 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1549 checkSimPin.start();
1550 return checkSimPin.unlockSim(null, pin);
1551 } finally {
1552 Binder.restoreCallingIdentity(identity);
1553 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 }
1555
Wink Savilleb564aae2014-10-23 10:18:09 -07001556 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001557 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001558
1559 final long identity = Binder.clearCallingIdentity();
1560 try {
1561 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1562 checkSimPuk.start();
1563 return checkSimPuk.unlockSim(puk, pin);
1564 } finally {
1565 Binder.restoreCallingIdentity(identity);
1566 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567 }
1568
1569 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001570 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001571 * a synchronous one.
1572 */
1573 private static class UnlockSim extends Thread {
1574
1575 private final IccCard mSimCard;
1576
1577 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001578 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1579 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001580
1581 // For replies from SimCard interface
1582 private Handler mHandler;
1583
1584 // For async handler to identify request type
1585 private static final int SUPPLY_PIN_COMPLETE = 100;
1586
1587 public UnlockSim(IccCard simCard) {
1588 mSimCard = simCard;
1589 }
1590
1591 @Override
1592 public void run() {
1593 Looper.prepare();
1594 synchronized (UnlockSim.this) {
1595 mHandler = new Handler() {
1596 @Override
1597 public void handleMessage(Message msg) {
1598 AsyncResult ar = (AsyncResult) msg.obj;
1599 switch (msg.what) {
1600 case SUPPLY_PIN_COMPLETE:
1601 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1602 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001603 mRetryCount = msg.arg1;
1604 if (ar.exception != null) {
1605 if (ar.exception instanceof CommandException &&
1606 ((CommandException)(ar.exception)).getCommandError()
1607 == CommandException.Error.PASSWORD_INCORRECT) {
1608 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1609 } else {
1610 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1611 }
1612 } else {
1613 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1614 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001615 mDone = true;
1616 UnlockSim.this.notifyAll();
1617 }
1618 break;
1619 }
1620 }
1621 };
1622 UnlockSim.this.notifyAll();
1623 }
1624 Looper.loop();
1625 }
1626
1627 /*
1628 * Use PIN or PUK to unlock SIM card
1629 *
1630 * If PUK is null, unlock SIM card with PIN
1631 *
1632 * If PUK is not null, unlock SIM card with PUK and set PIN code
1633 */
Wink Saville9de0f752013-10-22 19:04:03 -07001634 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001635
1636 while (mHandler == null) {
1637 try {
1638 wait();
1639 } catch (InterruptedException e) {
1640 Thread.currentThread().interrupt();
1641 }
1642 }
1643 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1644
1645 if (puk == null) {
1646 mSimCard.supplyPin(pin, callback);
1647 } else {
1648 mSimCard.supplyPuk(puk, pin, callback);
1649 }
1650
1651 while (!mDone) {
1652 try {
1653 Log.d(LOG_TAG, "wait for done");
1654 wait();
1655 } catch (InterruptedException e) {
1656 // Restore the interrupted status
1657 Thread.currentThread().interrupt();
1658 }
1659 }
1660 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001661 int[] resultArray = new int[2];
1662 resultArray[0] = mResult;
1663 resultArray[1] = mRetryCount;
1664 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001665 }
1666 }
1667
1668 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001669 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001670
1671 }
1672
Wink Savilleb564aae2014-10-23 10:18:09 -07001673 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001674 // No permission check needed here: this call is harmless, and it's
1675 // needed for the ServiceState.requestStateUpdate() call (which is
1676 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001677 final long identity = Binder.clearCallingIdentity();
1678 try {
1679 final Phone phone = getPhone(subId);
1680 if (phone != null) {
1681 phone.updateServiceLocation();
1682 }
1683 } finally {
1684 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001685 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001686 }
1687
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001688 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001689 @Override
1690 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001691 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001692 }
1693
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001694 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001695 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1696 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1697 callingFeatureId);
1698 }
1699
1700 @Deprecated
1701 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001702 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001703 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
1704 }
1705
1706 @Override
1707 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1708 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001709 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001710 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001711 return false;
1712 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001713
1714 final long identity = Binder.clearCallingIdentity();
1715 try {
1716 return isRadioOnForSubscriber(subId);
1717 } finally {
1718 Binder.restoreCallingIdentity(identity);
1719 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001720 }
1721
1722 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001723 final long identity = Binder.clearCallingIdentity();
1724 try {
1725 final Phone phone = getPhone(subId);
1726 if (phone != null) {
1727 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1728 } else {
1729 return false;
1730 }
1731 } finally {
1732 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001733 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 }
1735
1736 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001737 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001738 }
Wink Saville36469e72014-06-11 15:17:00 -07001739
Wink Savilleb564aae2014-10-23 10:18:09 -07001740 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001742
1743 final long identity = Binder.clearCallingIdentity();
1744 try {
1745 final Phone phone = getPhone(subId);
1746 if (phone != null) {
1747 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1748 }
1749 } finally {
1750 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001751 }
Wink Saville36469e72014-06-11 15:17:00 -07001752 }
1753
1754 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001755 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001756 }
1757
Wink Savilleb564aae2014-10-23 10:18:09 -07001758 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001759 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001760
1761 final long identity = Binder.clearCallingIdentity();
1762 try {
1763 final Phone phone = getPhone(subId);
1764 if (phone == null) {
1765 return false;
1766 }
1767 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1768 toggleRadioOnOffForSubscriber(subId);
1769 }
1770 return true;
1771 } finally {
1772 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001773 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 }
Wink Saville36469e72014-06-11 15:17:00 -07001775
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001776 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08001777 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001778 /*
1779 * If any of the Radios are available, it will need to be
1780 * shutdown. So return true if any Radio is available.
1781 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001782 final long identity = Binder.clearCallingIdentity();
1783 try {
1784 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1785 Phone phone = PhoneFactory.getPhone(i);
1786 if (phone != null && phone.isRadioAvailable()) return true;
1787 }
1788 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1789 return false;
1790 } finally {
1791 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001792 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001793 }
1794
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001795 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001796 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001797 enforceModifyPermission();
1798
1799 final long identity = Binder.clearCallingIdentity();
1800 try {
1801 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1802 logv("Shutting down Phone " + i);
1803 shutdownRadioUsingPhoneId(i);
1804 }
1805 } finally {
1806 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001807 }
1808 }
1809
1810 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001811 Phone phone = PhoneFactory.getPhone(phoneId);
1812 if (phone != null && phone.isRadioAvailable()) {
1813 phone.shutdownRadio();
1814 }
1815 }
1816
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001817 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001818 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001819
1820 final long identity = Binder.clearCallingIdentity();
1821 try {
1822 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1823 if (defaultPhone != null) {
1824 defaultPhone.setRadioPower(turnOn);
1825 return true;
1826 } else {
1827 loge("There's no default phone.");
1828 return false;
1829 }
1830 } finally {
1831 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001832 }
Wink Saville36469e72014-06-11 15:17:00 -07001833 }
1834
Wink Savilleb564aae2014-10-23 10:18:09 -07001835 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001836 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001837
1838 final long identity = Binder.clearCallingIdentity();
1839 try {
1840 final Phone phone = getPhone(subId);
1841 if (phone != null) {
1842 phone.setRadioPower(turnOn);
1843 return true;
1844 } else {
1845 return false;
1846 }
1847 } finally {
1848 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001849 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001850 }
1851
Wink Saville36469e72014-06-11 15:17:00 -07001852 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001853 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001854 public boolean enableDataConnectivity() {
1855 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001856
1857 final long identity = Binder.clearCallingIdentity();
1858 try {
1859 int subId = mSubscriptionController.getDefaultDataSubId();
1860 final Phone phone = getPhone(subId);
1861 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001862 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001863 return true;
1864 } else {
1865 return false;
1866 }
1867 } finally {
1868 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001869 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001870 }
1871
Wink Saville36469e72014-06-11 15:17:00 -07001872 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001873 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001874 public boolean disableDataConnectivity() {
1875 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001876
1877 final long identity = Binder.clearCallingIdentity();
1878 try {
1879 int subId = mSubscriptionController.getDefaultDataSubId();
1880 final Phone phone = getPhone(subId);
1881 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001882 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001883 return true;
1884 } else {
1885 return false;
1886 }
1887 } finally {
1888 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001889 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 }
1891
Sanket Padawe356d7632015-06-22 14:03:32 -07001892 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001893 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001894 final long identity = Binder.clearCallingIdentity();
1895 try {
1896 final Phone phone = getPhone(subId);
1897 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001898 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001899 } else {
1900 return false;
1901 }
1902 } finally {
1903 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001904 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001905 }
1906
1907 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001908 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001909 }
1910
pkanwarae03a6b2016-11-06 20:37:09 -08001911 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001912 enforceCallPermission();
1913
1914 final long identity = Binder.clearCallingIdentity();
1915 try {
1916 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1917 return;
1918 }
1919 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1920 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1921 } finally {
1922 Binder.restoreCallingIdentity(identity);
1923 }
pkanwar32d516d2016-10-14 19:37:38 -07001924 };
1925
Wink Savilleb564aae2014-10-23 10:18:09 -07001926 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001927 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001928
1929 final long identity = Binder.clearCallingIdentity();
1930 try {
1931 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1932 return false;
1933 }
1934 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1935 } finally {
1936 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001937 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 }
1939
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001940 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001941 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001942 }
1943
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001944 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001945 final long identity = Binder.clearCallingIdentity();
1946 try {
1947 Phone phone = PhoneFactory.getPhone(slotIndex);
1948 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1949 PhoneConstantConversions.convertCallState(phone.getState());
1950 } finally {
1951 Binder.restoreCallingIdentity(identity);
1952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953 }
1954
Sanket Padawe356d7632015-06-22 14:03:32 -07001955 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001956 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001957 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1958 }
1959
1960 @Override
1961 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001962 final long identity = Binder.clearCallingIdentity();
1963 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001964 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001965 if (phone != null) {
1966 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1967 } else {
1968 return PhoneConstantConversions.convertDataState(
1969 PhoneConstants.DataState.DISCONNECTED);
1970 }
1971 } finally {
1972 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001973 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001974 }
1975
Sanket Padawe356d7632015-06-22 14:03:32 -07001976 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001977 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001978 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1979 }
1980
1981 @Override
1982 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001983 final long identity = Binder.clearCallingIdentity();
1984 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001985 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001986 if (phone != null) {
1987 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1988 } else {
1989 return TelephonyManager.DATA_ACTIVITY_NONE;
1990 }
1991 } finally {
1992 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001993 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001994 }
1995
1996 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08001997 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001998 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001999 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002000
2001 LocationAccessPolicy.LocationPermissionResult locationResult =
2002 LocationAccessPolicy.checkLocationPermission(mApp,
2003 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2004 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002005 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002006 .setCallingPid(Binder.getCallingPid())
2007 .setCallingUid(Binder.getCallingUid())
2008 .setMethod("getCellLocation")
2009 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2010 .build());
2011 switch (locationResult) {
2012 case DENIED_HARD:
2013 throw new SecurityException("Not allowed to access cell location");
2014 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002015 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2016 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 }
2018
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002019 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002020 final long identity = Binder.clearCallingIdentity();
2021 try {
2022 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002023 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002024 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002025 } finally {
2026 Binder.restoreCallingIdentity(identity);
2027 }
Svetoslav64fad262015-04-14 14:35:21 -07002028 }
2029
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002030 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002031 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2032 String callingFeatureId) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002033 if (!TextUtils.isEmpty(callingPackage)) {
2034 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002035 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2036 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002037 return "";
2038 }
2039 }
2040
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002041 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2042 // registered cell info, so return a NULL country instead.
2043 final long identity = Binder.clearCallingIdentity();
2044 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002045 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2046 // Get default phone in this case.
2047 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2048 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002049 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002050 // Todo: fix this when we can get the actual cellular network info when the device
2051 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002052 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002053 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2054 null)) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002055 return "";
2056 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002057 Phone phone = PhoneFactory.getPhone(phoneId);
2058 if (phone != null) {
2059 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002060 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002061 if (sst != null) {
2062 LocaleTracker lt = sst.getLocaleTracker();
2063 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002064 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2065 return lt.getCurrentCountry();
2066 } else if (emergencyNumberTracker != null) {
2067 return emergencyNumberTracker.getEmergencyCountryIso();
2068 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002069 }
2070 }
2071 }
2072 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002073 } finally {
2074 Binder.restoreCallingIdentity(identity);
2075 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002076 }
2077
2078 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002079 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002080 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002081 }
2082
Sanket Padawe356d7632015-06-22 14:03:32 -07002083 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002084 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085 mApp.enforceCallingOrSelfPermission(
2086 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002087
2088 final long identity = Binder.clearCallingIdentity();
2089 try {
2090 final Phone phone = getPhone(subId);
2091 if (phone != null) {
2092 phone.enableLocationUpdates();
2093 }
2094 } finally {
2095 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002096 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002097 }
2098
2099 @Override
2100 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002101 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002102 }
2103
Sanket Padawe356d7632015-06-22 14:03:32 -07002104 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002105 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002106 mApp.enforceCallingOrSelfPermission(
2107 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002108
2109 final long identity = Binder.clearCallingIdentity();
2110 try {
2111 final Phone phone = getPhone(subId);
2112 if (phone != null) {
2113 phone.disableLocationUpdates();
2114 }
2115 } finally {
2116 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002117 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002118 }
2119
Nathan Harold31d7ff32018-10-15 20:20:30 -07002120 /**
2121 * Returns the target SDK version number for a given package name.
2122 *
Nathan Haroldec184742019-07-10 17:04:16 -07002123 * This call MUST be invoked before clearing the calling UID.
2124 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002125 * @return target SDK if the package is found or INT_MAX.
2126 */
2127 private int getTargetSdk(String packageName) {
2128 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002129 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002130 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002131 if (ai != null) return ai.targetSdkVersion;
2132 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002133 loge("Failed to get package info for pkg="
2134 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002135 }
2136 return Integer.MAX_VALUE;
2137 }
2138
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002139 @Override
2140 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002141 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2142 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002143 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002144 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2145 throw new SecurityException(
2146 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2147 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002148
Jordan Liu1617b712019-07-10 15:06:26 -07002149 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2151 return null;
2152 }
Svetoslav64fad262015-04-14 14:35:21 -07002153
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002154 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002156 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002157 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002158
Nathan Haroldf180aac2018-06-01 18:43:55 -07002159 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2160 for (CellInfo ci : info) {
2161 if (ci instanceof CellInfoGsm) {
2162 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2163 } else if (ci instanceof CellInfoWcdma) {
2164 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2165 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002167 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 }
2169
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002170 private List<CellInfo> getCachedCellInfo() {
2171 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2172 for (Phone phone : PhoneFactory.getPhones()) {
2173 List<CellInfo> info = phone.getAllCellInfo();
2174 if (info != null) cellInfos.addAll(info);
2175 }
2176 return cellInfos;
2177 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002178
2179 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002180 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002181 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002182 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002183
2184 LocationAccessPolicy.LocationPermissionResult locationResult =
2185 LocationAccessPolicy.checkLocationPermission(mApp,
2186 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2187 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002188 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002189 .setCallingPid(Binder.getCallingPid())
2190 .setCallingUid(Binder.getCallingUid())
2191 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002192 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002193 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2194 .build());
2195 switch (locationResult) {
2196 case DENIED_HARD:
2197 throw new SecurityException("Not allowed to access cell info");
2198 case DENIED_SOFT:
2199 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002200 }
2201
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002202 final int targetSdk = getTargetSdk(callingPackage);
2203 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2204 return getCachedCellInfo();
2205 }
2206
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002207 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002208 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002209 final long identity = Binder.clearCallingIdentity();
2210 try {
2211 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2212 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002213 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002214 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002215 if (info != null) cellInfos.addAll(info);
2216 }
2217 return cellInfos;
2218 } finally {
2219 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220 }
2221 }
2222
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002223 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002224 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2225 String callingFeatureId) {
2226 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2227 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002228 }
2229
2230 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002231 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2232 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002233 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002234 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002235 }
2236
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002237 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2238 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002239 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002240 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002241
2242 LocationAccessPolicy.LocationPermissionResult locationResult =
2243 LocationAccessPolicy.checkLocationPermission(mApp,
2244 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2245 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002246 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002247 .setCallingPid(Binder.getCallingPid())
2248 .setCallingUid(Binder.getCallingUid())
2249 .setMethod("requestCellInfoUpdate")
2250 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2251 .build());
2252 switch (locationResult) {
2253 case DENIED_HARD:
2254 throw new SecurityException("Not allowed to access cell info");
2255 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002256 try {
2257 cb.onCellInfo(new ArrayList<CellInfo>());
2258 } catch (RemoteException re) {
2259 // Drop without consequences
2260 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002261 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002262 }
2263
Nathan Harolda939a962019-05-09 10:13:47 -07002264
2265 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002266 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2267
2268 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2269 }
2270
2271 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002272 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002273 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002274 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002275
2276 final long identity = Binder.clearCallingIdentity();
2277 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002278 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002279 } finally {
2280 Binder.restoreCallingIdentity(identity);
2281 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 }
2283
Shishir Agrawala9f32182016-04-12 12:00:16 -07002284 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002285 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002286 Phone phone = PhoneFactory.getPhone(slotIndex);
2287 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002288 return null;
2289 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002290 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002291 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002292 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002293 return null;
2294 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002295
2296 final long identity = Binder.clearCallingIdentity();
2297 try {
2298 return phone.getImei();
2299 } finally {
2300 Binder.restoreCallingIdentity(identity);
2301 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002302 }
2303
2304 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002305 public String getTypeAllocationCodeForSlot(int slotIndex) {
2306 Phone phone = PhoneFactory.getPhone(slotIndex);
2307 String tac = null;
2308 if (phone != null) {
2309 String imei = phone.getImei();
2310 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2311 }
2312 return tac;
2313 }
2314
2315 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002316 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002317 Phone phone = PhoneFactory.getPhone(slotIndex);
2318 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002319 return null;
2320 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002321
Jeff Davidson913390f2018-02-23 17:11:49 -08002322 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002323 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002324 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002325 return null;
2326 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002327
2328 final long identity = Binder.clearCallingIdentity();
2329 try {
2330 return phone.getMeid();
2331 } finally {
2332 Binder.restoreCallingIdentity(identity);
2333 }
Jack Yu2af8d712017-03-15 17:14:14 -07002334 }
2335
2336 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002337 public String getManufacturerCodeForSlot(int slotIndex) {
2338 Phone phone = PhoneFactory.getPhone(slotIndex);
2339 String manufacturerCode = null;
2340 if (phone != null) {
2341 String meid = phone.getMeid();
2342 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2343 }
2344 return manufacturerCode;
2345 }
2346
2347 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002348 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2349 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002350 Phone phone = PhoneFactory.getPhone(slotIndex);
2351 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002352 return null;
2353 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002354 int subId = phone.getSubId();
2355 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002356 mApp, subId, callingPackage, callingFeatureId,
2357 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002358 return null;
2359 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002360
2361 final long identity = Binder.clearCallingIdentity();
2362 try {
2363 return phone.getDeviceSvn();
2364 } finally {
2365 Binder.restoreCallingIdentity(identity);
2366 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002367 }
2368
fionaxu43304da2017-11-27 22:51:16 -08002369 @Override
2370 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002371 final long identity = Binder.clearCallingIdentity();
2372 try {
2373 final Phone phone = getPhone(subId);
2374 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2375 } finally {
2376 Binder.restoreCallingIdentity(identity);
2377 }
fionaxu43304da2017-11-27 22:51:16 -08002378 }
2379
2380 @Override
2381 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002382 final long identity = Binder.clearCallingIdentity();
2383 try {
2384 final Phone phone = getPhone(subId);
2385 return phone == null ? null : phone.getCarrierName();
2386 } finally {
2387 Binder.restoreCallingIdentity(identity);
2388 }
fionaxu43304da2017-11-27 22:51:16 -08002389 }
2390
calvinpanffe225e2018-11-01 19:43:06 +08002391 @Override
chen xu0026ca62019-03-06 15:28:50 -08002392 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002393 final long identity = Binder.clearCallingIdentity();
2394 try {
2395 final Phone phone = getPhone(subId);
2396 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002397 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002398 } finally {
2399 Binder.restoreCallingIdentity(identity);
2400 }
2401 }
2402
2403 @Override
chen xu0026ca62019-03-06 15:28:50 -08002404 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002405 final long identity = Binder.clearCallingIdentity();
2406 try {
2407 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002408 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002409 } finally {
2410 Binder.restoreCallingIdentity(identity);
2411 }
2412 }
2413
chen xu651eec72018-11-11 19:03:44 -08002414 @Override
chen xu864e11c2018-12-06 22:10:03 -08002415 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2416 if (!isSubscriptionMccMnc) {
2417 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2418 }
chen xu651eec72018-11-11 19:03:44 -08002419 final Phone phone = PhoneFactory.getPhone(slotIndex);
2420 if (phone == null) {
2421 return TelephonyManager.UNKNOWN_CARRIER_ID;
2422 }
2423 final long identity = Binder.clearCallingIdentity();
2424 try {
2425 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2426 } finally {
2427 Binder.restoreCallingIdentity(identity);
2428 }
2429 }
2430
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 //
2432 // Internal helper methods.
2433 //
2434
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002435 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2437 *
2438 * @throws SecurityException if the caller does not have the required permission
2439 */
2440 private void enforceModifyPermission() {
2441 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2442 }
2443
Shuo Qianf2b2df42019-11-13 17:43:31 -08002444 private void enforceActiveEmergencySessionPermission() {
2445 mApp.enforceCallingOrSelfPermission(
2446 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2447 }
2448
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 /**
2450 * Make sure the caller has the CALL_PHONE permission.
2451 *
2452 * @throws SecurityException if the caller does not have the required permission
2453 */
2454 private void enforceCallPermission() {
2455 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2456 }
2457
paulhu423b5f22019-08-23 19:17:33 +08002458 private void enforceSettingsPermission() {
2459 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002460 }
2461
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 private String createTelUrl(String number) {
2463 if (TextUtils.isEmpty(number)) {
2464 return null;
2465 }
2466
Jake Hambye994d462014-02-03 13:10:13 -08002467 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 }
2469
Ihab Awadf9e92732013-12-05 18:02:52 -08002470 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2472 }
2473
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002474 private static void logv(String msg) {
2475 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2476 }
2477
Ihab Awadf9e92732013-12-05 18:02:52 -08002478 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2480 }
2481
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002482 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002483 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002484 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002485 }
2486
Sanket Padawe356d7632015-06-22 14:03:32 -07002487 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002488 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002489 final long identity = Binder.clearCallingIdentity();
2490 try {
2491 final Phone phone = PhoneFactory.getPhone(slotIndex);
2492 if (phone == null) {
2493 return PhoneConstants.PHONE_TYPE_NONE;
2494 } else {
2495 return phone.getPhoneType();
2496 }
2497 } finally {
2498 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 }
2501
2502 /**
2503 * Returns the CDMA ERI icon index to display
2504 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002505 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002506 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2507 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2508 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002509 }
2510
Sanket Padawe356d7632015-06-22 14:03:32 -07002511 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002512 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2513 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002514 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002515 mApp, subId, callingPackage, callingFeatureId,
2516 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002517 return -1;
2518 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002519
2520 final long identity = Binder.clearCallingIdentity();
2521 try {
2522 final Phone phone = getPhone(subId);
2523 if (phone != null) {
2524 return phone.getCdmaEriIconIndex();
2525 } else {
2526 return -1;
2527 }
2528 } finally {
2529 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002531 }
2532
2533 /**
2534 * Returns the CDMA ERI icon mode,
2535 * 0 - ON
2536 * 1 - FLASHING
2537 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002538 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002539 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2540 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2541 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002542 }
2543
Sanket Padawe356d7632015-06-22 14:03:32 -07002544 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002545 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2546 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002547 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002548 mApp, subId, callingPackage, callingFeatureId,
2549 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002550 return -1;
2551 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002552
2553 final long identity = Binder.clearCallingIdentity();
2554 try {
2555 final Phone phone = getPhone(subId);
2556 if (phone != null) {
2557 return phone.getCdmaEriIconMode();
2558 } else {
2559 return -1;
2560 }
2561 } finally {
2562 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002564 }
2565
2566 /**
2567 * Returns the CDMA ERI text,
2568 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002569 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002570 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2571 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2572 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002573 }
2574
Sanket Padawe356d7632015-06-22 14:03:32 -07002575 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002576 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2577 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002578 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002579 mApp, subId, callingPackage, callingFeatureId,
2580 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002581 return null;
2582 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002583
2584 final long identity = Binder.clearCallingIdentity();
2585 try {
2586 final Phone phone = getPhone(subId);
2587 if (phone != null) {
2588 return phone.getCdmaEriText();
2589 } else {
2590 return null;
2591 }
2592 } finally {
2593 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002594 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002595 }
2596
2597 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002598 * Returns the CDMA MDN.
2599 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002600 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002601 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2603 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002604
2605 final long identity = Binder.clearCallingIdentity();
2606 try {
2607 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002608 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002609 return phone.getLine1Number();
2610 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002611 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612 return null;
2613 }
2614 } finally {
2615 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002616 }
2617 }
2618
2619 /**
2620 * Returns the CDMA MIN.
2621 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002622 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002623 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2625 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626
2627 final long identity = Binder.clearCallingIdentity();
2628 try {
2629 final Phone phone = getPhone(subId);
2630 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2631 return phone.getCdmaMin();
2632 } else {
2633 return null;
2634 }
2635 } finally {
2636 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002637 }
2638 }
2639
Hall Liud892bec2018-11-30 14:51:45 -08002640 @Override
2641 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2642 INumberVerificationCallback callback, String callingPackage) {
2643 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2644 != PERMISSION_GRANTED) {
2645 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2646 }
2647 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2648
2649 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2650 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2651 throw new SecurityException("Calling package must be configured in the device config");
2652 }
2653
2654 if (range == null) {
2655 throw new NullPointerException("Range must be non-null");
2656 }
2657
2658 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002659 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002660
2661 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2662 }
2663
Junda Liuca05d5d2014-08-14 22:36:34 -07002664 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002665 * Returns true if CDMA provisioning needs to run.
2666 */
2667 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668 final long identity = Binder.clearCallingIdentity();
2669 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002670 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002671 } finally {
2672 Binder.restoreCallingIdentity(identity);
2673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002674 }
2675
2676 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002677 * Sets the voice mail number of a given subId.
2678 */
2679 @Override
2680 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08002681 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2682 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683
2684 final long identity = Binder.clearCallingIdentity();
2685 try {
2686 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2687 new Pair<String, String>(alphaTag, number), new Integer(subId));
2688 return success;
2689 } finally {
2690 Binder.restoreCallingIdentity(identity);
2691 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002692 }
2693
Ta-wei Yen87c49842016-05-13 21:19:52 -07002694 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002695 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2696 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002697 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2698 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002699 if (!TextUtils.equals(callingPackage, systemDialer)) {
2700 throw new SecurityException("caller must be system dialer");
2701 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702
2703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2706 if (phoneAccountHandle == null) {
2707 return null;
2708 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002709 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002710 } finally {
2711 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002712 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002713 }
2714
2715 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002716 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2717 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002718 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002719 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002720 mApp, subId, callingPackage, callingFeatureId,
2721 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002722 return null;
2723 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002724
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002725 final long identity = Binder.clearCallingIdentity();
2726 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002727 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002728 } finally {
2729 Binder.restoreCallingIdentity(identity);
2730 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002731 }
2732
2733 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002734 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2735 VisualVoicemailSmsFilterSettings settings) {
2736 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737
2738 final long identity = Binder.clearCallingIdentity();
2739 try {
2740 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002741 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002742 } finally {
2743 Binder.restoreCallingIdentity(identity);
2744 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002745 }
2746
2747 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002748 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2749 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002750
2751 final long identity = Binder.clearCallingIdentity();
2752 try {
2753 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002754 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002755 } finally {
2756 Binder.restoreCallingIdentity(identity);
2757 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002758 }
2759
2760 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002761 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2762 String callingPackage, int subId) {
2763 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002764
2765 final long identity = Binder.clearCallingIdentity();
2766 try {
2767 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002768 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002769 } finally {
2770 Binder.restoreCallingIdentity(identity);
2771 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002772 }
2773
2774 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002775 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002776 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002777
2778 final long identity = Binder.clearCallingIdentity();
2779 try {
2780 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002781 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002782 } finally {
2783 Binder.restoreCallingIdentity(identity);
2784 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002785 }
2786
2787 @Override
2788 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2789 String number, int port, String text, PendingIntent sentIntent) {
2790 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002791 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002792 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002793 SmsController smsController = PhoneFactory.getSmsController();
2794 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2795 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002796 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002797
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002798 /**
fionaxu0152e512016-11-14 13:36:14 -08002799 * Sets the voice activation state of a given subId.
2800 */
2801 @Override
2802 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2804 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002805
2806 final long identity = Binder.clearCallingIdentity();
2807 try {
2808 final Phone phone = getPhone(subId);
2809 if (phone != null) {
2810 phone.setVoiceActivationState(activationState);
2811 } else {
2812 loge("setVoiceActivationState fails with invalid subId: " + subId);
2813 }
2814 } finally {
2815 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002816 }
2817 }
2818
2819 /**
2820 * Sets the data activation state of a given subId.
2821 */
2822 @Override
2823 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2825 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826
2827 final long identity = Binder.clearCallingIdentity();
2828 try {
2829 final Phone phone = getPhone(subId);
2830 if (phone != null) {
2831 phone.setDataActivationState(activationState);
2832 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002833 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002834 }
2835 } finally {
2836 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002837 }
2838 }
2839
2840 /**
2841 * Returns the voice activation state of a given subId.
2842 */
2843 @Override
2844 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002845 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002846
fionaxu0152e512016-11-14 13:36:14 -08002847 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002848 final long identity = Binder.clearCallingIdentity();
2849 try {
2850 if (phone != null) {
2851 return phone.getVoiceActivationState();
2852 } else {
2853 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2854 }
2855 } finally {
2856 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002857 }
2858 }
2859
2860 /**
2861 * Returns the data activation state of a given subId.
2862 */
2863 @Override
2864 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002865 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002866
fionaxu0152e512016-11-14 13:36:14 -08002867 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002868 final long identity = Binder.clearCallingIdentity();
2869 try {
2870 if (phone != null) {
2871 return phone.getDataActivationState();
2872 } else {
2873 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2874 }
2875 } finally {
2876 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002877 }
2878 }
2879
2880 /**
Wink Saville36469e72014-06-11 15:17:00 -07002881 * Returns the unread count of voicemails for a subId
2882 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002883 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002884 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2885 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002886 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002887 mApp, subId, callingPackage, callingFeatureId,
2888 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002889 return 0;
2890 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002891 final long identity = Binder.clearCallingIdentity();
2892 try {
2893 final Phone phone = getPhone(subId);
2894 if (phone != null) {
2895 return phone.getVoiceMessageCount();
2896 } else {
2897 return 0;
2898 }
2899 } finally {
2900 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002901 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002902 }
2903
2904 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002905 * returns true, if the device is in a state where both voice and data
2906 * are supported simultaneously. This can change based on location or network condition.
2907 */
2908 @Override
2909 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910 final long identity = Binder.clearCallingIdentity();
2911 try {
2912 final Phone phone = getPhone(subId);
2913 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2914 } finally {
2915 Binder.restoreCallingIdentity(identity);
2916 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002917 }
2918
2919 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002920 * Send the dialer code if called from the current default dialer or the caller has
2921 * carrier privilege.
2922 * @param inputCode The dialer code to send
2923 */
2924 @Override
2925 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002926 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002927 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002928 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2929 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002930 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08002931 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08002932 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002933 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002934
2935 final long identity = Binder.clearCallingIdentity();
2936 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002937 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938 } finally {
2939 Binder.restoreCallingIdentity(identity);
2940 }
fionaxu235cc5e2017-03-06 22:25:57 -08002941 }
2942
Pengquan Menga1bb6272018-09-06 09:59:22 -07002943 @Override
2944 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002945 if (!isActiveSubscription(subId)) {
2946 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2947 }
2948
Pengquan Menga1bb6272018-09-06 09:59:22 -07002949 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2950 }
2951
Brad Ebinger35c841c2018-10-01 10:40:55 -07002952 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002953 public boolean isInEmergencySmsMode() {
2954 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2955 final long identity = Binder.clearCallingIdentity();
2956 try {
2957 for (Phone phone : PhoneFactory.getPhones()) {
2958 if (phone.isInEmergencySmsMode()) {
2959 return true;
2960 }
2961 }
2962 } finally {
2963 Binder.restoreCallingIdentity(identity);
2964 }
2965 return false;
2966 }
2967
shilu366312e2019-12-17 09:28:10 -08002968 /**
2969 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
2970 * @param subId The subscription to use to check the configuration.
2971 * @param c The callback that will be used to send the result.
2972 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07002973 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002974 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2975 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08002976 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002977 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08002978
Brad Ebinger77b832e2019-10-17 17:03:22 -07002979 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2980 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2981 "IMS not available on device.");
2982 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002983 final long token = Binder.clearCallingIdentity();
2984 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002985 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002986 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002987 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002988 } catch (ImsException e) {
2989 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002990 } finally {
2991 Binder.restoreCallingIdentity(token);
2992 }
2993 }
2994
shilu366312e2019-12-17 09:28:10 -08002995 /**
2996 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
2997 * @param subId The subscription to use to check the configuration.
2998 * @param c The callback that will be used to send the result.
2999 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003000 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003001 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
shilu366312e2019-12-17 09:28:10 -08003002 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003003 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003004 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3005 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3006 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003007 final long token = Binder.clearCallingIdentity();
3008 try {
3009 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3010 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3011 .removeRegistrationCallbackForSubscription(c, subId);
3012 } catch (ImsException e) {
3013 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3014 + "is inactive, ignoring unregister.");
3015 // If the subscription is no longer active, just return, since the callback
3016 // will already have been removed internally.
3017 } finally {
3018 Binder.restoreCallingIdentity(token);
3019 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003020 }
3021
Brad Ebinger774ba362019-10-22 17:36:18 -07003022 /**
3023 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3024 */
3025 @Override
3026 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3027 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3028 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3029 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3030 "IMS not available on device.");
3031 }
3032 final long token = Binder.clearCallingIdentity();
3033 try {
3034 Phone phone = getPhone(subId);
3035 if (phone == null) {
3036 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3037 + subId + "'");
3038 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3039 }
3040 phone.getImsRegistrationState(regState -> {
3041 try {
3042 consumer.accept((regState == null)
3043 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3044 } catch (RemoteException e) {
3045 // Ignore if the remote process is no longer available to call back.
3046 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3047 }
3048 });
3049 } finally {
3050 Binder.restoreCallingIdentity(token);
3051 }
3052 }
3053
3054 /**
3055 * Get the transport type for the IMS service registration state.
3056 */
3057 @Override
3058 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
shilu366312e2019-12-17 09:28:10 -08003059 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger774ba362019-10-22 17:36:18 -07003060 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3061 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3062 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3063 "IMS not available on device.");
3064 }
3065 final long token = Binder.clearCallingIdentity();
3066 try {
3067 Phone phone = getPhone(subId);
3068 if (phone == null) {
3069 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3070 + subId + "'");
3071 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3072 }
3073 phone.getImsRegistrationTech(regTech -> {
3074 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3075 int regTechConverted = (regTech == null)
3076 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3077 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3078 regTechConverted);
3079 try {
3080 consumer.accept(regTechConverted);
3081 } catch (RemoteException e) {
3082 // Ignore if the remote process is no longer available to call back.
3083 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3084 }
3085 });
3086 } finally {
3087 Binder.restoreCallingIdentity(token);
3088 }
3089 }
3090
shilu366312e2019-12-17 09:28:10 -08003091 /**
3092 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3093 * @param subId The subscription to use to check the configuration.
3094 * @param c The callback that will be used to send the result.
3095 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003096 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003097 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3098 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003099 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003100 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003101 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3102 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3103 "IMS not available on device.");
3104 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003105 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3106 final long token = Binder.clearCallingIdentity();
3107 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003108 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003109 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003110 } catch (ImsException e) {
3111 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003112 } finally {
3113 Binder.restoreCallingIdentity(token);
3114 }
3115 }
3116
shilu366312e2019-12-17 09:28:10 -08003117 /**
3118 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3119 * @param subId The subscription to use to check the configuration.
3120 * @param c The callback that will be used to send the result.
3121 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003122 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003123 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
shilu366312e2019-12-17 09:28:10 -08003124 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003125 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003126 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3127 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3128 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003129
3130 final long token = Binder.clearCallingIdentity();
3131 try {
3132 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3133 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003134 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003135 } catch (ImsException e) {
3136 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3137 + "is inactive, ignoring unregister.");
3138 // If the subscription is no longer active, just return, since the callback
3139 // will already have been removed internally.
3140 } finally {
3141 Binder.restoreCallingIdentity(token);
3142 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003143 }
3144
3145 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003146 public boolean isCapable(int subId, int capability, int regTech) {
3147 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003148 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3149 final long token = Binder.clearCallingIdentity();
3150 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003151 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003152 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003153 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003154 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3155 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003156 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003157 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3158 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003159 } finally {
3160 Binder.restoreCallingIdentity(token);
3161 }
3162 }
3163
3164 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003165 public boolean isAvailable(int subId, int capability, int regTech) {
3166 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003167 final long token = Binder.clearCallingIdentity();
3168 try {
3169 Phone phone = getPhone(subId);
3170 if (phone == null) return false;
3171 return phone.isImsCapabilityAvailable(capability, regTech);
3172 } finally {
3173 Binder.restoreCallingIdentity(token);
3174 }
3175 }
3176
Brad Ebinger77b832e2019-10-17 17:03:22 -07003177 /**
3178 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3179 * subscription.
3180 * @param subId The subscription to use to check the configuration.
3181 * @param callback The callback that will be used to send the result.
3182 * @param capability The MmTelFeature capability that will be used to send the result.
3183 * @param transportType The transport type of the MmTelFeature capability.
3184 */
3185 @Override
3186 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3187 int transportType) {
3188 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3189 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3190 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3191 "IMS not available on device.");
3192 }
3193 final long token = Binder.clearCallingIdentity();
3194 try {
3195 int slotId = getSlotIndex(subId);
3196 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3197 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3198 + subId + "'");
3199 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3200 }
3201 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3202 transportType, aBoolean -> {
3203 try {
3204 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3205 } catch (RemoteException e) {
3206 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3207 + "running. Ignore");
3208 }
3209 });
3210 } finally {
3211 Binder.restoreCallingIdentity(token);
3212 }
3213 }
3214
shilu366312e2019-12-17 09:28:10 -08003215 /**
3216 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3217 * @param subId The subscription to use to check the configuration.
3218 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003219 @Override
3220 public boolean isAdvancedCallingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003221 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
3222 enforceReadPrivilegedPermission("isAdvancedCallingSettingEnabled");
3223
Brad Ebinger35c841c2018-10-01 10:40:55 -07003224 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3225 final long token = Binder.clearCallingIdentity();
3226 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003227 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003228 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003229 } catch (ImsException e) {
3230 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003231 } finally {
3232 Binder.restoreCallingIdentity(token);
3233 }
3234 }
3235
3236 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003237 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003238 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003239 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003240 final long identity = Binder.clearCallingIdentity();
3241 try {
3242 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003243 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003244 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003245 } catch (ImsException e) {
3246 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003247 } finally {
3248 Binder.restoreCallingIdentity(identity);
3249 }
3250 }
3251
shilu366312e2019-12-17 09:28:10 -08003252 /**
3253 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3254 * @param subId The subscription to use to check the configuration.
3255 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003256 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003257 public boolean isVtSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003258 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003259 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003260 final long identity = Binder.clearCallingIdentity();
3261 try {
3262 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003263 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3264 } catch (ImsException e) {
3265 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003266 } finally {
3267 Binder.restoreCallingIdentity(identity);
3268 }
3269 }
3270
3271 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003272 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003273 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003274 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003275 final long identity = Binder.clearCallingIdentity();
3276 try {
3277 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003278 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003279 } catch (ImsException e) {
3280 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003281 } finally {
3282 Binder.restoreCallingIdentity(identity);
3283 }
3284 }
3285
shilu366312e2019-12-17 09:28:10 -08003286 /**
3287 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3288 * @param subId The subscription to use to check the configuration.
3289 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003290 @Override
3291 public boolean isVoWiFiSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003292 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003293 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3294 final long identity = Binder.clearCallingIdentity();
3295 try {
3296 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003297 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003298 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003299 } catch (ImsException e) {
3300 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003301 } finally {
3302 Binder.restoreCallingIdentity(identity);
3303 }
3304 }
3305
3306 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003307 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003309 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003310 final long identity = Binder.clearCallingIdentity();
3311 try {
3312 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003313 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003314 } catch (ImsException e) {
3315 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003316 } finally {
3317 Binder.restoreCallingIdentity(identity);
3318 }
3319 }
3320
shilu366312e2019-12-17 09:28:10 -08003321 /**
3322 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3323 * @param subId The subscription to use to check the configuration.
3324 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003325 @Override
3326 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003327 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003328 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3329 final long identity = Binder.clearCallingIdentity();
3330 try {
3331 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003332 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003333 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003334 } catch (ImsException e) {
3335 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003336 } finally {
3337 Binder.restoreCallingIdentity(identity);
3338 }
3339 }
3340
3341 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003342 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003344 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003345 final long identity = Binder.clearCallingIdentity();
3346 try {
3347 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003348 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003349 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003350 } catch (ImsException e) {
3351 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003352 } finally {
3353 Binder.restoreCallingIdentity(identity);
3354 }
3355 }
3356
3357 @Override
3358 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3360 "setVoWiFiNonPersistent");
3361 final long identity = Binder.clearCallingIdentity();
3362 try {
3363 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003364 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003365 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003366 } catch (ImsException e) {
3367 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003368 } finally {
3369 Binder.restoreCallingIdentity(identity);
3370 }
3371 }
3372
shilu366312e2019-12-17 09:28:10 -08003373 /**
3374 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3375 * @param subId The subscription to use to check the configuration.
3376 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003377 @Override
3378 public int getVoWiFiModeSetting(int subId) {
shilu366312e2019-12-17 09:28:10 -08003379 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003380 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3381 final long identity = Binder.clearCallingIdentity();
3382 try {
3383 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003384 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003385 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003386 } catch (ImsException e) {
3387 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003388 } finally {
3389 Binder.restoreCallingIdentity(identity);
3390 }
3391 }
3392
3393 @Override
3394 public void setVoWiFiModeSetting(int subId, int mode) {
3395 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3396 "setVoWiFiModeSetting");
3397 final long identity = Binder.clearCallingIdentity();
3398 try {
3399 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003400 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003401 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003402 } catch (ImsException e) {
3403 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003404 } finally {
3405 Binder.restoreCallingIdentity(identity);
3406 }
3407 }
3408
3409 @Override
3410 public int getVoWiFiRoamingModeSetting(int subId) {
3411 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3412 final long identity = Binder.clearCallingIdentity();
3413 try {
3414 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003415 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003416 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003417 } catch (ImsException e) {
3418 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003419 } finally {
3420 Binder.restoreCallingIdentity(identity);
3421 }
3422 }
3423
3424 @Override
3425 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3427 "setVoWiFiRoamingModeSetting");
3428 final long identity = Binder.clearCallingIdentity();
3429 try {
3430 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003431 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003432 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003433 } catch (ImsException e) {
3434 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003435 } finally {
3436 Binder.restoreCallingIdentity(identity);
3437 }
3438 }
3439
3440 @Override
3441 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3442 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3443 "setRttCapabilityEnabled");
3444 final long identity = Binder.clearCallingIdentity();
3445 try {
3446 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003447 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3448 } catch (ImsException e) {
3449 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003450 } finally {
3451 Binder.restoreCallingIdentity(identity);
3452 }
3453 }
3454
shilu366312e2019-12-17 09:28:10 -08003455 /**
3456 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3457 * @param subId The subscription to use to check the configuration.
3458 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003459 @Override
3460 public boolean isTtyOverVolteEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003461 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003462 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3463 final long identity = Binder.clearCallingIdentity();
3464 try {
3465 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003466 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003467 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003468 } catch (ImsException e) {
3469 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003470 } finally {
3471 Binder.restoreCallingIdentity(identity);
3472 }
3473 }
3474
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003475 @Override
3476 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3477 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3478 final long identity = Binder.clearCallingIdentity();
3479 try {
3480 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003481 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003482 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003483 } catch (ImsException e) {
3484 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003485 } finally {
3486 Binder.restoreCallingIdentity(identity);
3487 }
3488 }
3489
3490 @Override
3491 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3492 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3493 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003494 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3495 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3496 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003497 try {
3498 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003499 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003500 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003501 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003502 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3503 + "is inactive, ignoring unregister.");
3504 // If the subscription is no longer active, just return, since the callback will already
3505 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003506 } finally {
3507 Binder.restoreCallingIdentity(identity);
3508 }
3509 }
3510
allenwtsu99c623b2020-01-03 18:24:23 +08003511
3512 private void checkModifyPhoneStatePermission(int subId, String message) {
3513 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3514 message);
3515 }
3516
3517 private boolean isImsProvisioningRequired(int subId, int capability,
3518 boolean isMmtelCapability) {
3519 Phone phone = getPhone(subId);
3520 if (phone == null) {
3521 loge("phone instance null for subid " + subId);
3522 return false;
3523 }
3524 if (isMmtelCapability) {
3525 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3526 return false;
3527 }
3528 } else {
3529 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3530 return false;
3531 }
3532 }
3533 return true;
3534 }
3535
3536 @Override
3537 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3538 boolean isProvisioned) {
3539 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3540
3541 final long identity = Binder.clearCallingIdentity();
3542 try {
3543 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3544 if (!isImsProvisioningRequired(subId, capability, false)) {
3545 return;
3546 }
3547
3548 // this capability requires provisioning, route to the correct API.
3549 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3550 switch (capability) {
3551 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3552 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3553 ims.setEabProvisioned(isProvisioned);
3554 break;
3555 default: {
3556 throw new IllegalArgumentException("Tried to set provisioning for "
3557 + "rcs capability '" + capability + "', which does not require "
3558 + "provisioning.");
3559 }
3560 }
3561 } finally {
3562 Binder.restoreCallingIdentity(identity);
3563 }
3564
3565 }
3566
3567
3568 @Override
3569 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3570 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3571 final long identity = Binder.clearCallingIdentity();
3572 try {
3573 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3574 if (!isImsProvisioningRequired(subId, capability, false)) {
3575 return true;
3576 }
3577
3578 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3579 switch (capability) {
3580 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3581 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3582 return ims.isEabProvisionedOnDevice();
3583
3584 default: {
3585 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3586 + "capability '" + capability + "', which does not require "
3587 + "provisioning.");
3588 }
3589 }
3590
3591 } finally {
3592 Binder.restoreCallingIdentity(identity);
3593 }
3594 }
3595
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003596 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003597 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3598 boolean isProvisioned) {
3599 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3600 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3601 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3602 }
allenwtsu99c623b2020-01-03 18:24:23 +08003603 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003604 final long identity = Binder.clearCallingIdentity();
3605 try {
3606 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003607 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003608 return;
3609 }
3610
3611 // this capability requires provisioning, route to the correct API.
3612 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3613 switch (capability) {
3614 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3615 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3616 ims.setVolteProvisioned(isProvisioned);
3617 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3618 ims.setWfcProvisioned(isProvisioned);
3619 }
3620 break;
3621 }
3622 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3623 // There is currently no difference in VT provisioning type.
3624 ims.setVtProvisioned(isProvisioned);
3625 break;
3626 }
3627 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3628 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3629 // change the capability of the feature instead if needed.
3630 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3631 == isProvisioned) {
3632 // No change in provisioning.
3633 return;
3634 }
3635 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3636 try {
3637 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003638 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003639 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3640 + ", Exception" + e.getMessage());
3641 }
3642 break;
3643 }
3644 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003645 throw new IllegalArgumentException("Tried to set provisioning for "
3646 + "MmTel capability '" + capability + "', which does not require "
3647 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003648 }
3649 }
3650
3651 } finally {
3652 Binder.restoreCallingIdentity(identity);
3653 }
3654 }
3655
3656 @Override
3657 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3658 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3659 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3660 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3661 }
3662 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3663 final long identity = Binder.clearCallingIdentity();
3664 try {
3665 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003666 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003667 return true;
3668 }
3669
3670 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3671 switch (capability) {
3672 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3673 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3674 return ims.isVolteProvisionedOnDevice();
3675 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3676 return ims.isWfcProvisionedOnDevice();
3677 }
3678 // This should never happen, since we are checking tech above to make sure it
3679 // is either LTE or IWLAN.
3680 throw new IllegalArgumentException("Invalid radio technology for voice "
3681 + "capability.");
3682 }
3683 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3684 // There is currently no difference in VT provisioning type.
3685 return ims.isVtProvisionedOnDevice();
3686 }
3687 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3688 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3689 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3690 }
3691 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003692 throw new IllegalArgumentException(
3693 "Tried to get provisioning for MmTel capability '" + capability
3694 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003695 }
3696 }
3697
3698 } finally {
3699 Binder.restoreCallingIdentity(identity);
3700 }
3701 }
3702
3703 @Override
3704 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3705 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3706 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3707 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3708 }
3709 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3710 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3711 return (provisionedBits & capability) > 0;
3712 }
3713
3714 @Override
3715 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3716 boolean isProvisioned) {
3717 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3718 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3719 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3720 }
3721 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3722 "setProvisioningStatusForCapability");
3723 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3724 // If the current provisioning status for capability already matches isProvisioned,
3725 // do nothing.
3726 if (((provisionedBits & capability) > 0) == isProvisioned) {
3727 return;
3728 }
3729 if (isProvisioned) {
3730 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3731 } else {
3732 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3733 }
3734 }
3735
3736 /**
3737 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3738 * technology. The bitfield should mirror the bitfield defined by
3739 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3740 */
3741 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3742 String key = getMmTelProvisioningKey(subId, tech);
3743 // Default is no capabilities are provisioned.
3744 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3745 }
3746
3747 /**
3748 * Sets the MmTel capability provisioning bitfield (defined by
3749 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3750 * technology specified.
3751 *
3752 * Note: This is a synchronous command and should not be called on UI thread.
3753 */
3754 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3755 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3756 String key = getMmTelProvisioningKey(subId, tech);
3757 editor.putInt(key, newField);
3758 editor.commit();
3759 }
3760
3761 private static String getMmTelProvisioningKey(int subId, int tech) {
3762 // resulting key is provision_ims_mmtel_{subId}_{tech}
3763 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3764 }
3765
3766 /**
3767 * Query CarrierConfig to see if the specified capability requires provisioning for the
3768 * carrier associated with the subscription id.
3769 */
3770 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3771 int capability) {
3772 CarrierConfigManager configManager = new CarrierConfigManager(context);
3773 PersistableBundle c = configManager.getConfigForSubId(subId);
3774 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003775 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003776 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3777 false);
3778 boolean requireVoiceVtProvisioning = c.getBoolean(
3779 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3780
3781 // First check to make sure that the capability requires provisioning.
3782 switch (capability) {
3783 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3784 // intentional fallthrough
3785 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3786 if (requireVoiceVtProvisioning) {
3787 // Voice and Video requires provisioning
3788 return true;
3789 }
3790 break;
3791 }
3792 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3793 if (requireUtProvisioning) {
3794 // UT requires provisioning
3795 return true;
3796 }
3797 break;
3798 }
3799 }
3800 return false;
3801 }
3802
allenwtsu99c623b2020-01-03 18:24:23 +08003803 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
3804 int capability) {
3805 CarrierConfigManager configManager = new CarrierConfigManager(context);
3806 PersistableBundle c = configManager.getConfigForSubId(subId);
3807
3808 boolean requireRcsProvisioning = c.getBoolean(
3809 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
3810
3811 // First check to make sure that the capability requires provisioning.
3812 switch (capability) {
3813 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3814 // intentional fallthrough
3815 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
3816 if (requireRcsProvisioning) {
3817 // OPTION or PRESENCE requires provisioning
3818 return true;
3819 }
3820 break;
3821 }
3822 }
3823 return false;
3824 }
3825
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003826 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003827 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003828 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3829 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3830 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003831 enforceReadPrivilegedPermission("getImsProvisioningInt");
3832 final long identity = Binder.clearCallingIdentity();
3833 try {
3834 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003835 int slotId = getSlotIndex(subId);
3836 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3837 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3838 + subId + "' for key:" + key);
3839 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3840 }
3841 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003842 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003843 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3844 + subId + "' for key:" + key);
3845 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003846 } finally {
3847 Binder.restoreCallingIdentity(identity);
3848 }
3849 }
3850
3851 @Override
3852 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003853 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3854 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3855 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003856 enforceReadPrivilegedPermission("getImsProvisioningString");
3857 final long identity = Binder.clearCallingIdentity();
3858 try {
3859 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003860 int slotId = getSlotIndex(subId);
3861 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3862 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3863 + subId + "' for key:" + key);
3864 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3865 }
3866 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003867 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003868 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3869 + subId + "' for key:" + key);
3870 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003871 } finally {
3872 Binder.restoreCallingIdentity(identity);
3873 }
3874 }
3875
3876 @Override
3877 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003878 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3879 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3880 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003881 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3882 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003883 final long identity = Binder.clearCallingIdentity();
3884 try {
3885 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003886 int slotId = getSlotIndex(subId);
3887 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3888 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3889 + subId + "' for key:" + key);
3890 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3891 }
3892 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003893 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003894 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3895 + "' for key:" + key);
3896 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003897 } finally {
3898 Binder.restoreCallingIdentity(identity);
3899 }
3900 }
3901
3902 @Override
3903 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003904 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3905 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3906 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003907 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3908 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003909 final long identity = Binder.clearCallingIdentity();
3910 try {
3911 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003912 int slotId = getSlotIndex(subId);
3913 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3914 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3915 + subId + "' for key:" + key);
3916 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3917 }
3918 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003919 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003920 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3921 + "' for key:" + key);
3922 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003923 } finally {
3924 Binder.restoreCallingIdentity(identity);
3925 }
3926 }
3927
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003928 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003929 int slotId = SubscriptionManager.getSlotIndex(subId);
3930 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003931 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3932 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003933 }
3934 return slotId;
3935 }
3936
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003937 private int getSlotIndex(int subId) {
3938 int slotId = SubscriptionManager.getSlotIndex(subId);
3939 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3940 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3941 }
3942 return slotId;
3943 }
3944
Wink Saville36469e72014-06-11 15:17:00 -07003945 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003946 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003947 */
3948 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003949 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3950 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003951 final int targetSdk = getTargetSdk(callingPackage);
3952 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003953 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003954 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003955 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003956 mApp, subId, callingPackage, callingFeatureId,
3957 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003958 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3959 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003960
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003961 final long identity = Binder.clearCallingIdentity();
3962 try {
3963 final Phone phone = getPhone(subId);
3964 if (phone != null) {
3965 return phone.getServiceState().getDataNetworkType();
3966 } else {
3967 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3968 }
3969 } finally {
3970 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003971 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003972 }
3973
3974 /**
3975 * Returns the data network type
3976 */
3977 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003978 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
3979 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
3980 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003981 }
3982
3983 /**
3984 * Returns the data network type for a subId
3985 */
3986 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003987 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
3988 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003989 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003990 mApp, subId, callingPackage, callingFeatureId,
3991 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003992 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3993 }
3994
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003995 final long identity = Binder.clearCallingIdentity();
3996 try {
3997 final Phone phone = getPhone(subId);
3998 if (phone != null) {
3999 return phone.getServiceState().getDataNetworkType();
4000 } else {
4001 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4002 }
4003 } finally {
4004 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004005 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004006 }
4007
4008 /**
Wink Saville36469e72014-06-11 15:17:00 -07004009 * Returns the Voice network type for a subId
4010 */
4011 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004012 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4013 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004014 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004015 mApp, subId, callingPackage, callingFeatureId,
4016 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004017 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4018 }
4019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004020 final long identity = Binder.clearCallingIdentity();
4021 try {
4022 final Phone phone = getPhone(subId);
4023 if (phone != null) {
4024 return phone.getServiceState().getVoiceNetworkType();
4025 } else {
4026 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4027 }
4028 } finally {
4029 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004030 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004031 }
4032
4033 /**
4034 * @return true if a ICC card is present
4035 */
4036 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004037 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004038 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4039 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004040 }
4041
4042 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004043 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004044 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004045 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004046 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004047 final long identity = Binder.clearCallingIdentity();
4048 try {
4049 final Phone phone = PhoneFactory.getPhone(slotIndex);
4050 if (phone != null) {
4051 return phone.getIccCard().hasIccCard();
4052 } else {
4053 return false;
4054 }
4055 } finally {
4056 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004057 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004058 }
4059
4060 /**
4061 * Return if the current radio is LTE on CDMA. This
4062 * is a tri-state return value as for a period of time
4063 * the mode may be unknown.
4064 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004065 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004066 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004067 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004068 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004069 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004070 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4071 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4072 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004073 }
4074
Sanket Padawe356d7632015-06-22 14:03:32 -07004075 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004076 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4077 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004078 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004079 mApp, subId, callingPackage, callingFeatureId,
4080 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004081 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4082 }
4083
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004084 final long identity = Binder.clearCallingIdentity();
4085 try {
4086 final Phone phone = getPhone(subId);
4087 if (phone == null) {
4088 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4089 } else {
4090 return phone.getLteOnCdmaMode();
4091 }
4092 } finally {
4093 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004094 }
Wink Saville36469e72014-06-11 15:17:00 -07004095 }
4096
Wink Saville36469e72014-06-11 15:17:00 -07004097 /**
4098 * {@hide}
4099 * Returns Default subId, 0 in the case of single standby.
4100 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004101 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004102 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004103 }
4104
Shishir Agrawala9f32182016-04-12 12:00:16 -07004105 private int getSlotForDefaultSubscription() {
4106 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4107 }
4108
Wink Savilleb564aae2014-10-23 10:18:09 -07004109 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004110 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004111 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004112
Pengquan Menge92a50d2018-09-21 15:54:48 -07004113 private boolean isActiveSubscription(int subId) {
4114 return mSubscriptionController.isActiveSubId(subId);
4115 }
4116
Ihab Awadf2177b72013-11-25 13:33:23 -08004117 /**
4118 * @see android.telephony.TelephonyManager.WifiCallingChoices
4119 */
4120 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004121 final long identity = Binder.clearCallingIdentity();
4122 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004123 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004124 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4125 getWhenToMakeWifiCallsDefaultPreference());
4126 } finally {
4127 Binder.restoreCallingIdentity(identity);
4128 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004129 }
4130
4131 /**
4132 * @see android.telephony.TelephonyManager.WifiCallingChoices
4133 */
4134 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004135 final long identity = Binder.clearCallingIdentity();
4136 try {
4137 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004138 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004139 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4140 } finally {
4141 Binder.restoreCallingIdentity(identity);
4142 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004143 }
4144
Sailesh Nepald1e68152013-12-12 19:08:02 -08004145 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004146 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004147 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004148 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004149
Jordan Liu4c733742019-02-28 12:03:40 -08004150 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4151 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4152 if (phoneId == -1) {
4153 throw new IllegalArgumentException("Given slot index: " + slotIndex
4154 + " does not correspond to an active phone");
4155 }
4156 return PhoneFactory.getPhone(phoneId);
4157 }
4158
Shishir Agrawal566b7612013-10-28 14:41:00 -07004159 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004160 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4161 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4163 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004164 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004165 if (DBG) {
4166 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4167 }
4168 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4169 p2);
4170 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004171
Jordan Liu4c733742019-02-28 12:03:40 -08004172
4173 @Override
4174 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4175 int slotIndex, String callingPackage, String aid, int p2) {
4176 enforceModifyPermission();
4177 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4178 if (DBG) {
4179 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4180 }
4181 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4182 callingPackage, aid, p2);
4183 }
4184
4185 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4186 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004187 final long identity = Binder.clearCallingIdentity();
4188 try {
4189 if (TextUtils.equals(ISDR_AID, aid)) {
4190 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004191 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4192 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004193 if (bestComponent == null
4194 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4195 loge("The calling package is not allowed to access ISD-R.");
4196 throw new SecurityException(
4197 "The calling package is not allowed to access ISD-R.");
4198 }
Derek Tan740e1672017-06-27 14:56:27 -07004199 }
Derek Tan740e1672017-06-27 14:56:27 -07004200
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004201 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004202 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4203 null /* workSource */);
4204 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004205 return response;
4206 } finally {
4207 Binder.restoreCallingIdentity(identity);
4208 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004209 }
4210
4211 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004212 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004213 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4214 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004215 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4216 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4217 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004218
Jordan Liu4c733742019-02-28 12:03:40 -08004219 @Override
4220 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4221 enforceModifyPermission();
4222 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4223 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4224 channel);
4225 }
4226
4227 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004228 final long identity = Binder.clearCallingIdentity();
4229 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004230 if (channel < 0) {
4231 return false;
4232 }
Jordan Liu4c733742019-02-28 12:03:40 -08004233 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4234 null /* workSource */);
4235 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004236 return success;
4237 } finally {
4238 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004239 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004240 }
4241
4242 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004243 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004244 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4246 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004247 if (DBG) {
4248 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4249 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4250 + p3 + " data=" + data);
4251 }
4252 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4253 command, p1, p2, p3, data);
4254 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004255
Jordan Liu4c733742019-02-28 12:03:40 -08004256 @Override
4257 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4258 int command, int p1, int p2, int p3, String data) {
4259 enforceModifyPermission();
4260 if (DBG) {
4261 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4262 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4263 + p3 + " data=" + data);
4264 }
4265 return iccTransmitApduLogicalChannelWithPermission(
4266 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4267 data);
4268 }
4269
4270 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4271 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004272 final long identity = Binder.clearCallingIdentity();
4273 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004274 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004275 return "";
4276 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004277
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004278 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004279 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4280 null /* workSource */);
4281 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004282
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004283 // Append the returned status code to the end of the response payload.
4284 String s = Integer.toHexString(
4285 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4286 if (response.payload != null) {
4287 s = IccUtils.bytesToHexString(response.payload) + s;
4288 }
4289 return s;
4290 } finally {
4291 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004292 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004293 }
Jake Hambye994d462014-02-03 13:10:13 -08004294
Evan Charltonc66da362014-05-16 14:06:40 -07004295 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004296 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4297 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004298 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4299 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004300 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004301 if (DBG) {
4302 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4303 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4304 }
4305 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4306 cla, command, p1, p2, p3, data);
4307 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004308
Jordan Liu4c733742019-02-28 12:03:40 -08004309 @Override
4310 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4311 int command, int p1, int p2, int p3, String data) {
4312 enforceModifyPermission();
4313 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4314 if (DBG) {
4315 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4316 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4317 + " data=" + data);
4318 }
4319
4320 return iccTransmitApduBasicChannelWithPermission(
4321 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4322 p2, p3, data);
4323 }
4324
4325 // open APDU basic channel assuming the caller has sufficient permissions
4326 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4327 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004328 final long identity = Binder.clearCallingIdentity();
4329 try {
4330 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4331 && TextUtils.equals(ISDR_AID, data)) {
4332 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004333 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4334 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004335 if (bestComponent == null
4336 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4337 loge("The calling package is not allowed to select ISD-R.");
4338 throw new SecurityException(
4339 "The calling package is not allowed to select ISD-R.");
4340 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004341 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004342
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004343 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004344 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4345 null /* workSource */);
4346 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004347
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004348 // Append the returned status code to the end of the response payload.
4349 String s = Integer.toHexString(
4350 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4351 if (response.payload != null) {
4352 s = IccUtils.bytesToHexString(response.payload) + s;
4353 }
4354 return s;
4355 } finally {
4356 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004357 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004358 }
4359
4360 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004361 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004362 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004363 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4364 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004365
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004366 final long identity = Binder.clearCallingIdentity();
4367 try {
4368 if (DBG) {
4369 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4370 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4371 }
4372
4373 IccIoResult response =
4374 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4375 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4376 subId);
4377
4378 if (DBG) {
4379 log("Exchange SIM_IO [R]" + response);
4380 }
4381
4382 byte[] result = null;
4383 int length = 2;
4384 if (response.payload != null) {
4385 length = 2 + response.payload.length;
4386 result = new byte[length];
4387 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4388 } else {
4389 result = new byte[length];
4390 }
4391
4392 result[length - 1] = (byte) response.sw2;
4393 result[length - 2] = (byte) response.sw1;
4394 return result;
4395 } finally {
4396 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004397 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004398 }
4399
Nathan Haroldb3014052017-01-25 15:57:32 -08004400 /**
4401 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4402 * on a particular subscription
4403 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004404 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4405 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004406 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004407 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004408 return null;
4409 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004410
4411 final long identity = Binder.clearCallingIdentity();
4412 try {
4413 if (appType != TelephonyManager.APPTYPE_USIM
4414 && appType != TelephonyManager.APPTYPE_SIM) {
4415 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4416 return null;
4417 }
4418 Object response = sendRequest(
4419 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4420 if (response instanceof String[]) {
4421 return (String[]) response;
4422 }
yincheng zhaod698b842019-09-06 17:06:54 -07004423 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004424 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004425 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004426 } finally {
4427 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004428 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004429 }
4430
yincheng zhaod698b842019-09-06 17:06:54 -07004431 /**
4432 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4433 * subscription.
4434 *
4435 * @param subId the id of the subscription.
4436 * @param appType the uicc app type, must be USIM or SIM.
4437 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4438 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004439 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004440 * @return number of fplmns that is successfully written to the SIM.
4441 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004442 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4443 String callingFeatureId) {
4444 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4445 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004446 if (DBG) logv("no permissions for setForbiddenplmns");
4447 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4448 }
4449 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4450 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4451 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4452 }
4453 if (fplmns == null) {
4454 throw new IllegalArgumentException("Fplmn List provided is null");
4455 }
4456 for (String fplmn : fplmns) {
4457 if (!CellIdentity.isValidPlmn(fplmn)) {
4458 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4459 }
4460 }
4461 final long identity = Binder.clearCallingIdentity();
4462 try {
4463 Object response = sendRequest(
4464 CMD_SET_FORBIDDEN_PLMNS,
4465 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4466 subId);
4467 return (int) response;
4468 } finally {
4469 Binder.restoreCallingIdentity(identity);
4470 }
4471 }
4472
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004473 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004474 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4476 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004477
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004478 final long identity = Binder.clearCallingIdentity();
4479 try {
4480 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4481 if (response.payload == null) {
4482 return "";
4483 }
Evan Charltonc66da362014-05-16 14:06:40 -07004484
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004485 // Append the returned status code to the end of the response payload.
4486 String s = Integer.toHexString(
4487 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4488 s = IccUtils.bytesToHexString(response.payload) + s;
4489 return s;
4490 } finally {
4491 Binder.restoreCallingIdentity(identity);
4492 }
Evan Charltonc66da362014-05-16 14:06:40 -07004493 }
4494
Jake Hambye994d462014-02-03 13:10:13 -08004495 /**
4496 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4497 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4498 *
4499 * @param itemID the ID of the item to read
4500 * @return the NV item as a String, or null on error.
4501 */
4502 @Override
4503 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004504 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004505 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4506 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004507
4508 final long identity = Binder.clearCallingIdentity();
4509 try {
4510 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004511 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004512 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4513 return value;
4514 } finally {
4515 Binder.restoreCallingIdentity(identity);
4516 }
Jake Hambye994d462014-02-03 13:10:13 -08004517 }
4518
4519 /**
4520 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4521 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4522 *
4523 * @param itemID the ID of the item to read
4524 * @param itemValue the value to write, as a String
4525 * @return true on success; false on any failure
4526 */
4527 @Override
4528 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004529 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004530 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4531 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004532
4533 final long identity = Binder.clearCallingIdentity();
4534 try {
4535 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4536 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004537 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004538 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4539 return success;
4540 } finally {
4541 Binder.restoreCallingIdentity(identity);
4542 }
Jake Hambye994d462014-02-03 13:10:13 -08004543 }
4544
4545 /**
4546 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4547 * Used for device configuration by some CDMA operators.
4548 *
4549 * @param preferredRoamingList byte array containing the new PRL
4550 * @return true on success; false on any failure
4551 */
4552 @Override
4553 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004554 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4555 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004556
4557 final long identity = Binder.clearCallingIdentity();
4558 try {
4559 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4560 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4561 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4562 return success;
4563 } finally {
4564 Binder.restoreCallingIdentity(identity);
4565 }
Jake Hambye994d462014-02-03 13:10:13 -08004566 }
4567
4568 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004569 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004570 * Used for device configuration by some CDMA operators.
4571 *
chen xu6dac5ab2018-10-26 17:39:23 -07004572 * @param slotIndex - device slot.
4573 *
Jake Hambye994d462014-02-03 13:10:13 -08004574 * @return true on success; false on any failure
4575 */
4576 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004577 public boolean resetModemConfig(int slotIndex) {
4578 Phone phone = PhoneFactory.getPhone(slotIndex);
4579 if (phone != null) {
4580 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4581 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004582
chen xu6dac5ab2018-10-26 17:39:23 -07004583 final long identity = Binder.clearCallingIdentity();
4584 try {
4585 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4586 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4587 return success;
4588 } finally {
4589 Binder.restoreCallingIdentity(identity);
4590 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004591 }
chen xu6dac5ab2018-10-26 17:39:23 -07004592 return false;
4593 }
4594
4595 /**
4596 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4597 *
4598 * @param slotIndex - device slot.
4599 *
4600 * @return true on success; false on any failure
4601 */
4602 @Override
4603 public boolean rebootModem(int slotIndex) {
4604 Phone phone = PhoneFactory.getPhone(slotIndex);
4605 if (phone != null) {
4606 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4607 mApp, phone.getSubId(), "rebootModem");
4608
4609 final long identity = Binder.clearCallingIdentity();
4610 try {
4611 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4612 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4613 return success;
4614 } finally {
4615 Binder.restoreCallingIdentity(identity);
4616 }
4617 }
4618 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004619 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004620
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004621 public String[] getPcscfAddress(String apnType, String callingPackage,
4622 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004623 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004624 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4625 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004626 return new String[0];
4627 }
4628
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004629 final long identity = Binder.clearCallingIdentity();
4630 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004631 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004632 } finally {
4633 Binder.restoreCallingIdentity(identity);
4634 }
Wink Saville36469e72014-06-11 15:17:00 -07004635 }
4636
Brad Ebinger51f743a2017-01-23 13:50:20 -08004637 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004638 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4639 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004640 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004641 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004642 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004643
4644 final long identity = Binder.clearCallingIdentity();
4645 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004646 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004647 // may happen if the device does not support IMS.
4648 return;
4649 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004650 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004651 } finally {
4652 Binder.restoreCallingIdentity(identity);
4653 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004654 }
4655
4656 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004657 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4658 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004659 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004660 public void disableIms(int slotId) {
4661 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004662
4663 final long identity = Binder.clearCallingIdentity();
4664 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004665 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004666 // may happen if the device does not support IMS.
4667 return;
4668 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004669 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004670 } finally {
4671 Binder.restoreCallingIdentity(identity);
4672 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004673 }
4674
4675 /**
4676 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4677 * feature or {@link null} if the service is not available. If the feature is available, the
4678 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4679 */
4680 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004681 IImsServiceFeatureCallback callback) {
4682 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004683
4684 final long identity = Binder.clearCallingIdentity();
4685 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004686 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004687 // may happen if the device does not support IMS.
4688 return null;
4689 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004690 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004691 } finally {
4692 Binder.restoreCallingIdentity(identity);
4693 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004694 }
4695
4696 /**
4697 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4698 * feature during emergency calling or {@link null} if the service is not available. If the
4699 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4700 * listener for feature updates.
4701 */
4702 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4703 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004704
4705 final long identity = Binder.clearCallingIdentity();
4706 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004707 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004708 // may happen if the device does not support IMS.
4709 return null;
4710 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004711 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004712 } finally {
4713 Binder.restoreCallingIdentity(identity);
4714 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004715 }
4716
Brad Ebinger5f64b052017-12-14 14:26:15 -08004717 /**
4718 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004719 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004720 */
4721 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4722 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004723
4724 final long identity = Binder.clearCallingIdentity();
4725 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004726 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004727 // may happen if the device does not support IMS.
4728 return null;
4729 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004730 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004731 } finally {
4732 Binder.restoreCallingIdentity(identity);
4733 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004734 }
4735
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004736 /**
4737 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004738 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004739 */
4740 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4741 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004742
4743 final long identity = Binder.clearCallingIdentity();
4744 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004745 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004746 // may happen if the device does not support IMS.
4747 return null;
4748 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004749 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004750 } finally {
4751 Binder.restoreCallingIdentity(identity);
4752 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004753 }
4754
Brad Ebinger884c07b2018-02-15 16:17:40 -08004755 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004756 * Sets the ImsService Package Name that Telephony will bind to.
4757 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08004758 * @param slotIndex the slot ID that the ImsService should bind for.
4759 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004760 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004761 * @param featureTypes An integer array of feature types associated with a packageName.
4762 * @param packageName The name of the package that the current configuration will be replaced
4763 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004764 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004765 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004766 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4767 int[] featureTypes, String packageName) {
4768 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4769 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4771 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08004772 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004773
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004774 final long identity = Binder.clearCallingIdentity();
4775 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004776 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004777 // may happen if the device does not support IMS.
4778 return false;
4779 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004780 Map<Integer, String> featureConfig = new HashMap<>();
4781 for (int featureType : featureTypes) {
4782 featureConfig.put(featureType, packageName);
4783 }
4784 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4785 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004786 } finally {
4787 Binder.restoreCallingIdentity(identity);
4788 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004789 }
4790
4791 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08004792 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004793 *
4794 * @param slotId The slot that the ImsService is associated with.
4795 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4796 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004797 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004798 * @return the package name of the ImsService configuration.
4799 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004800 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4801 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004802 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08004803 TelephonyPermissions
4804 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4805 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4806 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004807
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004808 final long identity = Binder.clearCallingIdentity();
4809 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004810 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004811 // may happen if the device does not support IMS.
4812 return "";
4813 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004814 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004815 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4816 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004817 } finally {
4818 Binder.restoreCallingIdentity(identity);
4819 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004820 }
4821
Brad Ebinger77b832e2019-10-17 17:03:22 -07004822 /**
4823 * Get the MmTelFeature state associated with the requested subscription id.
4824 * @param subId The subscription that the MmTelFeature is associated with.
4825 * @param callback A callback with an integer containing the
4826 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4827 */
4828 @Override
4829 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4830 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4831 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4832 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4833 "IMS not available on device.");
4834 }
4835 final long token = Binder.clearCallingIdentity();
4836 try {
4837 int slotId = getSlotIndex(subId);
4838 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4839 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4840 + subId + "'");
4841 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4842 }
4843 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4844 try {
4845 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4846 } catch (RemoteException e) {
4847 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4848 + "Ignore");
4849 }
4850 });
4851 } finally {
4852 Binder.restoreCallingIdentity(token);
4853 }
4854 }
4855
Wink Saville36469e72014-06-11 15:17:00 -07004856 public void setImsRegistrationState(boolean registered) {
4857 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004858
4859 final long identity = Binder.clearCallingIdentity();
4860 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004861 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004862 } finally {
4863 Binder.restoreCallingIdentity(identity);
4864 }
Wink Saville36469e72014-06-11 15:17:00 -07004865 }
4866
4867 /**
Stuart Scott54788802015-03-30 13:18:01 -07004868 * Set the network selection mode to automatic.
4869 *
4870 */
4871 @Override
4872 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4874 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004875
Pengquan Menge92a50d2018-09-21 15:54:48 -07004876 if (!isActiveSubscription(subId)) {
4877 return;
4878 }
4879
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004880 final long identity = Binder.clearCallingIdentity();
4881 try {
4882 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4883 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4884 } finally {
4885 Binder.restoreCallingIdentity(identity);
4886 }
Stuart Scott54788802015-03-30 13:18:01 -07004887 }
4888
Pengquan Mengea84e042018-09-20 14:57:26 -07004889 /**
4890 * Ask the radio to connect to the input network and change selection mode to manual.
4891 *
4892 * @param subId the id of the subscription.
4893 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4894 * the operator to attach to.
4895 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4896 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4897 * normal network selection next time.
4898 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004899 */
4900 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004901 public boolean setNetworkSelectionModeManual(
4902 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004903 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4904 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004905
4906 if (!isActiveSubscription(subId)) {
4907 return false;
4908 }
4909
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004910 final long identity = Binder.clearCallingIdentity();
4911 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004912 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004913 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004914 if (DBG) {
4915 log("setNetworkSelectionModeManual: subId: " + subId
4916 + " operator: " + operatorInfo);
4917 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004918 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4919 } finally {
4920 Binder.restoreCallingIdentity(identity);
4921 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004922 }
4923
4924 /**
4925 * Scans for available networks.
4926 */
4927 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004928 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4929 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004930 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4931 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004932 LocationAccessPolicy.LocationPermissionResult locationResult =
4933 LocationAccessPolicy.checkLocationPermission(mApp,
4934 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4935 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004936 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004937 .setCallingPid(Binder.getCallingPid())
4938 .setCallingUid(Binder.getCallingUid())
4939 .setMethod("getCellNetworkScanResults")
4940 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4941 .build());
4942 switch (locationResult) {
4943 case DENIED_HARD:
4944 throw new SecurityException("Not allowed to access scan results -- location");
4945 case DENIED_SOFT:
4946 return null;
4947 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004948
Pengquan Menga1bb6272018-09-06 09:59:22 -07004949 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004950 try {
4951 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004952 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004953 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004954 } finally {
4955 Binder.restoreCallingIdentity(identity);
4956 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004957 }
4958
4959 /**
yinxub1bed742017-04-17 11:45:04 -07004960 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004961 *
yinxub1bed742017-04-17 11:45:04 -07004962 * @param subId id of the subscription
4963 * @param request contains the radio access networks with bands/channels to scan
4964 * @param messenger callback messenger for scan results or errors
4965 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004966 * @return the id of the requested scan which can be used to stop the scan.
4967 */
4968 @Override
4969 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004970 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4972 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004973 LocationAccessPolicy.LocationPermissionResult locationResult =
4974 LocationAccessPolicy.checkLocationPermission(mApp,
4975 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4976 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004977 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004978 .setCallingPid(Binder.getCallingPid())
4979 .setCallingUid(Binder.getCallingUid())
4980 .setMethod("requestNetworkScan")
4981 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4982 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004983 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004984 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004985 if (e != null) {
4986 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4987 throw e;
4988 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004989 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004990 return TelephonyScanManager.INVALID_SCAN_ID;
4991 }
4992 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004993 }
Hall Liu912dfd32019-04-25 14:02:26 -07004994 int callingUid = Binder.getCallingUid();
4995 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004996 final long identity = Binder.clearCallingIdentity();
4997 try {
4998 return mNetworkScanRequestTracker.startNetworkScan(
4999 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005000 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005001 } finally {
5002 Binder.restoreCallingIdentity(identity);
5003 }
yinxu504e1392017-04-12 16:03:22 -07005004 }
5005
Hall Liub2ac8ef2019-02-28 15:56:23 -08005006 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005007 NetworkScanRequest request, int subId) {
5008 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5009 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5010 boolean hasNetworkScanPermission =
5011 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5012 == PERMISSION_GRANTED;
5013
5014 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5015 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5016 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005017 }
5018
5019 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5020 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005021 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5022 return new SecurityException("Specific channels must not be"
5023 + " scanned without location access.");
5024 }
5025 }
5026 }
5027
Hall Liub2ac8ef2019-02-28 15:56:23 -08005028 return null;
5029 }
5030
yinxu504e1392017-04-12 16:03:22 -07005031 /**
5032 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005033 *
5034 * @param subId id of the subscription
5035 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005036 */
5037 @Override
5038 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5040 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005041
Hall Liu912dfd32019-04-25 14:02:26 -07005042 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005043 final long identity = Binder.clearCallingIdentity();
5044 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005045 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005046 } finally {
5047 Binder.restoreCallingIdentity(identity);
5048 }
yinxu504e1392017-04-12 16:03:22 -07005049 }
5050
5051 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005052 * Get the calculated preferred network type.
5053 * Used for debugging incorrect network type.
5054 *
5055 * @return the preferred network type, defined in RILConstants.java.
5056 */
5057 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005058 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005059 final Phone defaultPhone = getDefaultPhone();
5060 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005061 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005062 return RILConstants.PREFERRED_NETWORK_MODE;
5063 }
5064
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005065 final long identity = Binder.clearCallingIdentity();
5066 try {
5067 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005068 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005069 } finally {
5070 Binder.restoreCallingIdentity(identity);
5071 }
Junda Liu84d15a22014-07-02 11:21:04 -07005072 }
5073
5074 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005075 * Get the preferred network type.
5076 * Used for device configuration by some CDMA operators.
5077 *
5078 * @return the preferred network type, defined in RILConstants.java.
5079 */
5080 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005081 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005082 TelephonyPermissions
5083 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5084 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005085
5086 final long identity = Binder.clearCallingIdentity();
5087 try {
5088 if (DBG) log("getPreferredNetworkType");
5089 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5090 int networkType = (result != null ? result[0] : -1);
5091 if (DBG) log("getPreferredNetworkType: " + networkType);
5092 return networkType;
5093 } finally {
5094 Binder.restoreCallingIdentity(identity);
5095 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005096 }
5097
5098 /**
5099 * Set the preferred network type.
5100 * Used for device configuration by some CDMA operators.
5101 *
5102 * @param networkType the preferred network type, defined in RILConstants.java.
5103 * @return true on success; false on any failure.
5104 */
5105 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005106 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005107 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5108 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005109
5110 final long identity = Binder.clearCallingIdentity();
5111 try {
5112 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
5113 Boolean success = (Boolean) sendRequest(
5114 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5115 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5116 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005117 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005118 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5119 }
5120 return success;
5121 } finally {
5122 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005123 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005124 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005125
5126 /**
Miaoa84611c2019-03-15 09:21:10 +08005127 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005128 *
Miaoa84611c2019-03-15 09:21:10 +08005129 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005130 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005131 * @hide
5132 */
5133 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005134 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005135 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005136 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005137 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005138 try {
Miaoa84611c2019-03-15 09:21:10 +08005139 if (phone != null) {
5140 return phone.hasMatchedTetherApnSetting();
5141 } else {
5142 return false;
5143 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005144 } finally {
5145 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005146 }
Junda Liu475951f2014-11-07 16:45:03 -08005147 }
5148
5149 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005150 * Set mobile data enabled
5151 * Used by the user through settings etc to turn on/off mobile data
5152 *
5153 * @param enable {@code true} turn turn data on, else {@code false}
5154 */
5155 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005156 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005157 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5158 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005159
5160 final long identity = Binder.clearCallingIdentity();
5161 try {
5162 int phoneId = mSubscriptionController.getPhoneId(subId);
5163 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5164 Phone phone = PhoneFactory.getPhone(phoneId);
5165 if (phone != null) {
5166 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005167 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005168 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005169 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005170 }
5171 } finally {
5172 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005173 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005174 }
5175
5176 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005177 * Get the user enabled state of Mobile Data.
5178 *
5179 * TODO: remove and use isUserDataEnabled.
5180 * This can't be removed now because some vendor codes
5181 * calls through ITelephony directly while they should
5182 * use TelephonyManager.
5183 *
5184 * @return true on enabled
5185 */
5186 @Override
5187 public boolean getDataEnabled(int subId) {
5188 return isUserDataEnabled(subId);
5189 }
5190
5191 /**
5192 * Get whether mobile data is enabled per user setting.
5193 *
5194 * There are other factors deciding whether mobile data is actually enabled, but they are
5195 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005196 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005197 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005198 *
5199 * @return {@code true} if data is enabled else {@code false}
5200 */
5201 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005202 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005203 try {
5204 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5205 null);
5206 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005207 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5208 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005209 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005210
5211 final long identity = Binder.clearCallingIdentity();
5212 try {
5213 int phoneId = mSubscriptionController.getPhoneId(subId);
5214 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5215 Phone phone = PhoneFactory.getPhone(phoneId);
5216 if (phone != null) {
5217 boolean retVal = phone.isUserDataEnabled();
5218 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5219 return retVal;
5220 } else {
5221 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5222 return false;
5223 }
5224 } finally {
5225 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005226 }
5227 }
5228
5229 /**
5230 * Get whether mobile data is enabled.
5231 *
5232 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5233 * whether mobile data is actually enabled.
5234 *
5235 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5236 *
5237 * @return {@code true} if data is enabled else {@code false}
5238 */
5239 @Override
5240 public boolean isDataEnabled(int subId) {
5241 try {
5242 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5243 null);
5244 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5246 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005247 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005248
5249 final long identity = Binder.clearCallingIdentity();
5250 try {
5251 int phoneId = mSubscriptionController.getPhoneId(subId);
5252 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5253 Phone phone = PhoneFactory.getPhone(phoneId);
5254 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005255 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005256 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5257 return retVal;
5258 } else {
5259 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5260 return false;
5261 }
5262 } finally {
5263 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005264 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005265 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005266
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005267 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5268 Phone phone) {
5269 //load access rules from carrier configs, and check those as well: b/139133814
5270 SubscriptionController subController = SubscriptionController.getInstance();
5271 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5272 || subController == null) return privilegeFromSim;
5273
5274 int uid = Binder.getCallingUid();
5275 PackageManager pkgMgr = phone.getContext().getPackageManager();
5276 String[] packages = pkgMgr.getPackagesForUid(uid);
5277
5278 final long identity = Binder.clearCallingIdentity();
5279 try {
5280 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5281 SubscriptionManager subManager = (SubscriptionManager)
5282 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5283 for (String pkg : packages) {
5284 if (subManager.canManageSubscription(subInfo, pkg)) {
5285 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5286 }
5287 }
5288 return privilegeFromSim;
5289 } finally {
5290 Binder.restoreCallingIdentity(identity);
5291 }
5292 }
5293
5294 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5295 String pkgName) {
5296 //load access rules from carrier configs, and check those as well: b/139133814
5297 SubscriptionController subController = SubscriptionController.getInstance();
5298 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5299 || subController == null) return privilegeFromSim;
5300
5301 final long identity = Binder.clearCallingIdentity();
5302 try {
5303 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5304 SubscriptionManager subManager = (SubscriptionManager)
5305 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5306 return subManager.canManageSubscription(subInfo, pkgName)
5307 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5308 } finally {
5309 Binder.restoreCallingIdentity(identity);
5310 }
5311 }
5312
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005313 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005314 public int getCarrierPrivilegeStatus(int subId) {
5315 final Phone phone = getPhone(subId);
5316 if (phone == null) {
5317 loge("getCarrierPrivilegeStatus: Invalid subId");
5318 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5319 }
5320 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005321 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005322 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005323 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5324 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005325
5326 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5327 card.getCarrierPrivilegeStatusForCurrentTransaction(
5328 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005329 }
Junda Liu29340342014-07-10 15:23:27 -07005330
5331 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005332 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005333 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005334 final Phone phone = getPhone(subId);
5335 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005336 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005337 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5338 }
5339 UiccProfile profile =
5340 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5341 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005342 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005343 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5344 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005345 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005346 profile.getCarrierPrivilegeStatusForUid(
5347 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005348 }
5349
5350 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005351 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5352 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005353 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005354 }
5355
5356 int phoneId = SubscriptionManager.getPhoneId(subId);
5357 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005358 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005359 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005360 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5361 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005362 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5363 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5364 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005365 }
5366
5367 @Override
5368 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005369 if (TextUtils.isEmpty(pkgName))
5370 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005371 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5372 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5373 UiccCard card = UiccController.getInstance().getUiccCard(i);
5374 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005375 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005376 continue;
5377 }
5378
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005379 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5380 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5381 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005382 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5383 break;
5384 }
5385 }
5386
5387 return result;
Junda Liu29340342014-07-10 15:23:27 -07005388 }
Derek Tan89e89d42014-07-08 17:00:10 -07005389
5390 @Override
Junda Liue64de782015-04-16 17:19:16 -07005391 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5392 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5393 loge("phoneId " + phoneId + " is not valid.");
5394 return null;
5395 }
5396 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005397 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005398 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005399 return null ;
5400 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005401 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005402 }
5403
Amith Yamasani6e118872016-02-19 12:53:51 -08005404 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005405 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005406 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005407 List<String> privilegedPackages = new ArrayList<>();
5408 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005409 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5410 // has UICC in that slot.
5411 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005412 if (card.hasCarrierPrivilegeRules()) {
5413 if (packages == null) {
5414 // Only check packages in user 0 for now
5415 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005416 PackageManager.MATCH_DISABLED_COMPONENTS
5417 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005418 | PackageManager.GET_SIGNING_CERTIFICATES,
5419 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005420 }
5421 for (int p = packages.size() - 1; p >= 0; p--) {
5422 PackageInfo pkgInfo = packages.get(p);
5423 if (pkgInfo != null && pkgInfo.packageName != null
5424 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005425 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005426 privilegedPackages.add(pkgInfo.packageName);
5427 }
5428 }
5429 }
5430 }
5431 return privilegedPackages;
5432 }
5433
chen xuf7e9fe82019-05-09 19:31:02 -07005434 @Override
5435 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005436 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5437
5438 final long identity = Binder.clearCallingIdentity();
5439
chen xuf7e9fe82019-05-09 19:31:02 -07005440 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005441 try {
5442 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5443 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5444 }
5445 } finally {
5446 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005447 }
5448 return privilegedPackages;
5449 }
5450
Wink Savilleb564aae2014-10-23 10:18:09 -07005451 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005452 final Phone phone = getPhone(subId);
5453 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005454 if (card == null) {
5455 loge("getIccId: No UICC");
5456 return null;
5457 }
5458 String iccId = card.getIccId();
5459 if (TextUtils.isEmpty(iccId)) {
5460 loge("getIccId: ICC ID is null or empty.");
5461 return null;
5462 }
5463 return iccId;
5464 }
5465
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005466 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005467 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5468 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08005469 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005470 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005472 final long identity = Binder.clearCallingIdentity();
5473 try {
5474 final String iccId = getIccId(subId);
5475 final Phone phone = getPhone(subId);
5476 if (phone == null) {
5477 return false;
5478 }
5479 final String subscriberId = phone.getSubscriberId();
5480
5481 if (DBG_MERGE) {
5482 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5483 + subscriberId + " to " + number);
5484 }
5485
5486 if (TextUtils.isEmpty(iccId)) {
5487 return false;
5488 }
5489
5490 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5491
5492 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5493 if (alphaTag == null) {
5494 editor.remove(alphaTagPrefKey);
5495 } else {
5496 editor.putString(alphaTagPrefKey, alphaTag);
5497 }
5498
5499 // Record both the line number and IMSI for this ICCID, since we need to
5500 // track all merged IMSIs based on line number
5501 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5502 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5503 if (number == null) {
5504 editor.remove(numberPrefKey);
5505 editor.remove(subscriberPrefKey);
5506 } else {
5507 editor.putString(numberPrefKey, number);
5508 editor.putString(subscriberPrefKey, subscriberId);
5509 }
5510
5511 editor.commit();
5512 return true;
5513 } finally {
5514 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005515 }
Derek Tan7226c842014-07-02 17:42:23 -07005516 }
5517
5518 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005519 public String getLine1NumberForDisplay(int subId, String callingPackage,
5520 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005521 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005522 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005523 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005524 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005525 return null;
5526 }
Derek Tan97ebb422014-09-05 16:55:38 -07005527
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005528 final long identity = Binder.clearCallingIdentity();
5529 try {
5530 String iccId = getIccId(subId);
5531 if (iccId != null) {
5532 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5533 if (DBG_MERGE) {
5534 log("getLine1NumberForDisplay returning "
5535 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5536 }
5537 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005538 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005539 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5540 return null;
5541 } finally {
5542 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005543 }
Derek Tan7226c842014-07-02 17:42:23 -07005544 }
5545
5546 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005547 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5548 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005549 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005550 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005551 return null;
5552 }
Derek Tan97ebb422014-09-05 16:55:38 -07005553
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005554 final long identity = Binder.clearCallingIdentity();
5555 try {
5556 String iccId = getIccId(subId);
5557 if (iccId != null) {
5558 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5559 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5560 }
5561 return null;
5562 } finally {
5563 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005564 }
Derek Tan7226c842014-07-02 17:42:23 -07005565 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005566
5567 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005568 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5569 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005570 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5571 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005572 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005573 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005574 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005575 return null;
5576 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005577
Jordan Liub49b04b2019-05-06 14:45:15 -07005578 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5579 // the process, where TelephonyManager was instantiated.
5580 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005581 final long identity = Binder.clearCallingIdentity();
5582 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005583 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005584 final TelephonyManager tele = TelephonyManager.from(context);
5585 final SubscriptionManager sub = SubscriptionManager.from(context);
5586
5587 // Figure out what subscribers are currently active
5588 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005589
Jordan Liub49b04b2019-05-06 14:45:15 -07005590 // Only consider subs which match the current subId
5591 // This logic can be simplified. See b/131189269 for progress.
5592 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005593 activeSubscriberIds.add(tele.getSubscriberId(subId));
5594 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005595
5596 // First pass, find a number override for an active subscriber
5597 String mergeNumber = null;
5598 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5599 for (String key : prefs.keySet()) {
5600 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5601 final String subscriberId = (String) prefs.get(key);
5602 if (activeSubscriberIds.contains(subscriberId)) {
5603 final String iccId = key.substring(
5604 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5605 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5606 mergeNumber = (String) prefs.get(numberKey);
5607 if (DBG_MERGE) {
5608 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5609 + " for active subscriber " + subscriberId);
5610 }
5611 if (!TextUtils.isEmpty(mergeNumber)) {
5612 break;
5613 }
5614 }
5615 }
5616 }
5617
5618 // Shortcut when no active merged subscribers
5619 if (TextUtils.isEmpty(mergeNumber)) {
5620 return null;
5621 }
5622
5623 // Second pass, find all subscribers under that line override
5624 final ArraySet<String> result = new ArraySet<>();
5625 for (String key : prefs.keySet()) {
5626 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5627 final String number = (String) prefs.get(key);
5628 if (mergeNumber.equals(number)) {
5629 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5630 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5631 final String subscriberId = (String) prefs.get(subscriberKey);
5632 if (!TextUtils.isEmpty(subscriberId)) {
5633 result.add(subscriberId);
5634 }
5635 }
5636 }
5637 }
5638
5639 final String[] resultArray = result.toArray(new String[result.size()]);
5640 Arrays.sort(resultArray);
5641 if (DBG_MERGE) {
5642 Slog.d(LOG_TAG,
5643 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5644 }
5645 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005646 } finally {
5647 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005648 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005649 }
5650
5651 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005652 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5653 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5654
5655 final long identity = Binder.clearCallingIdentity();
5656 try {
5657 final TelephonyManager telephonyManager = mApp.getSystemService(
5658 TelephonyManager.class);
5659 String subscriberId = telephonyManager.getSubscriberId(subId);
5660 if (subscriberId == null) {
5661 if (DBG) {
5662 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5663 + subId);
5664 }
5665 return null;
5666 }
5667
5668 final SubscriptionInfo info = SubscriptionController.getInstance()
5669 .getSubscriptionInfo(subId);
5670 final ParcelUuid groupUuid = info.getGroupUuid();
5671 // If it doesn't belong to any group, return just subscriberId of itself.
5672 if (groupUuid == null) {
5673 return new String[]{subscriberId};
5674 }
5675
5676 // Get all subscriberIds from the group.
5677 final List<String> mergedSubscriberIds = new ArrayList<>();
5678 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005679 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5680 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07005681 for (SubscriptionInfo subInfo : groupInfos) {
5682 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5683 if (subscriberId != null) {
5684 mergedSubscriberIds.add(subscriberId);
5685 }
5686 }
5687
5688 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5689 } finally {
5690 Binder.restoreCallingIdentity(identity);
5691
5692 }
5693 }
5694
5695 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005696 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08005697 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005698 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005699
5700 final long identity = Binder.clearCallingIdentity();
5701 try {
5702 final Phone phone = getPhone(subId);
5703 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5704 } finally {
5705 Binder.restoreCallingIdentity(identity);
5706 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005707 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005708
5709 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005710 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005711 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5712 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08005713 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5714 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005715
5716 final long identity = Binder.clearCallingIdentity();
5717 try {
5718 final Phone phone = getPhone(subId);
5719 if (phone == null) {
5720 return false;
5721 }
5722 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5723 cdmaNonRoamingList);
5724 } finally {
5725 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005726 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005727 }
5728
5729 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005730 @Deprecated
5731 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5732 enforceModifyPermission();
5733
5734 int returnValue = 0;
5735 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005736 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005737 if(result.exception == null) {
5738 if (result.result != null) {
5739 byte[] responseData = (byte[])(result.result);
5740 if(responseData.length > oemResp.length) {
5741 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5742 responseData.length + "bytes. Buffer Size is " +
5743 oemResp.length + "bytes.");
5744 }
5745 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5746 returnValue = responseData.length;
5747 }
5748 } else {
5749 CommandException ex = (CommandException) result.exception;
5750 returnValue = ex.getCommandError().ordinal();
5751 if(returnValue > 0) returnValue *= -1;
5752 }
5753 } catch (RuntimeException e) {
5754 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5755 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5756 if(returnValue > 0) returnValue *= -1;
5757 }
5758
5759 return returnValue;
5760 }
5761
5762 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005763 public void setRadioCapability(RadioAccessFamily[] rafs) {
5764 try {
5765 ProxyController.getInstance().setRadioCapability(rafs);
5766 } catch (RuntimeException e) {
5767 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5768 }
5769 }
5770
5771 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005772 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005773 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005774 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005775 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005776 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005777 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005778 final long identity = Binder.clearCallingIdentity();
5779 try {
chen xub97461a2018-10-26 14:17:57 -07005780 TelephonyPermissions
5781 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5782 mApp, phone.getSubId(), "getRadioAccessFamily");
5783 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005784 } finally {
5785 Binder.restoreCallingIdentity(identity);
5786 }
chen xub97461a2018-10-26 14:17:57 -07005787 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005788 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005789
5790 @Override
5791 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005792 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005793 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005794
5795 final long identity = Binder.clearCallingIdentity();
5796 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005797 ImsManager.getInstance(defaultPhone.getContext(),
5798 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005799 } finally {
5800 Binder.restoreCallingIdentity(identity);
5801 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005802 }
5803
5804 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005805 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005806 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005807 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5808 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005809 return false;
5810 }
Svet Ganovb320e182015-04-16 12:30:10 -07005811
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005812 final long identity = Binder.clearCallingIdentity();
5813 try {
5814 // Check the user preference and the system-level IMS setting. Even if the user has
5815 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5816 // In the long run, we may instead need to check if there exists a connection service
5817 // which can support video calling.
5818 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005819 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005820 return imsManager.isVtEnabledByPlatform()
5821 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5822 && imsManager.isVtEnabledByUser();
5823 } finally {
5824 Binder.restoreCallingIdentity(identity);
5825 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005826 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005827
Andrew Leea1239f22015-03-02 17:44:07 -08005828 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005829 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5830 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005831 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005832 mApp, subId, callingPackage, callingFeatureId,
5833 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005834 return false;
5835 }
5836
5837 final long identity = Binder.clearCallingIdentity();
5838 try {
5839 CarrierConfigManager configManager =
5840 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005841 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005842 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5843 } finally {
5844 Binder.restoreCallingIdentity(identity);
5845 }
Andrew Leea1239f22015-03-02 17:44:07 -08005846 }
5847
5848 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005849 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005850 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005851 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005852 return false;
5853 }
5854
5855 final long identity = Binder.clearCallingIdentity();
5856 try {
5857 CarrierConfigManager configManager =
5858 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005859 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005860 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5861 } finally {
5862 Binder.restoreCallingIdentity(identity);
5863 }
Andrew Leea1239f22015-03-02 17:44:07 -08005864 }
5865
Andrew Lee9431b832015-03-09 18:46:45 -07005866 @Override
5867 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07005868 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005869 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005870 }
5871
5872 @Override
5873 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005874 final long identity = Binder.clearCallingIdentity();
5875 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005876 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005877 } finally {
5878 Binder.restoreCallingIdentity(identity);
5879 }
Andrew Lee9431b832015-03-09 18:46:45 -07005880 }
5881
Hall Liuf6668912018-10-31 17:05:23 -07005882 /**
5883 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5884 * support for the feature and device firmware support.
5885 *
5886 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5887 */
5888 @Override
5889 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005890 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005891 final Phone phone = getPhone(subscriptionId);
5892 if (phone == null) {
5893 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5894 return false;
5895 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005896 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005897 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005898 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5899 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005900 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005901 return isCarrierSupported && isDeviceSupported;
5902 } finally {
5903 Binder.restoreCallingIdentity(identity);
5904 }
Hall Liu98187582018-01-22 19:15:32 -08005905 }
5906
Hall Liuf6668912018-10-31 17:05:23 -07005907 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005908 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5909 * RTT setting, will return true if the device and carrier both support RTT.
5910 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005911 */
5912 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005913 final long identity = Binder.clearCallingIdentity();
5914 try {
Hall Liu63767ec2019-12-11 23:58:20 +00005915 boolean isRttSupported = isRttSupported(subscriptionId);
5916 boolean isUserRttSettingOn = Settings.Secure.getInt(
5917 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
5918 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5919 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5920 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005921 } finally {
5922 Binder.restoreCallingIdentity(identity);
5923 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005924 }
5925
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005926 @Deprecated
5927 @Override
5928 public String getDeviceId(String callingPackage) {
5929 return getDeviceIdWithFeature(callingPackage, null);
5930 }
5931
Sanket Padawe7310cc72015-01-14 09:53:20 -08005932 /**
5933 * Returns the unique device ID of phone, for example, the IMEI for
5934 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5935 *
5936 * <p>Requires Permission:
5937 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5938 */
5939 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005940 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005941 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005942 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005943 return null;
5944 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005945 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005946 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005947 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005948 return null;
5949 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005950
5951 final long identity = Binder.clearCallingIdentity();
5952 try {
5953 return phone.getDeviceId();
5954 } finally {
5955 Binder.restoreCallingIdentity(identity);
5956 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005957 }
5958
Ping Sunc67b7c22016-03-02 19:16:45 +08005959 /**
5960 * {@hide}
5961 * Returns the IMS Registration Status on a particular subid
5962 *
5963 * @param subId
5964 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005965 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005966 Phone phone = getPhone(subId);
5967 if (phone != null) {
5968 return phone.isImsRegistered();
5969 } else {
5970 return false;
5971 }
5972 }
5973
Santos Cordon7a1885b2015-02-03 11:15:19 -08005974 @Override
5975 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005976 final long identity = Binder.clearCallingIdentity();
5977 try {
5978 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5979 } finally {
5980 Binder.restoreCallingIdentity(identity);
5981 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005982 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005983
Tyler Gunnf70ed162019-04-03 15:28:53 -07005984 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07005985 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005986 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07005987 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005988 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07005989 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5990 }
5991 final long identity = Binder.clearCallingIdentity();
5992 try {
5993 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5994 } finally {
5995 Binder.restoreCallingIdentity(identity);
5996 }
5997 }
5998
5999 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006000 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6001 final long identity = Binder.clearCallingIdentity();
6002 try {
6003 Phone phone = getPhone(subscriptionId);
6004 if (phone == null) {
6005 return null;
6006 }
6007 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6008 } finally {
6009 Binder.restoreCallingIdentity(identity);
6010 }
6011 }
6012
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006013 /**
6014 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006015 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006016 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006017 final long identity = Binder.clearCallingIdentity();
6018 try {
6019 Phone phone = getPhone(subId);
6020 if (phone != null) {
6021 return phone.isWifiCallingEnabled();
6022 } else {
6023 return false;
6024 }
6025 } finally {
6026 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006027 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006028 }
6029
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006030 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006031 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006032 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006033 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006034 final long identity = Binder.clearCallingIdentity();
6035 try {
6036 Phone phone = getPhone(subId);
6037 if (phone != null) {
6038 return phone.isVideoEnabled();
6039 } else {
6040 return false;
6041 }
6042 } finally {
6043 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006044 }
6045 }
6046
6047 /**
6048 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6049 * defined in {@link ImsRegistrationImplBase}.
6050 */
6051 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006052 final long identity = Binder.clearCallingIdentity();
6053 try {
6054 Phone phone = getPhone(subId);
6055 if (phone != null) {
6056 return phone.getImsRegistrationTech();
6057 } else {
6058 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6059 }
6060 } finally {
6061 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006062 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006063 }
6064
Stuart Scott8eef64f2015-04-08 15:13:54 -07006065 @Override
6066 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006067 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006068 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6069 return;
6070 }
6071
Svet Ganovcc087f82015-05-12 20:35:54 -07006072 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006073
Svet Ganovcc087f82015-05-12 20:35:54 -07006074 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006075 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6076 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006077 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006078 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006079 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006080 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6081 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006082 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006083 // There has been issues when Sms raw table somehow stores orphan
6084 // fragments. They lead to garbled message when new fragments come
6085 // in and combined with those stale ones. In case this happens again,
6086 // user can reset all network settings which will clean up this table.
6087 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006088 // Clean up IMS settings as well here.
6089 int slotId = getSlotIndex(subId);
6090 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6091 ImsManager.getInstance(mApp, slotId).factoryReset();
6092 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006093
6094 // Erase modem config if erase modem on network setting is enabled.
6095 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6096 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6097 if (configValue != null && Boolean.parseBoolean(configValue)) {
6098 sendEraseModemConfig(getDefaultPhone());
6099 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006100 } finally {
6101 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006102 }
6103 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006104
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006105 private void cleanUpSmsRawTable(Context context) {
6106 ContentResolver resolver = context.getContentResolver();
6107 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6108 resolver.delete(uri, null, null);
6109 }
6110
Narayan Kamath1c496c22015-04-16 14:40:19 +01006111 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006112 public String getSimLocaleForSubscriber(int subId) {
6113 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6114 final Phone phone = getPhone(subId);
6115 if (phone == null) {
6116 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006117 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006118 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006119 final long identity = Binder.clearCallingIdentity();
6120 try {
chen xu5d3637b2019-01-21 23:31:38 -08006121 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006122 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08006123 if (info == null) {
6124 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6125 return null;
6126 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006127 // Try and fetch the locale from the carrier properties or from the SIM language
6128 // preferences (EF-PL and EF-LI)...
6129 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006130 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006131 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6132 if (localeFromDefaultSim != null) {
6133 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6134 if (DBG) log("Using locale from subId: " + subId + " locale: "
6135 + localeFromDefaultSim);
6136 return localeFromDefaultSim.toLanguageTag();
6137 } else {
6138 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006139 }
6140 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006141
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006142 // The SIM language preferences only store a language (e.g. fr = French), not an
6143 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6144 // the SIM and carrier preferences does not include a country we add the country
6145 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006146 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006147 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006148 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006149 return mccLocale.toLanguageTag();
6150 }
6151
6152 if (DBG) log("No locale found - returning null");
6153 return null;
6154 } finally {
6155 Binder.restoreCallingIdentity(identity);
6156 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006157 }
6158
6159 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006160 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6161 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006162 }
6163
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006164 /**
6165 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6166 */
6167 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006168 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6169 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006170 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006171
Chenjie Yu1ba97252018-01-11 18:16:20 -08006172 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006173 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006174
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006175 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006176 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6177 * representing the state of the modem.
6178 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006179 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6180 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006181 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006182 */
6183 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006184 public void requestModemActivityInfo(ResultReceiver result) {
6185 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006186 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006187
6188 final long identity = Binder.clearCallingIdentity();
6189 try {
6190 ModemActivityInfo ret = null;
6191 synchronized (mLastModemActivityInfo) {
6192 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6193 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006194 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006195 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006196 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xu13851032019-09-10 18:49:52 -07006197 int[] txTimeMs = info.getTransmitTimeMillis();
6198 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006199 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xu13851032019-09-10 18:49:52 -07006200 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006201 }
6202 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006203 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6204 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006205 mLastModemActivityInfo.setIdleTimeMillis(
6206 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xu13851032019-09-10 18:49:52 -07006207 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6208 mLastModemActivityInfo.setReceiveTimeMillis(
6209 info.getReceiveTimeMillis() + mLastModemActivityInfo
6210 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006211 }
Chen Xu13851032019-09-10 18:49:52 -07006212
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006213 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6214 mLastModemActivityInfo.getSleepTimeMillis(),
6215 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xu13851032019-09-10 18:49:52 -07006216 mLastModemActivityInfo.getTransmitTimeMillis(),
6217 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006218 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006219 Bundle bundle = new Bundle();
6220 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6221 result.send(0, bundle);
6222 } finally {
6223 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006224 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006225 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006226
Siddharth Rayb8114062018-06-17 15:02:38 -07006227 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6228 // less than total activity duration.
6229 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6230 if (info == null) {
6231 return false;
6232 }
6233 int activityDurationMs =
6234 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6235 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006236 int[] txTimeMs = info.getTransmitTimeMillis();
6237 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6238 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006239 }
6240 return (info.isValid()
6241 && (info.getSleepTimeMillis() <= activityDurationMs)
6242 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006243 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006244 && (totalTxTimeMs <= activityDurationMs));
6245 }
6246
Jack Yu85bd38a2015-11-09 11:34:32 -08006247 /**
6248 * {@hide}
6249 * Returns the service state information on specified subscription.
6250 */
6251 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006252 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6253 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006254 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006255 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006256 return null;
6257 }
6258
Hall Liuf19c44f2018-11-27 14:38:17 -08006259 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6260 LocationAccessPolicy.checkLocationPermission(mApp,
6261 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6262 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006263 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006264 .setCallingPid(Binder.getCallingPid())
6265 .setCallingUid(Binder.getCallingUid())
6266 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006267 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006268 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6269 .build());
6270
6271 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6272 LocationAccessPolicy.checkLocationPermission(mApp,
6273 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6274 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006275 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006276 .setCallingPid(Binder.getCallingPid())
6277 .setCallingUid(Binder.getCallingUid())
6278 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006279 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006280 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6281 .build());
6282 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6283 boolean hasFinePermission =
6284 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6285 boolean hasCoarsePermission =
6286 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6287
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006288 final long identity = Binder.clearCallingIdentity();
6289 try {
6290 final Phone phone = getPhone(subId);
6291 if (phone == null) {
6292 return null;
6293 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006294
Hall Liuf19c44f2018-11-27 14:38:17 -08006295 ServiceState ss = phone.getServiceState();
6296
6297 // Scrub out the location info in ServiceState depending on what level of access
6298 // the caller has.
6299 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006300 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6301 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006302 } finally {
6303 Binder.restoreCallingIdentity(identity);
6304 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006305 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006306
6307 /**
6308 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6309 *
6310 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6311 * voicemail ringtone.
6312 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6313 * PhoneAccount.
6314 */
6315 @Override
6316 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006317 final long identity = Binder.clearCallingIdentity();
6318 try {
6319 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6320 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006321 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006322 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006323
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006324 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6325 } finally {
6326 Binder.restoreCallingIdentity(identity);
6327 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006328 }
6329
6330 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006331 * Sets the per-account voicemail ringtone.
6332 *
6333 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6334 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6335 *
6336 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6337 * voicemail ringtone.
6338 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6339 * PhoneAccount.
6340 */
6341 @Override
6342 public void setVoicemailRingtoneUri(String callingPackage,
6343 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006344 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006345 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006346 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6347 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6349 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6350 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006351 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006352
6353 final long identity = Binder.clearCallingIdentity();
6354 try {
6355 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6356 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006357 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006358 }
6359 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6360 } finally {
6361 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006362 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006363 }
6364
6365 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006366 * Returns whether vibration is set for voicemail notification in Phone settings.
6367 *
6368 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6369 * voicemail vibration setting.
6370 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6371 */
6372 @Override
6373 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006374 final long identity = Binder.clearCallingIdentity();
6375 try {
6376 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6377 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006378 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006379 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006380
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006381 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6382 } finally {
6383 Binder.restoreCallingIdentity(identity);
6384 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006385 }
6386
Youhan Wange64578a2016-05-02 15:32:42 -07006387 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006388 * Sets the per-account voicemail vibration.
6389 *
6390 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6391 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6392 *
6393 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6394 * voicemail vibration setting.
6395 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6396 * specific PhoneAccount.
6397 */
6398 @Override
6399 public void setVoicemailVibrationEnabled(String callingPackage,
6400 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006401 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006402 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006403 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6404 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006405 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6406 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6407 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006408 }
6409
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006410 final long identity = Binder.clearCallingIdentity();
6411 try {
6412 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6413 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006414 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006415 }
6416 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6417 } finally {
6418 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006419 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006420 }
6421
6422 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006423 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6424 *
6425 * @throws SecurityException if the caller does not have the required permission
6426 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006427 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006428 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006429 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006430 }
6431
6432 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006433 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6434 * permission.
6435 *
6436 * @throws SecurityException if the caller does not have the required permission
6437 */
6438 private void enforceSendSmsPermission() {
6439 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6440 }
6441
6442 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006443 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006444 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006445 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006446 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006447 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006448 final long identity = Binder.clearCallingIdentity();
6449 try {
6450 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006451 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006452 if (componentName == null) {
6453 throw new SecurityException(
6454 "Caller not current active visual voicemail package[null]");
6455 }
6456 String vvmPackage = componentName.getPackageName();
6457 if (!callingPackage.equals(vvmPackage)) {
6458 throw new SecurityException("Caller not current active visual voicemail package["
6459 + vvmPackage + "]");
6460 }
6461 } finally {
6462 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006463 }
6464 }
6465
6466 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006467 * Return the application ID for the app type.
6468 *
6469 * @param subId the subscription ID that this request applies to.
6470 * @param appType the uicc app type.
6471 * @return Application ID for specificied app type, or null if no uicc.
6472 */
6473 @Override
6474 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006475 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006476 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006477
6478 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006479 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006480 if (phone == null) {
6481 return null;
6482 }
6483 String aid = null;
6484 try {
6485 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6486 .getApplicationByType(appType).getAid();
6487 } catch (Exception e) {
6488 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6489 }
6490 return aid;
6491 } finally {
6492 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006493 }
Youhan Wange64578a2016-05-02 15:32:42 -07006494 }
6495
Youhan Wang4001d252016-05-11 10:29:41 -07006496 /**
6497 * Return the Electronic Serial Number.
6498 *
6499 * @param subId the subscription ID that this request applies to.
6500 * @return ESN or null if error.
6501 */
6502 @Override
6503 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006504 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006505 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006506
6507 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006508 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006509 if (phone == null) {
6510 return null;
6511 }
6512 String esn = null;
6513 try {
6514 esn = phone.getEsn();
6515 } catch (Exception e) {
6516 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6517 }
6518 return esn;
6519 } finally {
6520 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006521 }
Youhan Wang4001d252016-05-11 10:29:41 -07006522 }
6523
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006524 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006525 * Return the Preferred Roaming List Version.
6526 *
6527 * @param subId the subscription ID that this request applies to.
6528 * @return PRLVersion or null if error.
6529 */
6530 @Override
6531 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006532 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006533 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006534
6535 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006536 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006537 if (phone == null) {
6538 return null;
6539 }
6540 String cdmaPrlVersion = null;
6541 try {
6542 cdmaPrlVersion = phone.getCdmaPrlVersion();
6543 } catch (Exception e) {
6544 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6545 }
6546 return cdmaPrlVersion;
6547 } finally {
6548 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006549 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006550 }
6551
6552 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006553 * Get snapshot of Telephony histograms
6554 * @return List of Telephony histograms
6555 * @hide
6556 */
6557 @Override
6558 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006559 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6560 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006561
6562 final long identity = Binder.clearCallingIdentity();
6563 try {
6564 return RIL.getTelephonyRILTimingHistograms();
6565 } finally {
6566 Binder.restoreCallingIdentity(identity);
6567 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006568 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006569
6570 /**
6571 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006572 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6573 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006574 * Require system privileges. In the future we may add this to carrier APIs.
6575 *
Michele Berionne482f8202018-11-27 18:57:59 -08006576 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006577 */
6578 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006579 @TelephonyManager.SetCarrierRestrictionResult
6580 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006581 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006582 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006583
Michele Berionne482f8202018-11-27 18:57:59 -08006584 if (carrierRestrictionRules == null) {
6585 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006586 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006587
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006588 final long identity = Binder.clearCallingIdentity();
6589 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006590 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006591 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006592 } finally {
6593 Binder.restoreCallingIdentity(identity);
6594 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006595 }
6596
6597 /**
6598 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006599 * Get the allowed carrier list and the excluded carrier list, including the priority between
6600 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006601 * Require system privileges. In the future we may add this to carrier APIs.
6602 *
Michele Berionne482f8202018-11-27 18:57:59 -08006603 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006604 */
6605 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006606 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006607 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006608 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006609
6610 final long identity = Binder.clearCallingIdentity();
6611 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006612 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6613 if (response instanceof CarrierRestrictionRules) {
6614 return (CarrierRestrictionRules) response;
6615 }
6616 // Response is an Exception of some kind,
6617 // which is signalled to the user as a NULL retval
6618 return null;
6619 } catch (Exception e) {
6620 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6621 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006622 } finally {
6623 Binder.restoreCallingIdentity(identity);
6624 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006625 }
6626
fionaxu59545b42016-05-25 15:53:37 -07006627 /**
6628 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6629 * @param subId the subscription ID that this action applies to.
6630 * @param enabled control enable or disable metered apns.
6631 * {@hide}
6632 */
6633 @Override
6634 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6635 enforceModifyPermission();
6636 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006637
6638 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006639 if (phone == null) {
6640 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6641 return;
6642 }
6643 try {
6644 phone.carrierActionSetMeteredApnsEnabled(enabled);
6645 } catch (Exception e) {
6646 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006647 } finally {
6648 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006649 }
6650 }
6651
6652 /**
6653 * Action set from carrier signalling broadcast receivers to enable/disable radio
6654 * @param subId the subscription ID that this action applies to.
6655 * @param enabled control enable or disable radio.
6656 * {@hide}
6657 */
6658 @Override
6659 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6660 enforceModifyPermission();
6661 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006662
6663 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006664 if (phone == null) {
6665 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6666 return;
6667 }
6668 try {
6669 phone.carrierActionSetRadioEnabled(enabled);
6670 } catch (Exception e) {
6671 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006672 } finally {
6673 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006674 }
6675 }
6676
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006677 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006678 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6679 * network status based on which carrier apps could apply actions accordingly,
6680 * enable/disable default url handler for example.
6681 *
6682 * @param subId the subscription ID that this action applies to.
6683 * @param report control start/stop reporting the default network status.
6684 * {@hide}
6685 */
6686 @Override
6687 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6688 enforceModifyPermission();
6689 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006690
6691 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006692 if (phone == null) {
6693 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6694 return;
6695 }
6696 try {
6697 phone.carrierActionReportDefaultNetworkStatus(report);
6698 } catch (Exception e) {
6699 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006700 } finally {
6701 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006702 }
6703 }
6704
6705 /**
fionaxud9622282017-07-17 17:51:30 -07006706 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6707 * @param subId the subscription ID that this action applies to.
6708 * {@hide}
6709 */
6710 @Override
6711 public void carrierActionResetAll(int subId) {
6712 enforceModifyPermission();
6713 final Phone phone = getPhone(subId);
6714 if (phone == null) {
6715 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6716 return;
6717 }
6718 try {
6719 phone.carrierActionResetAll();
6720 } catch (Exception e) {
6721 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6722 }
6723 }
6724
6725 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006726 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6727 * bug report is being generated.
6728 */
6729 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006730 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006731 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6732 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006733 writer.println("Permission Denial: can't dump Phone from pid="
6734 + Binder.getCallingPid()
6735 + ", uid=" + Binder.getCallingUid()
6736 + "without permission "
6737 + android.Manifest.permission.DUMP);
6738 return;
6739 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006740 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006741 }
Jack Yueb89b242016-06-22 13:27:47 -07006742
Brad Ebingerdac2f002018-04-03 15:17:52 -07006743 @Override
6744 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6745 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6746 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006747 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6748 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006749 }
6750
Jack Yueb89b242016-06-22 13:27:47 -07006751 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006752 * Get aggregated video call data usage since boot.
6753 *
6754 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6755 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006756 * {@hide}
6757 */
6758 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006759 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006760 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6761 null);
6762
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006763 final long identity = Binder.clearCallingIdentity();
6764 try {
6765 // NetworkStatsService keeps tracking the active network interface and identity. It
6766 // records the delta with the corresponding network identity.
6767 // We just return the total video call data usage snapshot since boot.
6768 Phone phone = getPhone(subId);
6769 if (phone != null) {
6770 return phone.getVtDataUsage(perUidStats);
6771 }
6772 return null;
6773 } finally {
6774 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006775 }
Jack Yueb89b242016-06-22 13:27:47 -07006776 }
Jack Yu75ab2952016-07-08 14:29:33 -07006777
6778 /**
6779 * Policy control of data connection. Usually used when data limit is passed.
6780 * @param enabled True if enabling the data, otherwise disabling.
6781 * @param subId Subscription index
6782 * {@hide}
6783 */
6784 @Override
6785 public void setPolicyDataEnabled(boolean enabled, int subId) {
6786 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006787
6788 final long identity = Binder.clearCallingIdentity();
6789 try {
6790 Phone phone = getPhone(subId);
6791 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006792 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006793 }
6794 } finally {
6795 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006796 }
6797 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006798
6799 /**
6800 * Get Client request stats
6801 * @return List of Client Request Stats
6802 * @hide
6803 */
6804 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006805 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6806 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006807 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006808 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006809 return null;
6810 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006811 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006812
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006813 final long identity = Binder.clearCallingIdentity();
6814 try {
6815 if (phone != null) {
6816 return phone.getClientRequestStats();
6817 }
6818
6819 return null;
6820 } finally {
6821 Binder.restoreCallingIdentity(identity);
6822 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006823 }
6824
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006825 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006826 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006827 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006828 }
Jack Yueb4124c2017-02-16 15:32:43 -08006829
6830 /**
Grace Chen70990072017-03-24 17:21:30 -07006831 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006832 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006833 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006834 * @param state State of SIM (power down, power up, pass through)
6835 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6836 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6837 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006838 *
6839 **/
6840 @Override
Grace Chen70990072017-03-24 17:21:30 -07006841 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006842 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006843 Phone phone = PhoneFactory.getPhone(slotIndex);
6844
vagdeviaf9a5b92018-08-15 16:01:53 -07006845 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6846
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006847 final long identity = Binder.clearCallingIdentity();
6848 try {
6849 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006850 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006851 }
6852 } finally {
6853 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006854 }
6855 }
Shuo Qiandd210312017-04-12 22:11:33 +00006856
Tyler Gunn65d45c22017-06-05 11:22:26 -07006857 private boolean isUssdApiAllowed(int subId) {
6858 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006859 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006860 if (configManager == null) {
6861 return false;
6862 }
6863 PersistableBundle pb = configManager.getConfigForSubId(subId);
6864 if (pb == null) {
6865 return false;
6866 }
6867 return pb.getBoolean(
6868 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6869 }
6870
Shuo Qiandd210312017-04-12 22:11:33 +00006871 /**
6872 * Check if phone is in emergency callback mode
6873 * @return true if phone is in emergency callback mode
6874 * @param subId sub id
6875 */
goneil9c5f4872017-12-05 14:07:56 -08006876 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006877 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006878 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006879 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006880
6881 final long identity = Binder.clearCallingIdentity();
6882 try {
6883 if (phone != null) {
6884 return phone.isInEcm();
6885 } else {
6886 return false;
6887 }
6888 } finally {
6889 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006890 }
6891 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006892
6893 /**
6894 * Get the current signal strength information for the given subscription.
6895 * Because this information is not updated when the device is in a low power state
6896 * it should not be relied-upon to be current.
6897 * @param subId Subscription index
6898 * @return the most recent cached signal strength info from the modem
6899 */
6900 @Override
6901 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006902 final long identity = Binder.clearCallingIdentity();
6903 try {
6904 Phone p = getPhone(subId);
6905 if (p == null) {
6906 return null;
6907 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006908
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006909 return p.getSignalStrength();
6910 } finally {
6911 Binder.restoreCallingIdentity(identity);
6912 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006913 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006914
Pengquan Meng77b7f132018-08-22 14:49:57 -07006915 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006916 * Get the current modem radio state for the given slot.
6917 * @param slotIndex slot index.
6918 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006919 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00006920 * @return the current radio power state from the modem
6921 */
6922 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006923 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00006924 Phone phone = PhoneFactory.getPhone(slotIndex);
6925 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006926 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
6927 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00006928 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6929 }
6930
6931 final long identity = Binder.clearCallingIdentity();
6932 try {
6933 return phone.getRadioPowerState();
6934 } finally {
6935 Binder.restoreCallingIdentity(identity);
6936 }
6937 }
6938 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6939 }
6940
6941 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006942 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6943 *
6944 * <p>Requires one of the following permissions:
6945 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6946 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6947 * privileges.
6948 *
6949 * @param subId subscription id
6950 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6951 * {@code false}.
6952 */
6953 @Override
6954 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006955 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6956 null /* message */);
6957
Pengquan Menga1bb6272018-09-06 09:59:22 -07006958 boolean isEnabled = false;
6959 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006960 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006961 Phone phone = getPhone(subId);
6962 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006963 } catch (Exception e) {
6964 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6965 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006966 } finally {
6967 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006968 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006969 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006970 }
6971
6972
6973 /**
6974 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6975 *
6976 * <p> Requires permission:
6977 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6978 * privileges.
6979 *
6980 * @param subId subscription id
6981 * @param isEnabled {@code true} means enable, {@code false} means disable.
6982 */
6983 @Override
6984 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006985 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6986 mApp, subId, "setDataRoamingEnabled");
6987
Pengquan Menga1bb6272018-09-06 09:59:22 -07006988 final long identity = Binder.clearCallingIdentity();
6989 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006990 Phone phone = getPhone(subId);
6991 if (phone != null) {
6992 phone.setDataRoamingEnabled(isEnabled);
6993 }
6994 } finally {
6995 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006996 }
6997 }
6998
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006999 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007000 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007001 TelephonyPermissions
7002 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007003 mApp, subId, "isManualNetworkSelectionAllowed");
7004
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007005 boolean isAllowed = true;
7006 final long identity = Binder.clearCallingIdentity();
7007 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007008 Phone phone = getPhone(subId);
7009 if (phone != null) {
7010 isAllowed = phone.isCspPlmnEnabled();
7011 }
7012 } finally {
7013 Binder.restoreCallingIdentity(identity);
7014 }
7015 return isAllowed;
7016 }
7017
7018 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007019 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007020 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007021 try {
7022 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007023 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007024 } catch (SecurityException e) {
7025 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7026 // has carrier privileges on an active UICC
7027 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7028 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007029 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007030 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007031 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007032
7033 final long identity = Binder.clearCallingIdentity();
7034 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007035 UiccController uiccController = UiccController.getInstance();
7036 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007037 if (hasReadPermission) {
7038 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007039 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007040
7041 // Remove private info if the caller doesn't have access
7042 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7043 for (UiccCardInfo cardInfo : cardInfos) {
7044 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7045 // is available
7046 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7047 if (card == null || card.getUiccProfile() == null) {
7048 // assume no access if the card or profile is unavailable
7049 filteredInfos.add(cardInfo.getUnprivileged());
7050 continue;
7051 }
7052 UiccProfile profile = card.getUiccProfile();
7053 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7054 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7055 filteredInfos.add(cardInfo);
7056 } else {
7057 filteredInfos.add(cardInfo.getUnprivileged());
7058 }
7059 }
7060 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007061 } finally {
7062 Binder.restoreCallingIdentity(identity);
7063 }
7064 }
7065
7066 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007067 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007068 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007069
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007070 final long identity = Binder.clearCallingIdentity();
7071 try {
7072 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7073 if (slots == null) {
7074 Rlog.i(LOG_TAG, "slots is null.");
7075 return null;
7076 }
7077
7078 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7079 for (int i = 0; i < slots.length; i++) {
7080 UiccSlot slot = slots[i];
7081 if (slot == null) {
7082 continue;
7083 }
7084
Jordan Liu7be7e652019-05-06 18:55:02 +00007085 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007086 UiccCard card = slot.getUiccCard();
7087 if (card != null) {
7088 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007089 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007090 cardId = slot.getEid();
7091 if (TextUtils.isEmpty(cardId)) {
7092 cardId = slot.getIccId();
7093 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007094 }
7095
Jordan Liu857451f2019-05-09 16:35:35 -07007096 if (cardId != null) {
7097 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7098 // if cardId is an EID, it's all digits so this is fine
7099 cardId = IccUtils.stripTrailingFs(cardId);
7100 }
7101
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007102 int cardState = 0;
7103 switch (slot.getCardState()) {
7104 case CARDSTATE_ABSENT:
7105 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7106 break;
7107 case CARDSTATE_PRESENT:
7108 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7109 break;
7110 case CARDSTATE_ERROR:
7111 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7112 break;
7113 case CARDSTATE_RESTRICTED:
7114 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7115 break;
7116 default:
7117 break;
7118
7119 }
7120
7121 infos[i] = new UiccSlotInfo(
7122 slot.isActive(),
7123 slot.isEuicc(),
7124 cardId,
7125 cardState,
7126 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007127 slot.isExtendedApduSupported(),
7128 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007129 }
7130 return infos;
7131 } finally {
7132 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007133 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007134 }
7135
7136 @Override
7137 public boolean switchSlots(int[] physicalSlots) {
7138 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007139
7140 final long identity = Binder.clearCallingIdentity();
7141 try {
7142 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7143 } finally {
7144 Binder.restoreCallingIdentity(identity);
7145 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007146 }
Jack Yu4c988042018-02-27 15:30:01 -08007147
7148 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007149 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007150 final long identity = Binder.clearCallingIdentity();
7151 try {
7152 return UiccController.getInstance().getCardIdForDefaultEuicc();
7153 } finally {
7154 Binder.restoreCallingIdentity(identity);
7155 }
7156 }
7157
7158 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007159 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7160 enforceModifyPermission();
7161 final Phone phone = getPhone(subId);
7162 if (phone == null) {
7163 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7164 return;
7165 }
7166
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007167 final long identity = Binder.clearCallingIdentity();
7168 try {
7169 phone.setRadioIndicationUpdateMode(filters, mode);
7170 } finally {
7171 Binder.restoreCallingIdentity(identity);
7172 }
Jack Yu4c988042018-02-27 15:30:01 -08007173 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007174
7175 /**
goneil47ffb6e2018-04-06 15:40:58 -07007176 * A test API to reload the UICC profile.
7177 *
7178 * <p>Requires that the calling app has permission
7179 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7180 * @hide
7181 */
7182 @Override
7183 public void refreshUiccProfile(int subId) {
7184 enforceModifyPermission();
7185
7186 final long identity = Binder.clearCallingIdentity();
7187 try {
7188 Phone phone = getPhone(subId);
7189 if (phone == null) {
7190 return;
7191 }
7192 UiccCard uiccCard = phone.getUiccCard();
7193 if (uiccCard == null) {
7194 return;
7195 }
7196 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7197 if (uiccProfile == null) {
7198 return;
7199 }
7200 uiccProfile.refresh();
7201 } finally {
7202 Binder.restoreCallingIdentity(identity);
7203 }
7204 }
7205
7206 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007207 * Returns false if the mobile data is disabled by default, otherwise return true.
7208 */
7209 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007210 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007211 }
7212
7213 /**
7214 * Returns true if the data roaming is enabled by default, i.e the system property
7215 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7216 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7217 */
7218 private boolean getDefaultDataRoamingEnabled(int subId) {
7219 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007220 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007221 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007222 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7223 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7224 return isDataRoamingEnabled;
7225 }
7226
7227 /**
7228 * Returns the default network type for the given {@code subId}, if the default network type is
7229 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7230 */
7231 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007232 List<Integer> list = TelephonyProperties.default_network();
7233 int phoneId = mSubscriptionController.getPhoneId(subId);
7234 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7235 return list.get(phoneId);
7236 }
7237 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007238 }
fionaxua13278b2018-03-21 00:08:13 -07007239
7240 @Override
7241 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007242 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007243 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007244
7245 final long identity = Binder.clearCallingIdentity();
7246 try {
7247 final Phone phone = getPhone(subId);
7248 if (phone == null) {
7249 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7250 return;
7251 }
chen xueaba88a2019-03-15 13:15:10 -07007252 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7253 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007254 } finally {
7255 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007256 }
fionaxua13278b2018-03-21 00:08:13 -07007257 }
7258
7259 @Override
7260 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007261 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007262
7263 final long identity = Binder.clearCallingIdentity();
7264 try {
7265 final Phone phone = getPhone(subId);
7266 if (phone == null) {
7267 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7268 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7269 }
7270 return phone.getCarrierIdListVersion();
7271 } finally {
7272 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007273 }
fionaxua13278b2018-03-21 00:08:13 -07007274 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007275
7276 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007277 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7278 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007279 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007280 mApp, subId, callingPackage, callingFeatureId,
7281 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007282 return -1;
7283 }
7284
7285 final long identity = Binder.clearCallingIdentity();
7286 try {
7287 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7288 } finally {
7289 Binder.restoreCallingIdentity(identity);
7290 }
7291 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007292
7293 @Override
7294 public int getCdmaRoamingMode(int subId) {
7295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7296 mApp, subId, "getCdmaRoamingMode");
7297
7298 final long identity = Binder.clearCallingIdentity();
7299 try {
7300 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7301 } finally {
7302 Binder.restoreCallingIdentity(identity);
7303 }
7304 }
7305
7306 @Override
7307 public boolean setCdmaRoamingMode(int subId, int mode) {
7308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7309 mApp, subId, "setCdmaRoamingMode");
7310
7311 final long identity = Binder.clearCallingIdentity();
7312 try {
7313 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7314 } finally {
7315 Binder.restoreCallingIdentity(identity);
7316 }
7317 }
7318
7319 @Override
7320 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7322 mApp, subId, "setCdmaSubscriptionMode");
7323
7324 final long identity = Binder.clearCallingIdentity();
7325 try {
7326 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7327 } finally {
7328 Binder.restoreCallingIdentity(identity);
7329 }
7330 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007331
sqianc5eccab2018-10-19 18:46:41 -07007332 @Override
sqian8c685422019-02-22 15:55:18 -08007333 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007334 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007335 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007336 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7337 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007338 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7339 }
7340 final long identity = Binder.clearCallingIdentity();
7341 try {
sqian854d44b2018-12-12 16:48:18 -08007342 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7343 for (Phone phone: PhoneFactory.getPhones()) {
7344 if (phone.getEmergencyNumberTracker() != null
7345 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7346 emergencyNumberListInternal.put(
7347 phone.getSubId(),
7348 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7349 }
sqian11b7a0e2018-12-05 18:48:28 -08007350 }
sqian854d44b2018-12-12 16:48:18 -08007351 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007352 } finally {
7353 Binder.restoreCallingIdentity(identity);
7354 }
sqianc5eccab2018-10-19 18:46:41 -07007355 }
7356
7357 @Override
sqian8c685422019-02-22 15:55:18 -08007358 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007359 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007360 if (!exactMatch) {
7361 TelephonyPermissions
7362 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007363 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007364 }
7365 final long identity = Binder.clearCallingIdentity();
7366 try {
sqian854d44b2018-12-12 16:48:18 -08007367 for (Phone phone: PhoneFactory.getPhones()) {
7368 if (phone.getEmergencyNumberTracker() != null
7369 && phone.getEmergencyNumberTracker() != null) {
7370 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7371 number, exactMatch)) {
7372 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007373 }
7374 }
sqian11b7a0e2018-12-05 18:48:28 -08007375 }
7376 return false;
7377 } finally {
7378 Binder.restoreCallingIdentity(identity);
7379 }
7380 }
7381
sqianf4ca7ed2019-01-15 18:32:07 -08007382 /**
7383 * Update emergency number list for test mode.
7384 */
7385 @Override
7386 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7387 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7388 "updateEmergencyNumberListTestMode");
7389
7390 final long identity = Binder.clearCallingIdentity();
7391 try {
7392 for (Phone phone: PhoneFactory.getPhones()) {
7393 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7394 if (tracker != null) {
7395 tracker.executeEmergencyNumberTestModeCommand(action, num);
7396 }
7397 }
7398 } finally {
7399 Binder.restoreCallingIdentity(identity);
7400 }
7401 }
7402
7403 /**
7404 * Get the full emergency number list for test mode.
7405 */
7406 @Override
7407 public List<String> getEmergencyNumberListTestMode() {
7408 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7409 "getEmergencyNumberListTestMode");
7410
7411 final long identity = Binder.clearCallingIdentity();
7412 try {
7413 Set<String> emergencyNumbers = new HashSet<>();
7414 for (Phone phone: PhoneFactory.getPhones()) {
7415 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7416 if (tracker != null) {
7417 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7418 emergencyNumbers.add(num.getNumber());
7419 }
7420 }
7421 }
7422 return new ArrayList<>(emergencyNumbers);
7423 } finally {
7424 Binder.restoreCallingIdentity(identity);
7425 }
7426 }
7427
chen xud6b45bd2018-10-30 22:27:10 -07007428 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007429 public int getEmergencyNumberDbVersion(int subId) {
7430 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7431
7432 final long identity = Binder.clearCallingIdentity();
7433 try {
7434 final Phone phone = getPhone(subId);
7435 if (phone == null) {
7436 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7437 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7438 }
7439 return phone.getEmergencyNumberDbVersion();
7440 } finally {
7441 Binder.restoreCallingIdentity(identity);
7442 }
7443 }
7444
7445 @Override
7446 public void notifyOtaEmergencyNumberDbInstalled() {
7447 enforceModifyPermission();
7448
7449 final long identity = Binder.clearCallingIdentity();
7450 try {
7451 for (Phone phone: PhoneFactory.getPhones()) {
7452 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7453 if (tracker != null) {
7454 tracker.updateOtaEmergencyNumberDatabase();
7455 }
7456 }
7457 } finally {
7458 Binder.restoreCallingIdentity(identity);
7459 }
7460 }
7461
7462 @Override
7463 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7464 enforceActiveEmergencySessionPermission();
7465
7466 final long identity = Binder.clearCallingIdentity();
7467 try {
7468 for (Phone phone: PhoneFactory.getPhones()) {
7469 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7470 if (tracker != null) {
7471 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7472 }
7473 }
7474 } finally {
7475 Binder.restoreCallingIdentity(identity);
7476 }
7477 }
7478
7479 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007480 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7481 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7482 Phone phone = getPhone(subId);
7483 if (phone == null) {
7484 return null;
7485 }
7486 final long identity = Binder.clearCallingIdentity();
7487 try {
7488 UiccProfile profile = UiccController.getInstance()
7489 .getUiccProfileForPhone(phone.getPhoneId());
7490 if (profile != null) {
7491 return profile.getCertsFromCarrierPrivilegeAccessRules();
7492 }
7493 } finally {
7494 Binder.restoreCallingIdentity(identity);
7495 }
7496 return null;
7497 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007498
7499 /**
7500 * Enable or disable a modem stack.
7501 */
7502 @Override
7503 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7504 enforceModifyPermission();
7505
7506 final long identity = Binder.clearCallingIdentity();
7507 try {
7508 Phone phone = PhoneFactory.getPhone(slotIndex);
7509 if (phone == null) {
7510 return false;
7511 } else {
7512 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7513 }
7514 } finally {
7515 Binder.restoreCallingIdentity(identity);
7516 }
7517 }
Michelecea4cf22018-12-21 15:00:11 -08007518
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007519 /**
7520 * Whether a modem stack is enabled or not.
7521 */
7522 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007523 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7524 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007525 Phone phone = PhoneFactory.getPhone(slotIndex);
7526 if (phone == null) return false;
7527
7528 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007529 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7530 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007531 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7532 }
7533
7534 final long identity = Binder.clearCallingIdentity();
7535 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007536 try {
7537 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7538 } catch (NoSuchElementException ex) {
7539 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7540 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007541 } finally {
7542 Binder.restoreCallingIdentity(identity);
7543 }
7544 }
7545
Michelecea4cf22018-12-21 15:00:11 -08007546 @Override
Michele0ea7d782019-03-19 14:58:42 -07007547 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007548 enforceModifyPermission();
7549
7550 final long identity = Binder.clearCallingIdentity();
7551 try {
7552 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007553 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007554 .commit();
7555 } finally {
7556 Binder.restoreCallingIdentity(identity);
7557 }
7558 }
7559
7560 @Override
Michele0ea7d782019-03-19 14:58:42 -07007561 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007562 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007563 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007564 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7565 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007566 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007567 }
Michelecea4cf22018-12-21 15:00:11 -08007568
7569 final long identity = Binder.clearCallingIdentity();
7570 try {
Michele0ea7d782019-03-19 14:58:42 -07007571 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007572 } finally {
7573 Binder.restoreCallingIdentity(identity);
7574 }
7575 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007576
Michele0ea7d782019-03-19 14:58:42 -07007577 @TelephonyManager.IsMultiSimSupportedResult
7578 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007579 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7580 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7581 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007582 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7583 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007584 }
7585 // Check if the hardware supports multisim functionality. If usage of multisim is not
7586 // supported by the modem, indicate that it is restricted.
7587 PhoneCapability staticCapability =
7588 mPhoneConfigurationManager.getStaticPhoneCapability();
7589 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007590 loge("isMultiSimSupportedInternal: no static configuration available");
7591 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007592 }
7593 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007594 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7595 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007596 }
7597 // Check if support of multiple SIMs is restricted by carrier
7598 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007599 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007600 }
7601
Michele0ea7d782019-03-19 14:58:42 -07007602 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007603 }
7604
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007605 /**
7606 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007607 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7608 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7609 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007610 * @param numOfSims number of active sims we want to switch to
7611 */
7612 @Override
7613 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007614 if (numOfSims == 1) {
7615 enforceModifyPermission();
7616 } else {
7617 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7618 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7619 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007620 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007621
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007622 try {
Michele30b57b22019-03-01 12:01:14 -08007623 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007624 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007625 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7626 return;
7627 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007628 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7629 } finally {
7630 Binder.restoreCallingIdentity(identity);
7631 }
7632 }
7633
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007634 @Override
7635 public boolean isApplicationOnUicc(int subId, int appType) {
7636 enforceReadPrivilegedPermission("isApplicationOnUicc");
7637 Phone phone = getPhone(subId);
7638 if (phone == null) {
7639 return false;
7640 }
7641 final long identity = Binder.clearCallingIdentity();
7642 try {
7643 UiccCard uiccCard = phone.getUiccCard();
7644 if (uiccCard == null) {
7645 return false;
7646 }
7647 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7648 if (uiccProfile == null) {
7649 return false;
7650 }
7651 if (TelephonyManager.APPTYPE_SIM <= appType
7652 && appType <= TelephonyManager.APPTYPE_ISIM) {
7653 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7654 }
7655 return false;
7656 } finally {
7657 Binder.restoreCallingIdentity(identity);
7658 }
7659 }
7660
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007661 /**
chen xub4baa772019-04-03 10:23:41 -07007662 * Get whether making changes to modem configurations will trigger reboot.
7663 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007664 */
7665 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007666 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7667 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007668 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007669 mApp, subId, callingPackage, callingFeatureId,
7670 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007671 return false;
7672 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007673 final long identity = Binder.clearCallingIdentity();
7674 try {
7675 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7676 } finally {
7677 Binder.restoreCallingIdentity(identity);
7678 }
7679 }
7680
Nathan Harold29f5f052019-02-15 13:41:57 -08007681 private void updateModemStateMetrics() {
7682 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7683 // TODO: check the state for each modem if the api is ready.
7684 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7685 }
7686
Pengquan Meng3889a572019-01-23 11:16:29 -08007687 @Override
7688 public int[] getSlotsMapping() {
7689 enforceReadPrivilegedPermission("getSlotsMapping");
7690
7691 final long identity = Binder.clearCallingIdentity();
7692 try {
7693 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7694 // All logical slots should have a mapping to a physical slot.
7695 int[] logicalSlotsMapping = new int[phoneCount];
7696 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7697 for (int i = 0; i < slotInfos.length; i++) {
7698 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7699 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7700 }
7701 }
7702 return logicalSlotsMapping;
7703 } finally {
7704 Binder.restoreCallingIdentity(identity);
7705 }
7706 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007707
7708 /**
7709 * Get the IRadio HAL Version
7710 */
7711 @Override
7712 public int getRadioHalVersion() {
7713 Phone phone = getDefaultPhone();
7714 if (phone == null) return -1;
7715 HalVersion hv = phone.getHalVersion();
7716 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7717 return hv.major * 100 + hv.minor;
7718 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007719
7720 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007721 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7722 * corresponding network requests on a subId.
7723 *
7724 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007725 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007726 * 2) APN is un-metered for this subscription, or
7727 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7728 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7729 *
7730 * @return whether data is allowed for a apn type.
7731 *
7732 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007733 */
7734 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007735 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07007736 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7737 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007738
7739 // Now that all security checks passes, perform the operation as ourselves.
7740 final long identity = Binder.clearCallingIdentity();
7741 try {
7742 Phone phone = getPhone(subId);
7743 if (phone == null) return false;
7744
Jack Yu41407ee2019-05-13 16:54:09 -07007745 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007746 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7747 } finally {
7748 Binder.restoreCallingIdentity(identity);
7749 }
7750 }
7751
7752 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007753 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007754 enforceReadPrivilegedPermission("isApnMetered");
7755
7756 // Now that all security checks passes, perform the operation as ourselves.
7757 final long identity = Binder.clearCallingIdentity();
7758 try {
7759 Phone phone = getPhone(subId);
7760 if (phone == null) return true; // By default return true.
7761
Jack Yu41407ee2019-05-13 16:54:09 -07007762 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007763 } finally {
7764 Binder.restoreCallingIdentity(identity);
7765 }
7766 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007767
7768 @Override
changbetty363e8ac2019-12-06 18:16:37 +08007769 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
7770 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
7771 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
7772 if (iccRecords == null) {
7773 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
7774 return false;
7775 }
7776 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
7777 }
7778
7779 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07007780 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7781 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7782 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7783 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7784 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7785 }
7786 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7787 Intent intent = new Intent();
7788 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7789 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7790 // Bring up choose default SMS subscription dialog right now
7791 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7792 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7793 mApp.startActivity(intent);
7794 }
chen xud5ca2d52019-05-28 15:20:57 -07007795
7796 @Override
7797 public String getMmsUAProfUrl(int subId) {
7798 //TODO investigate if this API should require proper permission check in R b/133791609
7799 final long identity = Binder.clearCallingIdentity();
7800 try {
7801 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7802 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7803 } finally {
7804 Binder.restoreCallingIdentity(identity);
7805 }
7806 }
7807
7808 @Override
7809 public String getMmsUserAgent(int subId) {
7810 //TODO investigate if this API should require proper permission check in R b/133791609
7811 final long identity = Binder.clearCallingIdentity();
7812 try {
7813 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7814 .getString(com.android.internal.R.string.config_mms_user_agent);
7815 } finally {
7816 Binder.restoreCallingIdentity(identity);
7817 }
7818 }
Jack Yub07d4972019-05-28 16:12:25 -07007819
7820 @Override
7821 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7822 enforceModifyPermission();
7823
7824 // Now that all security checks passes, perform the operation as ourselves.
7825 final long identity = Binder.clearCallingIdentity();
7826 try {
7827 Phone phone = getPhone(subId);
7828 if (phone == null) return false;
7829
7830 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7831 } finally {
7832 Binder.restoreCallingIdentity(identity);
7833 }
7834 }
7835
7836 @Override
7837 public boolean isDataAllowedInVoiceCall(int subId) {
7838 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7839
7840 // Now that all security checks passes, perform the operation as ourselves.
7841 final long identity = Binder.clearCallingIdentity();
7842 try {
7843 Phone phone = getPhone(subId);
7844 if (phone == null) return false;
7845
7846 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7847 } finally {
7848 Binder.restoreCallingIdentity(identity);
7849 }
7850 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007851
7852 /**
7853 * Updates whether conference event pacakge handling is enabled.
7854 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7855 * otherwise.
7856 */
7857 @Override
7858 public void setCepEnabled(boolean isCepEnabled) {
7859 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7860
7861 final long identity = Binder.clearCallingIdentity();
7862 try {
7863 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7864 for (Phone phone : PhoneFactory.getPhones()) {
7865 Phone defaultPhone = phone.getImsPhone();
7866 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7867 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7868 ImsPhoneCallTracker imsPhoneCallTracker =
7869 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7870 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7871 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7872 + imsPhone.getMsisdn());
7873 }
7874 }
7875 } finally {
7876 Binder.restoreCallingIdentity(identity);
7877 }
7878 }
allenwtsu46dcc572020-01-08 18:24:03 +08007879
7880 /**
7881 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
7882 *
7883 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
7884 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
7885 * before being read.
7886 */
7887 @Override
7888 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
7889 isCompressed) {
7890 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7891 mApp, subId, "notifyRcsAutoConfigurationReceived");
7892 try {
7893 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
7894 if (configBinder == null) {
7895 Rlog.e(LOG_TAG, "null result for getImsConfig");
7896 } else {
7897 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
7898 }
7899 } catch (RemoteException e) {
7900 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
7901 }
7902 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007903}