blob: 1987756c97612709efec19657777d694569e5cf7 [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080088import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080089import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070091import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070092import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080093import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080094import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000095import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070096import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070097import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080098import android.telephony.data.ApnSetting;
99import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700100import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800101import android.telephony.ims.ProvisioningManager;
Brad Ebinger774ba362019-10-22 17:36:18 -0700102import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700103import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800104import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700105import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800106import android.telephony.ims.aidl.IImsMmTelFeature;
107import android.telephony.ims.aidl.IImsRcsFeature;
108import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700109import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700110import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800111import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800112import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800113import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800114import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800116import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800118import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800119import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800120
Andrew Lee312e8172014-10-23 17:01:36 -0700121import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800122import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700124import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700125import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800126import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700127import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700128import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800130import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700131import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800132import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800134import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700135import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700136import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700137import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700139import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800140import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700141import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700142import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700143import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700144import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700145import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700146import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700147import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700148import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800149import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800150import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700151import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800152import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700153import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800154import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700155import com.android.internal.telephony.imsphone.ImsPhone;
156import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800157import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900158import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700159import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800160import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700161import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800162import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700163import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800164import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700165import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800166import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000167import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800168import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700169import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800170import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700171import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700172import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800173import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700174import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700175import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang050bb052020-01-13 23:33:09 -0800176import com.android.telephony.Rlog;
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
Peter Wang050bb052020-01-13 23:33:09 -08001457 private boolean isImsAvailableOnDevice() {
1458 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1459 if (pm == null) {
1460 // For some reason package manger is not available.. This will fail internally anyway,
1461 // so do not throw error and allow.
1462 return true;
1463 }
1464 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1465 }
1466
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001467 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001468 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001469 }
1470
Wink Savilleb564aae2014-10-23 10:18:09 -07001471 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001472 if (DBG) log("dial: " + number);
1473 // No permission check needed here: This is just a wrapper around the
1474 // ACTION_DIAL intent, which is available to any app since it puts up
1475 // the UI before it does anything.
1476
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001477 final long identity = Binder.clearCallingIdentity();
1478 try {
1479 String url = createTelUrl(number);
1480 if (url == null) {
1481 return;
1482 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001483
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001484 // PENDING: should we just silently fail if phone is offhook or ringing?
1485 PhoneConstants.State state = mCM.getState(subId);
1486 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1487 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1488 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1489 mApp.startActivity(intent);
1490 }
1491 } finally {
1492 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001493 }
1494 }
1495
1496 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001497 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001498 }
1499
Wink Savilleb564aae2014-10-23 10:18:09 -07001500 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001501 if (DBG) log("call: " + number);
1502
1503 // This is just a wrapper around the ACTION_CALL intent, but we still
1504 // need to do a permission check since we're calling startActivity()
1505 // from the context of the phone app.
1506 enforceCallPermission();
1507
Jordan Liu1617b712019-07-10 15:06:26 -07001508 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001509 != AppOpsManager.MODE_ALLOWED) {
1510 return;
1511 }
1512
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001513 final long identity = Binder.clearCallingIdentity();
1514 try {
1515 String url = createTelUrl(number);
1516 if (url == null) {
1517 return;
1518 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001519
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001520 boolean isValid = false;
1521 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1522 if (slist != null) {
1523 for (SubscriptionInfo subInfoRecord : slist) {
1524 if (subInfoRecord.getSubscriptionId() == subId) {
1525 isValid = true;
1526 break;
1527 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001528 }
Wink Saville08874612014-08-31 19:19:58 -07001529 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001530 if (!isValid) {
1531 return;
1532 }
Wink Saville08874612014-08-31 19:19:58 -07001533
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001534 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1535 intent.putExtra(SUBSCRIPTION_KEY, subId);
1536 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1537 mApp.startActivity(intent);
1538 } finally {
1539 Binder.restoreCallingIdentity(identity);
1540 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001541 }
1542
Wink Savilleb564aae2014-10-23 10:18:09 -07001543 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001544 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001545 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1546 }
1547
Wink Savilleb564aae2014-10-23 10:18:09 -07001548 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001549 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001550 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1551 }
1552
Wink Savilleb564aae2014-10-23 10:18:09 -07001553 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001555
1556 final long identity = Binder.clearCallingIdentity();
1557 try {
1558 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1559 checkSimPin.start();
1560 return checkSimPin.unlockSim(null, pin);
1561 } finally {
1562 Binder.restoreCallingIdentity(identity);
1563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001564 }
1565
Wink Savilleb564aae2014-10-23 10:18:09 -07001566 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001568
1569 final long identity = Binder.clearCallingIdentity();
1570 try {
1571 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1572 checkSimPuk.start();
1573 return checkSimPuk.unlockSim(puk, pin);
1574 } finally {
1575 Binder.restoreCallingIdentity(identity);
1576 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001577 }
1578
1579 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001580 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001581 * a synchronous one.
1582 */
1583 private static class UnlockSim extends Thread {
1584
1585 private final IccCard mSimCard;
1586
1587 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001588 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1589 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001590
1591 // For replies from SimCard interface
1592 private Handler mHandler;
1593
1594 // For async handler to identify request type
1595 private static final int SUPPLY_PIN_COMPLETE = 100;
1596
1597 public UnlockSim(IccCard simCard) {
1598 mSimCard = simCard;
1599 }
1600
1601 @Override
1602 public void run() {
1603 Looper.prepare();
1604 synchronized (UnlockSim.this) {
1605 mHandler = new Handler() {
1606 @Override
1607 public void handleMessage(Message msg) {
1608 AsyncResult ar = (AsyncResult) msg.obj;
1609 switch (msg.what) {
1610 case SUPPLY_PIN_COMPLETE:
1611 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1612 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001613 mRetryCount = msg.arg1;
1614 if (ar.exception != null) {
1615 if (ar.exception instanceof CommandException &&
1616 ((CommandException)(ar.exception)).getCommandError()
1617 == CommandException.Error.PASSWORD_INCORRECT) {
1618 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1619 } else {
1620 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1621 }
1622 } else {
1623 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1624 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001625 mDone = true;
1626 UnlockSim.this.notifyAll();
1627 }
1628 break;
1629 }
1630 }
1631 };
1632 UnlockSim.this.notifyAll();
1633 }
1634 Looper.loop();
1635 }
1636
1637 /*
1638 * Use PIN or PUK to unlock SIM card
1639 *
1640 * If PUK is null, unlock SIM card with PIN
1641 *
1642 * If PUK is not null, unlock SIM card with PUK and set PIN code
1643 */
Wink Saville9de0f752013-10-22 19:04:03 -07001644 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001645
1646 while (mHandler == null) {
1647 try {
1648 wait();
1649 } catch (InterruptedException e) {
1650 Thread.currentThread().interrupt();
1651 }
1652 }
1653 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1654
1655 if (puk == null) {
1656 mSimCard.supplyPin(pin, callback);
1657 } else {
1658 mSimCard.supplyPuk(puk, pin, callback);
1659 }
1660
1661 while (!mDone) {
1662 try {
1663 Log.d(LOG_TAG, "wait for done");
1664 wait();
1665 } catch (InterruptedException e) {
1666 // Restore the interrupted status
1667 Thread.currentThread().interrupt();
1668 }
1669 }
1670 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001671 int[] resultArray = new int[2];
1672 resultArray[0] = mResult;
1673 resultArray[1] = mRetryCount;
1674 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001675 }
1676 }
1677
1678 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001679 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001680
1681 }
1682
Wink Savilleb564aae2014-10-23 10:18:09 -07001683 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001684 // No permission check needed here: this call is harmless, and it's
1685 // needed for the ServiceState.requestStateUpdate() call (which is
1686 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001687 final long identity = Binder.clearCallingIdentity();
1688 try {
1689 final Phone phone = getPhone(subId);
1690 if (phone != null) {
1691 phone.updateServiceLocation();
1692 }
1693 } finally {
1694 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001695 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001696 }
1697
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001698 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001699 @Override
1700 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001701 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001702 }
1703
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001704 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001705 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1706 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1707 callingFeatureId);
1708 }
1709
1710 @Deprecated
1711 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001712 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001713 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
1714 }
1715
1716 @Override
1717 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1718 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001719 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001720 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001721 return false;
1722 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001723
1724 final long identity = Binder.clearCallingIdentity();
1725 try {
1726 return isRadioOnForSubscriber(subId);
1727 } finally {
1728 Binder.restoreCallingIdentity(identity);
1729 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001730 }
1731
1732 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001733 final long identity = Binder.clearCallingIdentity();
1734 try {
1735 final Phone phone = getPhone(subId);
1736 if (phone != null) {
1737 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1738 } else {
1739 return false;
1740 }
1741 } finally {
1742 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001743 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001744 }
1745
1746 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001747 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748 }
Wink Saville36469e72014-06-11 15:17:00 -07001749
Wink Savilleb564aae2014-10-23 10:18:09 -07001750 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001752
1753 final long identity = Binder.clearCallingIdentity();
1754 try {
1755 final Phone phone = getPhone(subId);
1756 if (phone != null) {
1757 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1758 }
1759 } finally {
1760 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001761 }
Wink Saville36469e72014-06-11 15:17:00 -07001762 }
1763
1764 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001765 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001766 }
1767
Wink Savilleb564aae2014-10-23 10:18:09 -07001768 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001769 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001770
1771 final long identity = Binder.clearCallingIdentity();
1772 try {
1773 final Phone phone = getPhone(subId);
1774 if (phone == null) {
1775 return false;
1776 }
1777 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1778 toggleRadioOnOffForSubscriber(subId);
1779 }
1780 return true;
1781 } finally {
1782 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001783 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001784 }
Wink Saville36469e72014-06-11 15:17:00 -07001785
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001786 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08001787 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001788 /*
1789 * If any of the Radios are available, it will need to be
1790 * shutdown. So return true if any Radio is available.
1791 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001792 final long identity = Binder.clearCallingIdentity();
1793 try {
1794 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1795 Phone phone = PhoneFactory.getPhone(i);
1796 if (phone != null && phone.isRadioAvailable()) return true;
1797 }
1798 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1799 return false;
1800 } finally {
1801 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001802 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001803 }
1804
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001805 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001806 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001807 enforceModifyPermission();
1808
1809 final long identity = Binder.clearCallingIdentity();
1810 try {
1811 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1812 logv("Shutting down Phone " + i);
1813 shutdownRadioUsingPhoneId(i);
1814 }
1815 } finally {
1816 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001817 }
1818 }
1819
1820 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001821 Phone phone = PhoneFactory.getPhone(phoneId);
1822 if (phone != null && phone.isRadioAvailable()) {
1823 phone.shutdownRadio();
1824 }
1825 }
1826
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001827 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001828 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001829
1830 final long identity = Binder.clearCallingIdentity();
1831 try {
1832 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1833 if (defaultPhone != null) {
1834 defaultPhone.setRadioPower(turnOn);
1835 return true;
1836 } else {
1837 loge("There's no default phone.");
1838 return false;
1839 }
1840 } finally {
1841 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001842 }
Wink Saville36469e72014-06-11 15:17:00 -07001843 }
1844
Wink Savilleb564aae2014-10-23 10:18:09 -07001845 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001847
1848 final long identity = Binder.clearCallingIdentity();
1849 try {
1850 final Phone phone = getPhone(subId);
1851 if (phone != null) {
1852 phone.setRadioPower(turnOn);
1853 return true;
1854 } else {
1855 return false;
1856 }
1857 } finally {
1858 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001860 }
1861
Wink Saville36469e72014-06-11 15:17:00 -07001862 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001863 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001864 public boolean enableDataConnectivity() {
1865 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001866
1867 final long identity = Binder.clearCallingIdentity();
1868 try {
1869 int subId = mSubscriptionController.getDefaultDataSubId();
1870 final Phone phone = getPhone(subId);
1871 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001872 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001873 return true;
1874 } else {
1875 return false;
1876 }
1877 } finally {
1878 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001879 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001880 }
1881
Wink Saville36469e72014-06-11 15:17:00 -07001882 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001883 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001884 public boolean disableDataConnectivity() {
1885 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001886
1887 final long identity = Binder.clearCallingIdentity();
1888 try {
1889 int subId = mSubscriptionController.getDefaultDataSubId();
1890 final Phone phone = getPhone(subId);
1891 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001892 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001893 return true;
1894 } else {
1895 return false;
1896 }
1897 } finally {
1898 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001899 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001900 }
1901
Sanket Padawe356d7632015-06-22 14:03:32 -07001902 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001903 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001904 final long identity = Binder.clearCallingIdentity();
1905 try {
1906 final Phone phone = getPhone(subId);
1907 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001908 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001909 } else {
1910 return false;
1911 }
1912 } finally {
1913 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001914 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001915 }
1916
1917 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001918 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001919 }
1920
pkanwarae03a6b2016-11-06 20:37:09 -08001921 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001922 enforceCallPermission();
1923
1924 final long identity = Binder.clearCallingIdentity();
1925 try {
1926 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1927 return;
1928 }
1929 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1930 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1931 } finally {
1932 Binder.restoreCallingIdentity(identity);
1933 }
pkanwar32d516d2016-10-14 19:37:38 -07001934 };
1935
Wink Savilleb564aae2014-10-23 10:18:09 -07001936 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001937 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001938
1939 final long identity = Binder.clearCallingIdentity();
1940 try {
1941 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1942 return false;
1943 }
1944 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1945 } finally {
1946 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001947 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001948 }
1949
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001950 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001951 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001952 }
1953
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001954 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001955 final long identity = Binder.clearCallingIdentity();
1956 try {
1957 Phone phone = PhoneFactory.getPhone(slotIndex);
1958 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1959 PhoneConstantConversions.convertCallState(phone.getState());
1960 } finally {
1961 Binder.restoreCallingIdentity(identity);
1962 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001963 }
1964
Sanket Padawe356d7632015-06-22 14:03:32 -07001965 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001966 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001967 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1968 }
1969
1970 @Override
1971 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001972 final long identity = Binder.clearCallingIdentity();
1973 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001974 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001975 if (phone != null) {
1976 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1977 } else {
1978 return PhoneConstantConversions.convertDataState(
1979 PhoneConstants.DataState.DISCONNECTED);
1980 }
1981 } finally {
1982 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001983 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001984 }
1985
Sanket Padawe356d7632015-06-22 14:03:32 -07001986 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001987 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001988 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1989 }
1990
1991 @Override
1992 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001993 final long identity = Binder.clearCallingIdentity();
1994 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001995 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001996 if (phone != null) {
1997 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1998 } else {
1999 return TelephonyManager.DATA_ACTIVITY_NONE;
2000 }
2001 } finally {
2002 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002003 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002004 }
2005
2006 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002007 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002008 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002009 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002010
2011 LocationAccessPolicy.LocationPermissionResult locationResult =
2012 LocationAccessPolicy.checkLocationPermission(mApp,
2013 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2014 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002015 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002016 .setCallingPid(Binder.getCallingPid())
2017 .setCallingUid(Binder.getCallingUid())
2018 .setMethod("getCellLocation")
2019 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2020 .build());
2021 switch (locationResult) {
2022 case DENIED_HARD:
2023 throw new SecurityException("Not allowed to access cell location");
2024 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002025 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2026 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002027 }
2028
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002029 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002030 final long identity = Binder.clearCallingIdentity();
2031 try {
2032 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002033 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002034 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002035 } finally {
2036 Binder.restoreCallingIdentity(identity);
2037 }
Svetoslav64fad262015-04-14 14:35:21 -07002038 }
2039
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002040 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002041 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2042 String callingFeatureId) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002043 if (!TextUtils.isEmpty(callingPackage)) {
2044 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002045 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2046 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002047 return "";
2048 }
2049 }
2050
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002051 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2052 // registered cell info, so return a NULL country instead.
2053 final long identity = Binder.clearCallingIdentity();
2054 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002055 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2056 // Get default phone in this case.
2057 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2058 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002059 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002060 // Todo: fix this when we can get the actual cellular network info when the device
2061 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002062 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002063 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2064 null)) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002065 return "";
2066 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002067 Phone phone = PhoneFactory.getPhone(phoneId);
2068 if (phone != null) {
2069 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002070 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002071 if (sst != null) {
2072 LocaleTracker lt = sst.getLocaleTracker();
2073 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002074 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2075 return lt.getCurrentCountry();
2076 } else if (emergencyNumberTracker != null) {
2077 return emergencyNumberTracker.getEmergencyCountryIso();
2078 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002079 }
2080 }
2081 }
2082 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002083 } finally {
2084 Binder.restoreCallingIdentity(identity);
2085 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002086 }
2087
2088 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002089 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002090 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002091 }
2092
Sanket Padawe356d7632015-06-22 14:03:32 -07002093 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002094 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 mApp.enforceCallingOrSelfPermission(
2096 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002097
2098 final long identity = Binder.clearCallingIdentity();
2099 try {
2100 final Phone phone = getPhone(subId);
2101 if (phone != null) {
2102 phone.enableLocationUpdates();
2103 }
2104 } finally {
2105 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002106 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002107 }
2108
2109 @Override
2110 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002111 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002112 }
2113
Sanket Padawe356d7632015-06-22 14:03:32 -07002114 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002115 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002116 mApp.enforceCallingOrSelfPermission(
2117 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002118
2119 final long identity = Binder.clearCallingIdentity();
2120 try {
2121 final Phone phone = getPhone(subId);
2122 if (phone != null) {
2123 phone.disableLocationUpdates();
2124 }
2125 } finally {
2126 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002127 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002128 }
2129
Nathan Harold31d7ff32018-10-15 20:20:30 -07002130 /**
2131 * Returns the target SDK version number for a given package name.
2132 *
Nathan Haroldec184742019-07-10 17:04:16 -07002133 * This call MUST be invoked before clearing the calling UID.
2134 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002135 * @return target SDK if the package is found or INT_MAX.
2136 */
2137 private int getTargetSdk(String packageName) {
2138 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002139 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002140 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002141 if (ai != null) return ai.targetSdkVersion;
2142 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002143 loge("Failed to get package info for pkg="
2144 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002145 }
2146 return Integer.MAX_VALUE;
2147 }
2148
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002149 @Override
2150 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002151 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2152 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002153 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002154 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2155 throw new SecurityException(
2156 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2157 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002158
Jordan Liu1617b712019-07-10 15:06:26 -07002159 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2161 return null;
2162 }
Svetoslav64fad262015-04-14 14:35:21 -07002163
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002164 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002165
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002166 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002167 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168
Nathan Haroldf180aac2018-06-01 18:43:55 -07002169 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2170 for (CellInfo ci : info) {
2171 if (ci instanceof CellInfoGsm) {
2172 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2173 } else if (ci instanceof CellInfoWcdma) {
2174 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2175 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002176 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002177 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002178 }
2179
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002180 private List<CellInfo> getCachedCellInfo() {
2181 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2182 for (Phone phone : PhoneFactory.getPhones()) {
2183 List<CellInfo> info = phone.getAllCellInfo();
2184 if (info != null) cellInfos.addAll(info);
2185 }
2186 return cellInfos;
2187 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002188
2189 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002190 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002191 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002192 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002193
2194 LocationAccessPolicy.LocationPermissionResult locationResult =
2195 LocationAccessPolicy.checkLocationPermission(mApp,
2196 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2197 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002198 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002199 .setCallingPid(Binder.getCallingPid())
2200 .setCallingUid(Binder.getCallingUid())
2201 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002202 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002203 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2204 .build());
2205 switch (locationResult) {
2206 case DENIED_HARD:
2207 throw new SecurityException("Not allowed to access cell info");
2208 case DENIED_SOFT:
2209 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 }
2211
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002212 final int targetSdk = getTargetSdk(callingPackage);
2213 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2214 return getCachedCellInfo();
2215 }
2216
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002217 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002218 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002219 final long identity = Binder.clearCallingIdentity();
2220 try {
2221 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2222 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002223 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002224 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002225 if (info != null) cellInfos.addAll(info);
2226 }
2227 return cellInfos;
2228 } finally {
2229 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002230 }
2231 }
2232
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002233 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002234 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2235 String callingFeatureId) {
2236 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2237 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002238 }
2239
2240 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002241 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2242 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002243 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002244 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002245 }
2246
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002247 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2248 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002249 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002250 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002251
2252 LocationAccessPolicy.LocationPermissionResult locationResult =
2253 LocationAccessPolicy.checkLocationPermission(mApp,
2254 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2255 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002256 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002257 .setCallingPid(Binder.getCallingPid())
2258 .setCallingUid(Binder.getCallingUid())
2259 .setMethod("requestCellInfoUpdate")
2260 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2261 .build());
2262 switch (locationResult) {
2263 case DENIED_HARD:
2264 throw new SecurityException("Not allowed to access cell info");
2265 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002266 try {
2267 cb.onCellInfo(new ArrayList<CellInfo>());
2268 } catch (RemoteException re) {
2269 // Drop without consequences
2270 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002271 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002272 }
2273
Nathan Harolda939a962019-05-09 10:13:47 -07002274
2275 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002276 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2277
2278 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2279 }
2280
2281 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002283 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002284 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002285
2286 final long identity = Binder.clearCallingIdentity();
2287 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002288 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002289 } finally {
2290 Binder.restoreCallingIdentity(identity);
2291 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002292 }
2293
Shishir Agrawala9f32182016-04-12 12:00:16 -07002294 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002295 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002296 Phone phone = PhoneFactory.getPhone(slotIndex);
2297 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002298 return null;
2299 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002300 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002301 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002302 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002303 return null;
2304 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002305
2306 final long identity = Binder.clearCallingIdentity();
2307 try {
2308 return phone.getImei();
2309 } finally {
2310 Binder.restoreCallingIdentity(identity);
2311 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002312 }
2313
2314 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002315 public String getTypeAllocationCodeForSlot(int slotIndex) {
2316 Phone phone = PhoneFactory.getPhone(slotIndex);
2317 String tac = null;
2318 if (phone != null) {
2319 String imei = phone.getImei();
2320 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2321 }
2322 return tac;
2323 }
2324
2325 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002326 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002327 Phone phone = PhoneFactory.getPhone(slotIndex);
2328 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002329 return null;
2330 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002331
Jeff Davidson913390f2018-02-23 17:11:49 -08002332 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002333 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002334 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002335 return null;
2336 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002337
2338 final long identity = Binder.clearCallingIdentity();
2339 try {
2340 return phone.getMeid();
2341 } finally {
2342 Binder.restoreCallingIdentity(identity);
2343 }
Jack Yu2af8d712017-03-15 17:14:14 -07002344 }
2345
2346 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002347 public String getManufacturerCodeForSlot(int slotIndex) {
2348 Phone phone = PhoneFactory.getPhone(slotIndex);
2349 String manufacturerCode = null;
2350 if (phone != null) {
2351 String meid = phone.getMeid();
2352 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2353 }
2354 return manufacturerCode;
2355 }
2356
2357 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002358 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2359 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002360 Phone phone = PhoneFactory.getPhone(slotIndex);
2361 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002362 return null;
2363 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002364 int subId = phone.getSubId();
2365 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002366 mApp, subId, callingPackage, callingFeatureId,
2367 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002368 return null;
2369 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002370
2371 final long identity = Binder.clearCallingIdentity();
2372 try {
2373 return phone.getDeviceSvn();
2374 } finally {
2375 Binder.restoreCallingIdentity(identity);
2376 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002377 }
2378
fionaxu43304da2017-11-27 22:51:16 -08002379 @Override
2380 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002381 final long identity = Binder.clearCallingIdentity();
2382 try {
2383 final Phone phone = getPhone(subId);
2384 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2385 } finally {
2386 Binder.restoreCallingIdentity(identity);
2387 }
fionaxu43304da2017-11-27 22:51:16 -08002388 }
2389
2390 @Override
2391 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002392 final long identity = Binder.clearCallingIdentity();
2393 try {
2394 final Phone phone = getPhone(subId);
2395 return phone == null ? null : phone.getCarrierName();
2396 } finally {
2397 Binder.restoreCallingIdentity(identity);
2398 }
fionaxu43304da2017-11-27 22:51:16 -08002399 }
2400
calvinpanffe225e2018-11-01 19:43:06 +08002401 @Override
chen xu0026ca62019-03-06 15:28:50 -08002402 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002403 final long identity = Binder.clearCallingIdentity();
2404 try {
2405 final Phone phone = getPhone(subId);
2406 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002407 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002408 } finally {
2409 Binder.restoreCallingIdentity(identity);
2410 }
2411 }
2412
2413 @Override
chen xu0026ca62019-03-06 15:28:50 -08002414 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002415 final long identity = Binder.clearCallingIdentity();
2416 try {
2417 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002418 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002419 } finally {
2420 Binder.restoreCallingIdentity(identity);
2421 }
2422 }
2423
chen xu651eec72018-11-11 19:03:44 -08002424 @Override
chen xu864e11c2018-12-06 22:10:03 -08002425 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2426 if (!isSubscriptionMccMnc) {
2427 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2428 }
chen xu651eec72018-11-11 19:03:44 -08002429 final Phone phone = PhoneFactory.getPhone(slotIndex);
2430 if (phone == null) {
2431 return TelephonyManager.UNKNOWN_CARRIER_ID;
2432 }
2433 final long identity = Binder.clearCallingIdentity();
2434 try {
2435 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2436 } finally {
2437 Binder.restoreCallingIdentity(identity);
2438 }
2439 }
2440
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441 //
2442 // Internal helper methods.
2443 //
2444
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002445 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002446 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2447 *
2448 * @throws SecurityException if the caller does not have the required permission
2449 */
2450 private void enforceModifyPermission() {
2451 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2452 }
2453
Shuo Qianf2b2df42019-11-13 17:43:31 -08002454 private void enforceActiveEmergencySessionPermission() {
2455 mApp.enforceCallingOrSelfPermission(
2456 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2457 }
2458
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002459 /**
2460 * Make sure the caller has the CALL_PHONE permission.
2461 *
2462 * @throws SecurityException if the caller does not have the required permission
2463 */
2464 private void enforceCallPermission() {
2465 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2466 }
2467
paulhu423b5f22019-08-23 19:17:33 +08002468 private void enforceSettingsPermission() {
2469 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002470 }
2471
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002472 private String createTelUrl(String number) {
2473 if (TextUtils.isEmpty(number)) {
2474 return null;
2475 }
2476
Jake Hambye994d462014-02-03 13:10:13 -08002477 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478 }
2479
Ihab Awadf9e92732013-12-05 18:02:52 -08002480 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002481 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2482 }
2483
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002484 private static void logv(String msg) {
2485 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2486 }
2487
Ihab Awadf9e92732013-12-05 18:02:52 -08002488 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2490 }
2491
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002492 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002493 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002494 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002495 }
2496
Sanket Padawe356d7632015-06-22 14:03:32 -07002497 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002498 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002499 final long identity = Binder.clearCallingIdentity();
2500 try {
2501 final Phone phone = PhoneFactory.getPhone(slotIndex);
2502 if (phone == null) {
2503 return PhoneConstants.PHONE_TYPE_NONE;
2504 } else {
2505 return phone.getPhoneType();
2506 }
2507 } finally {
2508 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002509 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002510 }
2511
2512 /**
2513 * Returns the CDMA ERI icon index to display
2514 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002515 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002516 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2517 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2518 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002519 }
2520
Sanket Padawe356d7632015-06-22 14:03:32 -07002521 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002522 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2523 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002524 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002525 mApp, subId, callingPackage, callingFeatureId,
2526 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002527 return -1;
2528 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002529
2530 final long identity = Binder.clearCallingIdentity();
2531 try {
2532 final Phone phone = getPhone(subId);
2533 if (phone != null) {
2534 return phone.getCdmaEriIconIndex();
2535 } else {
2536 return -1;
2537 }
2538 } finally {
2539 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002540 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002541 }
2542
2543 /**
2544 * Returns the CDMA ERI icon mode,
2545 * 0 - ON
2546 * 1 - FLASHING
2547 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002548 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002549 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2550 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2551 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002552 }
2553
Sanket Padawe356d7632015-06-22 14:03:32 -07002554 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002555 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2556 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002557 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002558 mApp, subId, callingPackage, callingFeatureId,
2559 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002560 return -1;
2561 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002562
2563 final long identity = Binder.clearCallingIdentity();
2564 try {
2565 final Phone phone = getPhone(subId);
2566 if (phone != null) {
2567 return phone.getCdmaEriIconMode();
2568 } else {
2569 return -1;
2570 }
2571 } finally {
2572 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002573 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002574 }
2575
2576 /**
2577 * Returns the CDMA ERI text,
2578 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002579 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002580 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2581 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2582 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002583 }
2584
Sanket Padawe356d7632015-06-22 14:03:32 -07002585 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002586 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2587 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002588 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002589 mApp, subId, callingPackage, callingFeatureId,
2590 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002591 return null;
2592 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002593
2594 final long identity = Binder.clearCallingIdentity();
2595 try {
2596 final Phone phone = getPhone(subId);
2597 if (phone != null) {
2598 return phone.getCdmaEriText();
2599 } else {
2600 return null;
2601 }
2602 } finally {
2603 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002604 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002605 }
2606
2607 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002608 * Returns the CDMA MDN.
2609 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002610 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002611 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002612 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2613 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002614
2615 final long identity = Binder.clearCallingIdentity();
2616 try {
2617 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002618 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619 return phone.getLine1Number();
2620 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002621 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002622 return null;
2623 }
2624 } finally {
2625 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002626 }
2627 }
2628
2629 /**
2630 * Returns the CDMA MIN.
2631 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002632 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002633 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2635 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002636
2637 final long identity = Binder.clearCallingIdentity();
2638 try {
2639 final Phone phone = getPhone(subId);
2640 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2641 return phone.getCdmaMin();
2642 } else {
2643 return null;
2644 }
2645 } finally {
2646 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002647 }
2648 }
2649
Hall Liud892bec2018-11-30 14:51:45 -08002650 @Override
2651 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2652 INumberVerificationCallback callback, String callingPackage) {
2653 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2654 != PERMISSION_GRANTED) {
2655 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2656 }
2657 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2658
2659 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2660 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2661 throw new SecurityException("Calling package must be configured in the device config");
2662 }
2663
2664 if (range == null) {
2665 throw new NullPointerException("Range must be non-null");
2666 }
2667
2668 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002669 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002670
2671 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2672 }
2673
Junda Liuca05d5d2014-08-14 22:36:34 -07002674 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002675 * Returns true if CDMA provisioning needs to run.
2676 */
2677 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002678 final long identity = Binder.clearCallingIdentity();
2679 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002680 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681 } finally {
2682 Binder.restoreCallingIdentity(identity);
2683 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002684 }
2685
2686 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002687 * Sets the voice mail number of a given subId.
2688 */
2689 @Override
2690 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08002691 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2692 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002693
2694 final long identity = Binder.clearCallingIdentity();
2695 try {
2696 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2697 new Pair<String, String>(alphaTag, number), new Integer(subId));
2698 return success;
2699 } finally {
2700 Binder.restoreCallingIdentity(identity);
2701 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002702 }
2703
Ta-wei Yen87c49842016-05-13 21:19:52 -07002704 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002705 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2706 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002707 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2708 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002709 if (!TextUtils.equals(callingPackage, systemDialer)) {
2710 throw new SecurityException("caller must be system dialer");
2711 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002712
2713 final long identity = Binder.clearCallingIdentity();
2714 try {
2715 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2716 if (phoneAccountHandle == null) {
2717 return null;
2718 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002719 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002720 } finally {
2721 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002722 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002723 }
2724
2725 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002726 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2727 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002728 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002729 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002730 mApp, subId, callingPackage, callingFeatureId,
2731 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002732 return null;
2733 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002734
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002735 final long identity = Binder.clearCallingIdentity();
2736 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002737 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002738 } finally {
2739 Binder.restoreCallingIdentity(identity);
2740 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002741 }
2742
2743 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002744 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2745 VisualVoicemailSmsFilterSettings settings) {
2746 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002747
2748 final long identity = Binder.clearCallingIdentity();
2749 try {
2750 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002751 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002752 } finally {
2753 Binder.restoreCallingIdentity(identity);
2754 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002755 }
2756
2757 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002758 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2759 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002760
2761 final long identity = Binder.clearCallingIdentity();
2762 try {
2763 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002764 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002765 } finally {
2766 Binder.restoreCallingIdentity(identity);
2767 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002768 }
2769
2770 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002771 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2772 String callingPackage, int subId) {
2773 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002774
2775 final long identity = Binder.clearCallingIdentity();
2776 try {
2777 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002778 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002779 } finally {
2780 Binder.restoreCallingIdentity(identity);
2781 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002782 }
2783
2784 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002785 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002786 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002787
2788 final long identity = Binder.clearCallingIdentity();
2789 try {
2790 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002791 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002792 } finally {
2793 Binder.restoreCallingIdentity(identity);
2794 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002795 }
2796
2797 @Override
2798 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2799 String number, int port, String text, PendingIntent sentIntent) {
2800 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002801 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002802 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002803 SmsController smsController = PhoneFactory.getSmsController();
2804 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2805 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002806 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002807
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002808 /**
fionaxu0152e512016-11-14 13:36:14 -08002809 * Sets the voice activation state of a given subId.
2810 */
2811 @Override
2812 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002813 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2814 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002815
2816 final long identity = Binder.clearCallingIdentity();
2817 try {
2818 final Phone phone = getPhone(subId);
2819 if (phone != null) {
2820 phone.setVoiceActivationState(activationState);
2821 } else {
2822 loge("setVoiceActivationState fails with invalid subId: " + subId);
2823 }
2824 } finally {
2825 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002826 }
2827 }
2828
2829 /**
2830 * Sets the data activation state of a given subId.
2831 */
2832 @Override
2833 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002834 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2835 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002836
2837 final long identity = Binder.clearCallingIdentity();
2838 try {
2839 final Phone phone = getPhone(subId);
2840 if (phone != null) {
2841 phone.setDataActivationState(activationState);
2842 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002843 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002844 }
2845 } finally {
2846 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002847 }
2848 }
2849
2850 /**
2851 * Returns the voice activation state of a given subId.
2852 */
2853 @Override
2854 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002855 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002856
fionaxu0152e512016-11-14 13:36:14 -08002857 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002858 final long identity = Binder.clearCallingIdentity();
2859 try {
2860 if (phone != null) {
2861 return phone.getVoiceActivationState();
2862 } else {
2863 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2864 }
2865 } finally {
2866 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002867 }
2868 }
2869
2870 /**
2871 * Returns the data activation state of a given subId.
2872 */
2873 @Override
2874 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002875 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002876
fionaxu0152e512016-11-14 13:36:14 -08002877 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002878 final long identity = Binder.clearCallingIdentity();
2879 try {
2880 if (phone != null) {
2881 return phone.getDataActivationState();
2882 } else {
2883 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2884 }
2885 } finally {
2886 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002887 }
2888 }
2889
2890 /**
Wink Saville36469e72014-06-11 15:17:00 -07002891 * Returns the unread count of voicemails for a subId
2892 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002893 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002894 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2895 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002896 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002897 mApp, subId, callingPackage, callingFeatureId,
2898 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002899 return 0;
2900 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002901 final long identity = Binder.clearCallingIdentity();
2902 try {
2903 final Phone phone = getPhone(subId);
2904 if (phone != null) {
2905 return phone.getVoiceMessageCount();
2906 } else {
2907 return 0;
2908 }
2909 } finally {
2910 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002911 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002912 }
2913
2914 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002915 * returns true, if the device is in a state where both voice and data
2916 * are supported simultaneously. This can change based on location or network condition.
2917 */
2918 @Override
2919 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002920 final long identity = Binder.clearCallingIdentity();
2921 try {
2922 final Phone phone = getPhone(subId);
2923 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2924 } finally {
2925 Binder.restoreCallingIdentity(identity);
2926 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002927 }
2928
2929 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002930 * Send the dialer code if called from the current default dialer or the caller has
2931 * carrier privilege.
2932 * @param inputCode The dialer code to send
2933 */
2934 @Override
2935 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002936 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002937 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002938 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2939 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002940 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08002941 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08002942 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002943 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002944
2945 final long identity = Binder.clearCallingIdentity();
2946 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002947 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002948 } finally {
2949 Binder.restoreCallingIdentity(identity);
2950 }
fionaxu235cc5e2017-03-06 22:25:57 -08002951 }
2952
Pengquan Menga1bb6272018-09-06 09:59:22 -07002953 @Override
2954 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08002955 TelephonyPermissions
2956 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
2957 mApp, subId, "getNetworkSelectionMode");
2958 final long identity = Binder.clearCallingIdentity();
2959 try {
2960 if (!isActiveSubscription(subId)) {
2961 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2962 }
2963 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2964 } finally {
2965 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07002966 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002967 }
2968
Brad Ebinger35c841c2018-10-01 10:40:55 -07002969 @Override
Sarah Chin5f0ecd72019-12-06 10:24:18 -08002970 public PhoneCapability getPhoneCapability(int subId, String callingPackage,
2971 String callingFeatureId) {
2972 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2973 mApp, subId, callingPackage, callingFeatureId, "getPhoneCapability")) {
2974 return null;
2975 }
2976 final long identity = Binder.clearCallingIdentity();
2977 try {
2978 return mPhoneConfigurationManager.getStaticPhoneCapability();
2979 } finally {
2980 Binder.restoreCallingIdentity(identity);
2981 }
2982 }
2983
2984 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002985 public boolean isInEmergencySmsMode() {
2986 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2987 final long identity = Binder.clearCallingIdentity();
2988 try {
2989 for (Phone phone : PhoneFactory.getPhones()) {
2990 if (phone.isInEmergencySmsMode()) {
2991 return true;
2992 }
2993 }
2994 } finally {
2995 Binder.restoreCallingIdentity(identity);
2996 }
2997 return false;
2998 }
2999
shilu366312e2019-12-17 09:28:10 -08003000 /**
3001 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3002 * @param subId The subscription to use to check the configuration.
3003 * @param c The callback that will be used to send the result.
3004 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003005 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003006 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3007 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003008 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003009 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003010
Brad Ebinger77b832e2019-10-17 17:03:22 -07003011 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3012 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3013 "IMS not available on device.");
3014 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003015 final long token = Binder.clearCallingIdentity();
3016 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003017 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003018 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003019 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003020 } catch (ImsException e) {
3021 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003022 } finally {
3023 Binder.restoreCallingIdentity(token);
3024 }
3025 }
3026
shilu366312e2019-12-17 09:28:10 -08003027 /**
3028 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3029 * @param subId The subscription to use to check the configuration.
3030 * @param c The callback that will be used to send the result.
3031 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003032 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003033 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
shilu366312e2019-12-17 09:28:10 -08003034 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003035 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003036 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3037 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3038 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003039 final long token = Binder.clearCallingIdentity();
3040 try {
3041 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3042 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3043 .removeRegistrationCallbackForSubscription(c, subId);
3044 } catch (ImsException e) {
3045 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3046 + "is inactive, ignoring unregister.");
3047 // If the subscription is no longer active, just return, since the callback
3048 // will already have been removed internally.
3049 } finally {
3050 Binder.restoreCallingIdentity(token);
3051 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003052 }
3053
Brad Ebinger774ba362019-10-22 17:36:18 -07003054 /**
3055 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3056 */
3057 @Override
3058 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3059 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3060 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3061 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3062 "IMS not available on device.");
3063 }
3064 final long token = Binder.clearCallingIdentity();
3065 try {
3066 Phone phone = getPhone(subId);
3067 if (phone == null) {
3068 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3069 + subId + "'");
3070 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3071 }
3072 phone.getImsRegistrationState(regState -> {
3073 try {
3074 consumer.accept((regState == null)
3075 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3076 } catch (RemoteException e) {
3077 // Ignore if the remote process is no longer available to call back.
3078 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3079 }
3080 });
3081 } finally {
3082 Binder.restoreCallingIdentity(token);
3083 }
3084 }
3085
3086 /**
3087 * Get the transport type for the IMS service registration state.
3088 */
3089 @Override
3090 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
shilu366312e2019-12-17 09:28:10 -08003091 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger774ba362019-10-22 17:36:18 -07003092 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3093 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3094 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3095 "IMS not available on device.");
3096 }
3097 final long token = Binder.clearCallingIdentity();
3098 try {
3099 Phone phone = getPhone(subId);
3100 if (phone == null) {
3101 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3102 + subId + "'");
3103 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3104 }
3105 phone.getImsRegistrationTech(regTech -> {
3106 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3107 int regTechConverted = (regTech == null)
3108 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3109 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3110 regTechConverted);
3111 try {
3112 consumer.accept(regTechConverted);
3113 } catch (RemoteException e) {
3114 // Ignore if the remote process is no longer available to call back.
3115 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3116 }
3117 });
3118 } finally {
3119 Binder.restoreCallingIdentity(token);
3120 }
3121 }
3122
shilu366312e2019-12-17 09:28:10 -08003123 /**
3124 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3125 * @param subId The subscription to use to check the configuration.
3126 * @param c The callback that will be used to send the result.
3127 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003128 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003129 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3130 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003131 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003132 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003133 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3134 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3135 "IMS not available on device.");
3136 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003137 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3138 final long token = Binder.clearCallingIdentity();
3139 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003140 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003141 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003142 } catch (ImsException e) {
3143 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003144 } finally {
3145 Binder.restoreCallingIdentity(token);
3146 }
3147 }
3148
shilu366312e2019-12-17 09:28:10 -08003149 /**
3150 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3151 * @param subId The subscription to use to check the configuration.
3152 * @param c The callback that will be used to send the result.
3153 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003154 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003155 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
shilu366312e2019-12-17 09:28:10 -08003156 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003157 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003158 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3159 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3160 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003161
3162 final long token = Binder.clearCallingIdentity();
3163 try {
3164 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3165 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003166 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003167 } catch (ImsException e) {
3168 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3169 + "is inactive, ignoring unregister.");
3170 // If the subscription is no longer active, just return, since the callback
3171 // will already have been removed internally.
3172 } finally {
3173 Binder.restoreCallingIdentity(token);
3174 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003175 }
3176
3177 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003178 public boolean isCapable(int subId, int capability, int regTech) {
3179 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003180 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3181 final long token = Binder.clearCallingIdentity();
3182 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003183 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003184 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003185 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003186 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3187 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003188 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003189 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3190 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003191 } finally {
3192 Binder.restoreCallingIdentity(token);
3193 }
3194 }
3195
3196 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003197 public boolean isAvailable(int subId, int capability, int regTech) {
3198 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003199 final long token = Binder.clearCallingIdentity();
3200 try {
3201 Phone phone = getPhone(subId);
3202 if (phone == null) return false;
3203 return phone.isImsCapabilityAvailable(capability, regTech);
3204 } finally {
3205 Binder.restoreCallingIdentity(token);
3206 }
3207 }
3208
Brad Ebinger77b832e2019-10-17 17:03:22 -07003209 /**
3210 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3211 * subscription.
3212 * @param subId The subscription to use to check the configuration.
3213 * @param callback The callback that will be used to send the result.
3214 * @param capability The MmTelFeature capability that will be used to send the result.
3215 * @param transportType The transport type of the MmTelFeature capability.
3216 */
3217 @Override
3218 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3219 int transportType) {
3220 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3221 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3222 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3223 "IMS not available on device.");
3224 }
3225 final long token = Binder.clearCallingIdentity();
3226 try {
3227 int slotId = getSlotIndex(subId);
3228 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3229 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3230 + subId + "'");
3231 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3232 }
3233 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3234 transportType, aBoolean -> {
3235 try {
3236 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3237 } catch (RemoteException e) {
3238 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3239 + "running. Ignore");
3240 }
3241 });
3242 } finally {
3243 Binder.restoreCallingIdentity(token);
3244 }
3245 }
3246
shilu366312e2019-12-17 09:28:10 -08003247 /**
3248 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3249 * @param subId The subscription to use to check the configuration.
3250 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003251 @Override
3252 public boolean isAdvancedCallingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003253 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
3254 enforceReadPrivilegedPermission("isAdvancedCallingSettingEnabled");
3255
Brad Ebinger35c841c2018-10-01 10:40:55 -07003256 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3257 final long token = Binder.clearCallingIdentity();
3258 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003259 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003260 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003261 } catch (ImsException e) {
3262 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003263 } finally {
3264 Binder.restoreCallingIdentity(token);
3265 }
3266 }
3267
3268 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003269 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003271 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003272 final long identity = Binder.clearCallingIdentity();
3273 try {
3274 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003275 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003276 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003277 } catch (ImsException e) {
3278 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003279 } finally {
3280 Binder.restoreCallingIdentity(identity);
3281 }
3282 }
3283
shilu366312e2019-12-17 09:28:10 -08003284 /**
3285 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3286 * @param subId The subscription to use to check the configuration.
3287 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003288 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003289 public boolean isVtSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003290 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003291 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003292 final long identity = Binder.clearCallingIdentity();
3293 try {
3294 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003295 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3296 } catch (ImsException e) {
3297 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003298 } finally {
3299 Binder.restoreCallingIdentity(identity);
3300 }
3301 }
3302
3303 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003304 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003305 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003306 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003307 final long identity = Binder.clearCallingIdentity();
3308 try {
3309 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003310 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003311 } catch (ImsException e) {
3312 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003313 } finally {
3314 Binder.restoreCallingIdentity(identity);
3315 }
3316 }
3317
shilu366312e2019-12-17 09:28:10 -08003318 /**
3319 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3320 * @param subId The subscription to use to check the configuration.
3321 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003322 @Override
3323 public boolean isVoWiFiSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003324 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003325 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3326 final long identity = Binder.clearCallingIdentity();
3327 try {
3328 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003329 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003330 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003331 } catch (ImsException e) {
3332 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003333 } finally {
3334 Binder.restoreCallingIdentity(identity);
3335 }
3336 }
3337
3338 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003339 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003341 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003342 final long identity = Binder.clearCallingIdentity();
3343 try {
3344 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003345 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003346 } catch (ImsException e) {
3347 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003348 } finally {
3349 Binder.restoreCallingIdentity(identity);
3350 }
3351 }
3352
shilu366312e2019-12-17 09:28:10 -08003353 /**
3354 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3355 * @param subId The subscription to use to check the configuration.
3356 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003357 @Override
3358 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003359 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003360 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
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 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003365 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
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
3373 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003374 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003375 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003376 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003377 final long identity = Binder.clearCallingIdentity();
3378 try {
3379 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003380 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003381 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003382 } catch (ImsException e) {
3383 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003384 } finally {
3385 Binder.restoreCallingIdentity(identity);
3386 }
3387 }
3388
3389 @Override
3390 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3392 "setVoWiFiNonPersistent");
3393 final long identity = Binder.clearCallingIdentity();
3394 try {
3395 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003396 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003397 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003398 } catch (ImsException e) {
3399 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003400 } finally {
3401 Binder.restoreCallingIdentity(identity);
3402 }
3403 }
3404
shilu366312e2019-12-17 09:28:10 -08003405 /**
3406 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3407 * @param subId The subscription to use to check the configuration.
3408 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003409 @Override
3410 public int getVoWiFiModeSetting(int subId) {
shilu366312e2019-12-17 09:28:10 -08003411 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003412 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3413 final long identity = Binder.clearCallingIdentity();
3414 try {
3415 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003416 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003417 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003418 } catch (ImsException e) {
3419 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003420 } finally {
3421 Binder.restoreCallingIdentity(identity);
3422 }
3423 }
3424
3425 @Override
3426 public void setVoWiFiModeSetting(int subId, int mode) {
3427 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3428 "setVoWiFiModeSetting");
3429 final long identity = Binder.clearCallingIdentity();
3430 try {
3431 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003432 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003433 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003434 } catch (ImsException e) {
3435 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003436 } finally {
3437 Binder.restoreCallingIdentity(identity);
3438 }
3439 }
3440
3441 @Override
3442 public int getVoWiFiRoamingModeSetting(int subId) {
3443 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3444 final long identity = Binder.clearCallingIdentity();
3445 try {
3446 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003447 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003448 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003449 } catch (ImsException e) {
3450 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003451 } finally {
3452 Binder.restoreCallingIdentity(identity);
3453 }
3454 }
3455
3456 @Override
3457 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3459 "setVoWiFiRoamingModeSetting");
3460 final long identity = Binder.clearCallingIdentity();
3461 try {
3462 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003463 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003464 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003465 } catch (ImsException e) {
3466 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003467 } finally {
3468 Binder.restoreCallingIdentity(identity);
3469 }
3470 }
3471
3472 @Override
3473 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3475 "setRttCapabilityEnabled");
3476 final long identity = Binder.clearCallingIdentity();
3477 try {
3478 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003479 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3480 } catch (ImsException e) {
3481 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003482 } finally {
3483 Binder.restoreCallingIdentity(identity);
3484 }
3485 }
3486
shilu366312e2019-12-17 09:28:10 -08003487 /**
3488 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3489 * @param subId The subscription to use to check the configuration.
3490 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003491 @Override
3492 public boolean isTtyOverVolteEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003493 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003494 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3495 final long identity = Binder.clearCallingIdentity();
3496 try {
3497 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003498 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003499 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003500 } catch (ImsException e) {
3501 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003502 } finally {
3503 Binder.restoreCallingIdentity(identity);
3504 }
3505 }
3506
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003507 @Override
3508 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3509 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3510 final long identity = Binder.clearCallingIdentity();
3511 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003512 if (!isImsAvailableOnDevice()) {
3513 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3514 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003515 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003516 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003517 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003518 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003519 } catch (ImsException e) {
3520 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003521 } finally {
3522 Binder.restoreCallingIdentity(identity);
3523 }
3524 }
3525
3526 @Override
3527 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3528 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3529 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003530 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3531 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3532 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003533 try {
3534 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003535 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003536 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003537 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003538 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3539 + "is inactive, ignoring unregister.");
3540 // If the subscription is no longer active, just return, since the callback will already
3541 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003542 } finally {
3543 Binder.restoreCallingIdentity(identity);
3544 }
3545 }
3546
allenwtsu99c623b2020-01-03 18:24:23 +08003547
3548 private void checkModifyPhoneStatePermission(int subId, String message) {
3549 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3550 message);
3551 }
3552
3553 private boolean isImsProvisioningRequired(int subId, int capability,
3554 boolean isMmtelCapability) {
3555 Phone phone = getPhone(subId);
3556 if (phone == null) {
3557 loge("phone instance null for subid " + subId);
3558 return false;
3559 }
3560 if (isMmtelCapability) {
3561 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3562 return false;
3563 }
3564 } else {
3565 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3566 return false;
3567 }
3568 }
3569 return true;
3570 }
3571
3572 @Override
3573 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3574 boolean isProvisioned) {
3575 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3576
3577 final long identity = Binder.clearCallingIdentity();
3578 try {
3579 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3580 if (!isImsProvisioningRequired(subId, capability, false)) {
3581 return;
3582 }
3583
3584 // this capability requires provisioning, route to the correct API.
3585 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3586 switch (capability) {
3587 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3588 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3589 ims.setEabProvisioned(isProvisioned);
3590 break;
3591 default: {
3592 throw new IllegalArgumentException("Tried to set provisioning for "
3593 + "rcs capability '" + capability + "', which does not require "
3594 + "provisioning.");
3595 }
3596 }
3597 } finally {
3598 Binder.restoreCallingIdentity(identity);
3599 }
3600
3601 }
3602
3603
3604 @Override
3605 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3606 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3607 final long identity = Binder.clearCallingIdentity();
3608 try {
3609 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3610 if (!isImsProvisioningRequired(subId, capability, false)) {
3611 return true;
3612 }
3613
3614 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3615 switch (capability) {
3616 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3617 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3618 return ims.isEabProvisionedOnDevice();
3619
3620 default: {
3621 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3622 + "capability '" + capability + "', which does not require "
3623 + "provisioning.");
3624 }
3625 }
3626
3627 } finally {
3628 Binder.restoreCallingIdentity(identity);
3629 }
3630 }
3631
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003632 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003633 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3634 boolean isProvisioned) {
3635 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3636 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3637 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3638 }
allenwtsu99c623b2020-01-03 18:24:23 +08003639 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003640 final long identity = Binder.clearCallingIdentity();
3641 try {
3642 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003643 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003644 return;
3645 }
3646
3647 // this capability requires provisioning, route to the correct API.
3648 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3649 switch (capability) {
3650 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3651 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3652 ims.setVolteProvisioned(isProvisioned);
3653 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3654 ims.setWfcProvisioned(isProvisioned);
3655 }
3656 break;
3657 }
3658 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3659 // There is currently no difference in VT provisioning type.
3660 ims.setVtProvisioned(isProvisioned);
3661 break;
3662 }
3663 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3664 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3665 // change the capability of the feature instead if needed.
3666 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3667 == isProvisioned) {
3668 // No change in provisioning.
3669 return;
3670 }
3671 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3672 try {
3673 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003674 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003675 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3676 + ", Exception" + e.getMessage());
3677 }
3678 break;
3679 }
3680 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003681 throw new IllegalArgumentException("Tried to set provisioning for "
3682 + "MmTel capability '" + capability + "', which does not require "
3683 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003684 }
3685 }
3686
3687 } finally {
3688 Binder.restoreCallingIdentity(identity);
3689 }
3690 }
3691
3692 @Override
3693 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3694 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3695 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3696 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3697 }
3698 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3699 final long identity = Binder.clearCallingIdentity();
3700 try {
3701 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003702 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003703 return true;
3704 }
3705
3706 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3707 switch (capability) {
3708 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3709 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3710 return ims.isVolteProvisionedOnDevice();
3711 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3712 return ims.isWfcProvisionedOnDevice();
3713 }
3714 // This should never happen, since we are checking tech above to make sure it
3715 // is either LTE or IWLAN.
3716 throw new IllegalArgumentException("Invalid radio technology for voice "
3717 + "capability.");
3718 }
3719 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3720 // There is currently no difference in VT provisioning type.
3721 return ims.isVtProvisionedOnDevice();
3722 }
3723 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3724 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3725 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3726 }
3727 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003728 throw new IllegalArgumentException(
3729 "Tried to get provisioning for MmTel capability '" + capability
3730 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003731 }
3732 }
3733
3734 } finally {
3735 Binder.restoreCallingIdentity(identity);
3736 }
3737 }
3738
3739 @Override
3740 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3741 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3742 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3743 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3744 }
3745 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3746 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3747 return (provisionedBits & capability) > 0;
3748 }
3749
3750 @Override
3751 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3752 boolean isProvisioned) {
3753 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3754 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3755 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3756 }
3757 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3758 "setProvisioningStatusForCapability");
3759 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3760 // If the current provisioning status for capability already matches isProvisioned,
3761 // do nothing.
3762 if (((provisionedBits & capability) > 0) == isProvisioned) {
3763 return;
3764 }
3765 if (isProvisioned) {
3766 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3767 } else {
3768 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3769 }
3770 }
3771
3772 /**
3773 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3774 * technology. The bitfield should mirror the bitfield defined by
3775 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3776 */
3777 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3778 String key = getMmTelProvisioningKey(subId, tech);
3779 // Default is no capabilities are provisioned.
3780 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3781 }
3782
3783 /**
3784 * Sets the MmTel capability provisioning bitfield (defined by
3785 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3786 * technology specified.
3787 *
3788 * Note: This is a synchronous command and should not be called on UI thread.
3789 */
3790 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3791 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3792 String key = getMmTelProvisioningKey(subId, tech);
3793 editor.putInt(key, newField);
3794 editor.commit();
3795 }
3796
3797 private static String getMmTelProvisioningKey(int subId, int tech) {
3798 // resulting key is provision_ims_mmtel_{subId}_{tech}
3799 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3800 }
3801
3802 /**
3803 * Query CarrierConfig to see if the specified capability requires provisioning for the
3804 * carrier associated with the subscription id.
3805 */
3806 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3807 int capability) {
3808 CarrierConfigManager configManager = new CarrierConfigManager(context);
3809 PersistableBundle c = configManager.getConfigForSubId(subId);
3810 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003811 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003812 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3813 false);
3814 boolean requireVoiceVtProvisioning = c.getBoolean(
3815 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3816
3817 // First check to make sure that the capability requires provisioning.
3818 switch (capability) {
3819 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3820 // intentional fallthrough
3821 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3822 if (requireVoiceVtProvisioning) {
3823 // Voice and Video requires provisioning
3824 return true;
3825 }
3826 break;
3827 }
3828 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3829 if (requireUtProvisioning) {
3830 // UT requires provisioning
3831 return true;
3832 }
3833 break;
3834 }
3835 }
3836 return false;
3837 }
3838
allenwtsu99c623b2020-01-03 18:24:23 +08003839 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
3840 int capability) {
3841 CarrierConfigManager configManager = new CarrierConfigManager(context);
3842 PersistableBundle c = configManager.getConfigForSubId(subId);
3843
3844 boolean requireRcsProvisioning = c.getBoolean(
3845 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
3846
3847 // First check to make sure that the capability requires provisioning.
3848 switch (capability) {
3849 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3850 // intentional fallthrough
3851 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
3852 if (requireRcsProvisioning) {
3853 // OPTION or PRESENCE requires provisioning
3854 return true;
3855 }
3856 break;
3857 }
3858 }
3859 return false;
3860 }
3861
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003862 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003863 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003864 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3865 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3866 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003867 enforceReadPrivilegedPermission("getImsProvisioningInt");
3868 final long identity = Binder.clearCallingIdentity();
3869 try {
3870 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003871 int slotId = getSlotIndex(subId);
3872 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3873 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3874 + subId + "' for key:" + key);
3875 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3876 }
3877 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003878 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003879 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3880 + subId + "' for key:" + key);
3881 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003882 } finally {
3883 Binder.restoreCallingIdentity(identity);
3884 }
3885 }
3886
3887 @Override
3888 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003889 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3890 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3891 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003892 enforceReadPrivilegedPermission("getImsProvisioningString");
3893 final long identity = Binder.clearCallingIdentity();
3894 try {
3895 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003896 int slotId = getSlotIndex(subId);
3897 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3898 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3899 + subId + "' for key:" + key);
3900 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3901 }
3902 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003903 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003904 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3905 + subId + "' for key:" + key);
3906 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003907 } finally {
3908 Binder.restoreCallingIdentity(identity);
3909 }
3910 }
3911
3912 @Override
3913 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003914 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3915 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3916 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003917 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3918 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003919 final long identity = Binder.clearCallingIdentity();
3920 try {
3921 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003922 int slotId = getSlotIndex(subId);
3923 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3924 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3925 + subId + "' for key:" + key);
3926 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3927 }
3928 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003929 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003930 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3931 + "' for key:" + key);
3932 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003933 } finally {
3934 Binder.restoreCallingIdentity(identity);
3935 }
3936 }
3937
3938 @Override
3939 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003940 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3941 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3942 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003943 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3944 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003945 final long identity = Binder.clearCallingIdentity();
3946 try {
3947 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003948 int slotId = getSlotIndex(subId);
3949 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3950 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3951 + subId + "' for key:" + key);
3952 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3953 }
3954 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003955 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003956 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3957 + "' for key:" + key);
3958 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003959 } finally {
3960 Binder.restoreCallingIdentity(identity);
3961 }
3962 }
3963
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003964 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003965 int slotId = SubscriptionManager.getSlotIndex(subId);
3966 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003967 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3968 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003969 }
3970 return slotId;
3971 }
3972
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003973 private int getSlotIndex(int subId) {
3974 int slotId = SubscriptionManager.getSlotIndex(subId);
3975 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3976 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3977 }
3978 return slotId;
3979 }
3980
Wink Saville36469e72014-06-11 15:17:00 -07003981 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003982 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003983 */
3984 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003985 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3986 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003987 final int targetSdk = getTargetSdk(callingPackage);
3988 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003989 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003990 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003991 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003992 mApp, subId, callingPackage, callingFeatureId,
3993 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003994 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3995 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003996
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003997 final long identity = Binder.clearCallingIdentity();
3998 try {
3999 final Phone phone = getPhone(subId);
4000 if (phone != null) {
4001 return phone.getServiceState().getDataNetworkType();
4002 } else {
4003 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4004 }
4005 } finally {
4006 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004007 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004008 }
4009
4010 /**
4011 * Returns the data network type
4012 */
4013 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004014 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4015 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4016 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004017 }
4018
4019 /**
4020 * Returns the data network type for a subId
4021 */
4022 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004023 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4024 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004025 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004026 mApp, subId, callingPackage, callingFeatureId,
4027 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004028 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4029 }
4030
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004031 final long identity = Binder.clearCallingIdentity();
4032 try {
4033 final Phone phone = getPhone(subId);
4034 if (phone != null) {
4035 return phone.getServiceState().getDataNetworkType();
4036 } else {
4037 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4038 }
4039 } finally {
4040 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004041 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004042 }
4043
4044 /**
Wink Saville36469e72014-06-11 15:17:00 -07004045 * Returns the Voice network type for a subId
4046 */
4047 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004048 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4049 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004050 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004051 mApp, subId, callingPackage, callingFeatureId,
4052 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004053 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4054 }
4055
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004056 final long identity = Binder.clearCallingIdentity();
4057 try {
4058 final Phone phone = getPhone(subId);
4059 if (phone != null) {
4060 return phone.getServiceState().getVoiceNetworkType();
4061 } else {
4062 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4063 }
4064 } finally {
4065 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004066 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004067 }
4068
4069 /**
4070 * @return true if a ICC card is present
4071 */
4072 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004073 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004074 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4075 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004076 }
4077
4078 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004079 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004080 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004081 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004082 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004083 final long identity = Binder.clearCallingIdentity();
4084 try {
4085 final Phone phone = PhoneFactory.getPhone(slotIndex);
4086 if (phone != null) {
4087 return phone.getIccCard().hasIccCard();
4088 } else {
4089 return false;
4090 }
4091 } finally {
4092 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004093 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004094 }
4095
4096 /**
4097 * Return if the current radio is LTE on CDMA. This
4098 * is a tri-state return value as for a period of time
4099 * the mode may be unknown.
4100 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004101 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004102 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004103 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004104 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004105 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004106 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4107 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4108 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004109 }
4110
Sanket Padawe356d7632015-06-22 14:03:32 -07004111 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004112 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4113 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004114 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004115 mApp, subId, callingPackage, callingFeatureId,
4116 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004117 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4118 }
4119
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004120 final long identity = Binder.clearCallingIdentity();
4121 try {
4122 final Phone phone = getPhone(subId);
4123 if (phone == null) {
4124 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4125 } else {
4126 return phone.getLteOnCdmaMode();
4127 }
4128 } finally {
4129 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004130 }
Wink Saville36469e72014-06-11 15:17:00 -07004131 }
4132
Wink Saville36469e72014-06-11 15:17:00 -07004133 /**
4134 * {@hide}
4135 * Returns Default subId, 0 in the case of single standby.
4136 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004137 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004138 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004139 }
4140
Shishir Agrawala9f32182016-04-12 12:00:16 -07004141 private int getSlotForDefaultSubscription() {
4142 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4143 }
4144
Wink Savilleb564aae2014-10-23 10:18:09 -07004145 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004146 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004147 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004148
Pengquan Menge92a50d2018-09-21 15:54:48 -07004149 private boolean isActiveSubscription(int subId) {
4150 return mSubscriptionController.isActiveSubId(subId);
4151 }
4152
Ihab Awadf2177b72013-11-25 13:33:23 -08004153 /**
4154 * @see android.telephony.TelephonyManager.WifiCallingChoices
4155 */
4156 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004157 final long identity = Binder.clearCallingIdentity();
4158 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004159 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004160 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4161 getWhenToMakeWifiCallsDefaultPreference());
4162 } finally {
4163 Binder.restoreCallingIdentity(identity);
4164 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004165 }
4166
4167 /**
4168 * @see android.telephony.TelephonyManager.WifiCallingChoices
4169 */
4170 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004171 final long identity = Binder.clearCallingIdentity();
4172 try {
4173 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004174 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004175 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4176 } finally {
4177 Binder.restoreCallingIdentity(identity);
4178 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004179 }
4180
Sailesh Nepald1e68152013-12-12 19:08:02 -08004181 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004182 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004183 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004184 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004185
Jordan Liu4c733742019-02-28 12:03:40 -08004186 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4187 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4188 if (phoneId == -1) {
4189 throw new IllegalArgumentException("Given slot index: " + slotIndex
4190 + " does not correspond to an active phone");
4191 }
4192 return PhoneFactory.getPhone(phoneId);
4193 }
4194
Shishir Agrawal566b7612013-10-28 14:41:00 -07004195 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004196 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4197 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004198 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4199 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004200 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004201 if (DBG) {
4202 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4203 }
4204 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4205 p2);
4206 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004207
Jordan Liu4c733742019-02-28 12:03:40 -08004208
4209 @Override
4210 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4211 int slotIndex, String callingPackage, String aid, int p2) {
4212 enforceModifyPermission();
4213 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4214 if (DBG) {
4215 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4216 }
4217 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4218 callingPackage, aid, p2);
4219 }
4220
4221 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4222 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004223 final long identity = Binder.clearCallingIdentity();
4224 try {
4225 if (TextUtils.equals(ISDR_AID, aid)) {
4226 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004227 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4228 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004229 if (bestComponent == null
4230 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4231 loge("The calling package is not allowed to access ISD-R.");
4232 throw new SecurityException(
4233 "The calling package is not allowed to access ISD-R.");
4234 }
Derek Tan740e1672017-06-27 14:56:27 -07004235 }
Derek Tan740e1672017-06-27 14:56:27 -07004236
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004237 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004238 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4239 null /* workSource */);
4240 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004241 return response;
4242 } finally {
4243 Binder.restoreCallingIdentity(identity);
4244 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004245 }
4246
4247 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004248 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004249 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4250 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004251 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4252 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4253 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004254
Jordan Liu4c733742019-02-28 12:03:40 -08004255 @Override
4256 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4257 enforceModifyPermission();
4258 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4259 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4260 channel);
4261 }
4262
4263 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004264 final long identity = Binder.clearCallingIdentity();
4265 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004266 if (channel < 0) {
4267 return false;
4268 }
Jordan Liu4c733742019-02-28 12:03:40 -08004269 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4270 null /* workSource */);
4271 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004272 return success;
4273 } finally {
4274 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004275 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004276 }
4277
4278 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004279 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004280 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004281 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4282 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004283 if (DBG) {
4284 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4285 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4286 + p3 + " data=" + data);
4287 }
4288 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4289 command, p1, p2, p3, data);
4290 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004291
Jordan Liu4c733742019-02-28 12:03:40 -08004292 @Override
4293 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4294 int command, int p1, int p2, int p3, String data) {
4295 enforceModifyPermission();
4296 if (DBG) {
4297 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4298 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4299 + p3 + " data=" + data);
4300 }
4301 return iccTransmitApduLogicalChannelWithPermission(
4302 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4303 data);
4304 }
4305
4306 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4307 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004308 final long identity = Binder.clearCallingIdentity();
4309 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004310 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004311 return "";
4312 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004313
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004314 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004315 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4316 null /* workSource */);
4317 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004318
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004319 // Append the returned status code to the end of the response payload.
4320 String s = Integer.toHexString(
4321 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4322 if (response.payload != null) {
4323 s = IccUtils.bytesToHexString(response.payload) + s;
4324 }
4325 return s;
4326 } finally {
4327 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004328 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004329 }
Jake Hambye994d462014-02-03 13:10:13 -08004330
Evan Charltonc66da362014-05-16 14:06:40 -07004331 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004332 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4333 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004334 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4335 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004336 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004337 if (DBG) {
4338 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4339 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4340 }
4341 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4342 cla, command, p1, p2, p3, data);
4343 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004344
Jordan Liu4c733742019-02-28 12:03:40 -08004345 @Override
4346 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4347 int command, int p1, int p2, int p3, String data) {
4348 enforceModifyPermission();
4349 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4350 if (DBG) {
4351 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4352 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4353 + " data=" + data);
4354 }
4355
4356 return iccTransmitApduBasicChannelWithPermission(
4357 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4358 p2, p3, data);
4359 }
4360
4361 // open APDU basic channel assuming the caller has sufficient permissions
4362 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4363 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004364 final long identity = Binder.clearCallingIdentity();
4365 try {
4366 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4367 && TextUtils.equals(ISDR_AID, data)) {
4368 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004369 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4370 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004371 if (bestComponent == null
4372 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4373 loge("The calling package is not allowed to select ISD-R.");
4374 throw new SecurityException(
4375 "The calling package is not allowed to select ISD-R.");
4376 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004377 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004379 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004380 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4381 null /* workSource */);
4382 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004383
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004384 // Append the returned status code to the end of the response payload.
4385 String s = Integer.toHexString(
4386 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4387 if (response.payload != null) {
4388 s = IccUtils.bytesToHexString(response.payload) + s;
4389 }
4390 return s;
4391 } finally {
4392 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004393 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004394 }
4395
4396 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004397 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004398 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4400 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004401
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004402 final long identity = Binder.clearCallingIdentity();
4403 try {
4404 if (DBG) {
4405 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4406 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4407 }
4408
4409 IccIoResult response =
4410 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4411 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4412 subId);
4413
4414 if (DBG) {
4415 log("Exchange SIM_IO [R]" + response);
4416 }
4417
4418 byte[] result = null;
4419 int length = 2;
4420 if (response.payload != null) {
4421 length = 2 + response.payload.length;
4422 result = new byte[length];
4423 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4424 } else {
4425 result = new byte[length];
4426 }
4427
4428 result[length - 1] = (byte) response.sw2;
4429 result[length - 2] = (byte) response.sw1;
4430 return result;
4431 } finally {
4432 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004433 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004434 }
4435
Nathan Haroldb3014052017-01-25 15:57:32 -08004436 /**
4437 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4438 * on a particular subscription
4439 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004440 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4441 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004442 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004443 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004444 return null;
4445 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004446
4447 final long identity = Binder.clearCallingIdentity();
4448 try {
4449 if (appType != TelephonyManager.APPTYPE_USIM
4450 && appType != TelephonyManager.APPTYPE_SIM) {
4451 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4452 return null;
4453 }
4454 Object response = sendRequest(
4455 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4456 if (response instanceof String[]) {
4457 return (String[]) response;
4458 }
yincheng zhaod698b842019-09-06 17:06:54 -07004459 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004460 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004461 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004462 } finally {
4463 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004464 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004465 }
4466
yincheng zhaod698b842019-09-06 17:06:54 -07004467 /**
4468 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4469 * subscription.
4470 *
4471 * @param subId the id of the subscription.
4472 * @param appType the uicc app type, must be USIM or SIM.
4473 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4474 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004475 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004476 * @return number of fplmns that is successfully written to the SIM.
4477 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004478 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4479 String callingFeatureId) {
4480 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4481 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004482 if (DBG) logv("no permissions for setForbiddenplmns");
4483 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4484 }
4485 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4486 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4487 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4488 }
4489 if (fplmns == null) {
4490 throw new IllegalArgumentException("Fplmn List provided is null");
4491 }
4492 for (String fplmn : fplmns) {
4493 if (!CellIdentity.isValidPlmn(fplmn)) {
4494 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4495 }
4496 }
4497 final long identity = Binder.clearCallingIdentity();
4498 try {
4499 Object response = sendRequest(
4500 CMD_SET_FORBIDDEN_PLMNS,
4501 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4502 subId);
4503 return (int) response;
4504 } finally {
4505 Binder.restoreCallingIdentity(identity);
4506 }
4507 }
4508
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004509 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004510 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004511 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4512 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004513
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004514 final long identity = Binder.clearCallingIdentity();
4515 try {
4516 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4517 if (response.payload == null) {
4518 return "";
4519 }
Evan Charltonc66da362014-05-16 14:06:40 -07004520
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004521 // Append the returned status code to the end of the response payload.
4522 String s = Integer.toHexString(
4523 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4524 s = IccUtils.bytesToHexString(response.payload) + s;
4525 return s;
4526 } finally {
4527 Binder.restoreCallingIdentity(identity);
4528 }
Evan Charltonc66da362014-05-16 14:06:40 -07004529 }
4530
Jake Hambye994d462014-02-03 13:10:13 -08004531 /**
4532 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4533 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4534 *
4535 * @param itemID the ID of the item to read
4536 * @return the NV item as a String, or null on error.
4537 */
4538 @Override
4539 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004540 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004541 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4542 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004543
4544 final long identity = Binder.clearCallingIdentity();
4545 try {
4546 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004547 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004548 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4549 return value;
4550 } finally {
4551 Binder.restoreCallingIdentity(identity);
4552 }
Jake Hambye994d462014-02-03 13:10:13 -08004553 }
4554
4555 /**
4556 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4557 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4558 *
4559 * @param itemID the ID of the item to read
4560 * @param itemValue the value to write, as a String
4561 * @return true on success; false on any failure
4562 */
4563 @Override
4564 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004565 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004566 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4567 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004568
4569 final long identity = Binder.clearCallingIdentity();
4570 try {
4571 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4572 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004573 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004574 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4575 return success;
4576 } finally {
4577 Binder.restoreCallingIdentity(identity);
4578 }
Jake Hambye994d462014-02-03 13:10:13 -08004579 }
4580
4581 /**
4582 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4583 * Used for device configuration by some CDMA operators.
4584 *
4585 * @param preferredRoamingList byte array containing the new PRL
4586 * @return true on success; false on any failure
4587 */
4588 @Override
4589 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004590 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4591 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004592
4593 final long identity = Binder.clearCallingIdentity();
4594 try {
4595 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4596 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4597 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4598 return success;
4599 } finally {
4600 Binder.restoreCallingIdentity(identity);
4601 }
Jake Hambye994d462014-02-03 13:10:13 -08004602 }
4603
4604 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004605 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004606 * Used for device configuration by some CDMA operators.
4607 *
chen xu6dac5ab2018-10-26 17:39:23 -07004608 * @param slotIndex - device slot.
4609 *
Jake Hambye994d462014-02-03 13:10:13 -08004610 * @return true on success; false on any failure
4611 */
4612 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004613 public boolean resetModemConfig(int slotIndex) {
4614 Phone phone = PhoneFactory.getPhone(slotIndex);
4615 if (phone != null) {
4616 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4617 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004618
chen xu6dac5ab2018-10-26 17:39:23 -07004619 final long identity = Binder.clearCallingIdentity();
4620 try {
4621 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4622 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4623 return success;
4624 } finally {
4625 Binder.restoreCallingIdentity(identity);
4626 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004627 }
chen xu6dac5ab2018-10-26 17:39:23 -07004628 return false;
4629 }
4630
4631 /**
4632 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4633 *
4634 * @param slotIndex - device slot.
4635 *
4636 * @return true on success; false on any failure
4637 */
4638 @Override
4639 public boolean rebootModem(int slotIndex) {
4640 Phone phone = PhoneFactory.getPhone(slotIndex);
4641 if (phone != null) {
4642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4643 mApp, phone.getSubId(), "rebootModem");
4644
4645 final long identity = Binder.clearCallingIdentity();
4646 try {
4647 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4648 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4649 return success;
4650 } finally {
4651 Binder.restoreCallingIdentity(identity);
4652 }
4653 }
4654 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004655 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004656
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004657 public String[] getPcscfAddress(String apnType, String callingPackage,
4658 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004659 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004660 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4661 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004662 return new String[0];
4663 }
4664
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004665 final long identity = Binder.clearCallingIdentity();
4666 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004667 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004668 } finally {
4669 Binder.restoreCallingIdentity(identity);
4670 }
Wink Saville36469e72014-06-11 15:17:00 -07004671 }
4672
Brad Ebinger51f743a2017-01-23 13:50:20 -08004673 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004674 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4675 * {@link #disableIms(int)}.
4676 * @param slotIndex device slot.
4677 */
4678 public void resetIms(int slotIndex) {
4679 enforceModifyPermission();
4680
4681 final long identity = Binder.clearCallingIdentity();
4682 try {
4683 if (mImsResolver == null) {
4684 // may happen if the does not support IMS.
4685 return;
4686 }
4687 mImsResolver.disableIms(slotIndex);
4688 mImsResolver.enableIms(slotIndex);
4689 } finally {
4690 Binder.restoreCallingIdentity(identity);
4691 }
4692 }
4693
4694 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004695 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4696 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004697 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004698 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004699 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004700
4701 final long identity = Binder.clearCallingIdentity();
4702 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004703 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004704 // may happen if the device does not support IMS.
4705 return;
4706 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004707 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004708 } finally {
4709 Binder.restoreCallingIdentity(identity);
4710 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004711 }
4712
4713 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004714 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4715 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004716 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004717 public void disableIms(int slotId) {
4718 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004719
4720 final long identity = Binder.clearCallingIdentity();
4721 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004722 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004723 // may happen if the device does not support IMS.
4724 return;
4725 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004726 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004727 } finally {
4728 Binder.restoreCallingIdentity(identity);
4729 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004730 }
4731
4732 /**
4733 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4734 * feature or {@link null} if the service is not available. If the feature is available, the
4735 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4736 */
4737 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004738 IImsServiceFeatureCallback callback) {
4739 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004740
4741 final long identity = Binder.clearCallingIdentity();
4742 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004743 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004744 // may happen if the device does not support IMS.
4745 return null;
4746 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004747 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004748 } finally {
4749 Binder.restoreCallingIdentity(identity);
4750 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004751 }
4752
4753 /**
4754 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4755 * feature during emergency calling or {@link null} if the service is not available. If the
4756 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4757 * listener for feature updates.
4758 */
4759 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4760 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004761
4762 final long identity = Binder.clearCallingIdentity();
4763 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004764 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004765 // may happen if the device does not support IMS.
4766 return null;
4767 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004768 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004769 } finally {
4770 Binder.restoreCallingIdentity(identity);
4771 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004772 }
4773
Brad Ebinger5f64b052017-12-14 14:26:15 -08004774 /**
4775 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004776 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004777 */
4778 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4779 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004780
4781 final long identity = Binder.clearCallingIdentity();
4782 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004783 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004784 // may happen if the device does not support IMS.
4785 return null;
4786 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004787 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004788 } finally {
4789 Binder.restoreCallingIdentity(identity);
4790 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004791 }
4792
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004793 /**
4794 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004795 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004796 */
4797 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4798 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004799
4800 final long identity = Binder.clearCallingIdentity();
4801 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004802 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004803 // may happen if the device does not support IMS.
4804 return null;
4805 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004806 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004807 } finally {
4808 Binder.restoreCallingIdentity(identity);
4809 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004810 }
4811
Brad Ebinger884c07b2018-02-15 16:17:40 -08004812 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004813 * Sets the ImsService Package Name that Telephony will bind to.
4814 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08004815 * @param slotIndex the slot ID that the ImsService should bind for.
4816 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004817 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004818 * @param featureTypes An integer array of feature types associated with a packageName.
4819 * @param packageName The name of the package that the current configuration will be replaced
4820 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004821 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004822 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004823 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4824 int[] featureTypes, String packageName) {
4825 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4826 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004827 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4828 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08004829 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004830
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004831 final long identity = Binder.clearCallingIdentity();
4832 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004833 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004834 // may happen if the device does not support IMS.
4835 return false;
4836 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004837 Map<Integer, String> featureConfig = new HashMap<>();
4838 for (int featureType : featureTypes) {
4839 featureConfig.put(featureType, packageName);
4840 }
4841 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4842 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004843 } finally {
4844 Binder.restoreCallingIdentity(identity);
4845 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004846 }
4847
4848 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08004849 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004850 *
4851 * @param slotId The slot that the ImsService is associated with.
4852 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4853 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004854 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004855 * @return the package name of the ImsService configuration.
4856 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004857 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4858 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004859 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08004860 TelephonyPermissions
4861 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4862 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4863 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004864
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004865 final long identity = Binder.clearCallingIdentity();
4866 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004867 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004868 // may happen if the device does not support IMS.
4869 return "";
4870 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004871 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004872 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4873 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004874 } finally {
4875 Binder.restoreCallingIdentity(identity);
4876 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004877 }
4878
Brad Ebinger77b832e2019-10-17 17:03:22 -07004879 /**
4880 * Get the MmTelFeature state associated with the requested subscription id.
4881 * @param subId The subscription that the MmTelFeature is associated with.
4882 * @param callback A callback with an integer containing the
4883 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4884 */
4885 @Override
4886 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4887 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4888 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4889 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4890 "IMS not available on device.");
4891 }
4892 final long token = Binder.clearCallingIdentity();
4893 try {
4894 int slotId = getSlotIndex(subId);
4895 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4896 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4897 + subId + "'");
4898 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4899 }
4900 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4901 try {
4902 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4903 } catch (RemoteException e) {
4904 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4905 + "Ignore");
4906 }
4907 });
4908 } finally {
4909 Binder.restoreCallingIdentity(token);
4910 }
4911 }
4912
Wink Saville36469e72014-06-11 15:17:00 -07004913 public void setImsRegistrationState(boolean registered) {
4914 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004915
4916 final long identity = Binder.clearCallingIdentity();
4917 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004918 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004919 } finally {
4920 Binder.restoreCallingIdentity(identity);
4921 }
Wink Saville36469e72014-06-11 15:17:00 -07004922 }
4923
4924 /**
Stuart Scott54788802015-03-30 13:18:01 -07004925 * Set the network selection mode to automatic.
4926 *
4927 */
4928 @Override
4929 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004930 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4931 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004932
4933 final long identity = Binder.clearCallingIdentity();
4934 try {
shilufc958392020-01-20 11:36:01 -08004935 if (!isActiveSubscription(subId)) {
4936 return;
4937 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004938 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4939 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4940 } finally {
4941 Binder.restoreCallingIdentity(identity);
4942 }
Stuart Scott54788802015-03-30 13:18:01 -07004943 }
4944
Pengquan Mengea84e042018-09-20 14:57:26 -07004945 /**
4946 * Ask the radio to connect to the input network and change selection mode to manual.
4947 *
4948 * @param subId the id of the subscription.
4949 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4950 * the operator to attach to.
4951 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4952 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4953 * normal network selection next time.
4954 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004955 */
4956 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004957 public boolean setNetworkSelectionModeManual(
4958 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004959 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4960 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004961
4962 if (!isActiveSubscription(subId)) {
4963 return false;
4964 }
4965
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004966 final long identity = Binder.clearCallingIdentity();
4967 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004968 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004969 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004970 if (DBG) {
4971 log("setNetworkSelectionModeManual: subId: " + subId
4972 + " operator: " + operatorInfo);
4973 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4975 } finally {
4976 Binder.restoreCallingIdentity(identity);
4977 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004978 }
4979
4980 /**
4981 * Scans for available networks.
4982 */
4983 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004984 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4985 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4987 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004988 LocationAccessPolicy.LocationPermissionResult locationResult =
4989 LocationAccessPolicy.checkLocationPermission(mApp,
4990 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4991 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004992 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004993 .setCallingPid(Binder.getCallingPid())
4994 .setCallingUid(Binder.getCallingUid())
4995 .setMethod("getCellNetworkScanResults")
4996 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4997 .build());
4998 switch (locationResult) {
4999 case DENIED_HARD:
5000 throw new SecurityException("Not allowed to access scan results -- location");
5001 case DENIED_SOFT:
5002 return null;
5003 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004
Pengquan Menga1bb6272018-09-06 09:59:22 -07005005 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005006 try {
5007 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005008 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005009 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005010 } finally {
5011 Binder.restoreCallingIdentity(identity);
5012 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005013 }
5014
5015 /**
yinxub1bed742017-04-17 11:45:04 -07005016 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005017 *
yinxub1bed742017-04-17 11:45:04 -07005018 * @param subId id of the subscription
5019 * @param request contains the radio access networks with bands/channels to scan
5020 * @param messenger callback messenger for scan results or errors
5021 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005022 * @return the id of the requested scan which can be used to stop the scan.
5023 */
5024 @Override
5025 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005026 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005027 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5028 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005029 LocationAccessPolicy.LocationPermissionResult locationResult =
5030 LocationAccessPolicy.checkLocationPermission(mApp,
5031 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5032 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005033 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005034 .setCallingPid(Binder.getCallingPid())
5035 .setCallingUid(Binder.getCallingUid())
5036 .setMethod("requestNetworkScan")
5037 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5038 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005039 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005040 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005041 if (e != null) {
5042 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5043 throw e;
5044 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005045 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005046 return TelephonyScanManager.INVALID_SCAN_ID;
5047 }
5048 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005049 }
Hall Liu912dfd32019-04-25 14:02:26 -07005050 int callingUid = Binder.getCallingUid();
5051 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005052 final long identity = Binder.clearCallingIdentity();
5053 try {
5054 return mNetworkScanRequestTracker.startNetworkScan(
5055 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005056 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005057 } finally {
5058 Binder.restoreCallingIdentity(identity);
5059 }
yinxu504e1392017-04-12 16:03:22 -07005060 }
5061
Hall Liub2ac8ef2019-02-28 15:56:23 -08005062 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005063 NetworkScanRequest request, int subId) {
5064 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5065 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5066 boolean hasNetworkScanPermission =
5067 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5068 == PERMISSION_GRANTED;
5069
5070 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5071 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5072 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005073 }
5074
5075 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5076 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005077 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5078 return new SecurityException("Specific channels must not be"
5079 + " scanned without location access.");
5080 }
5081 }
5082 }
5083
Hall Liub2ac8ef2019-02-28 15:56:23 -08005084 return null;
5085 }
5086
yinxu504e1392017-04-12 16:03:22 -07005087 /**
5088 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005089 *
5090 * @param subId id of the subscription
5091 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005092 */
5093 @Override
5094 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005095 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5096 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005097
Hall Liu912dfd32019-04-25 14:02:26 -07005098 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005099 final long identity = Binder.clearCallingIdentity();
5100 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005101 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005102 } finally {
5103 Binder.restoreCallingIdentity(identity);
5104 }
yinxu504e1392017-04-12 16:03:22 -07005105 }
5106
5107 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005108 * Get the calculated preferred network type.
5109 * Used for debugging incorrect network type.
5110 *
5111 * @return the preferred network type, defined in RILConstants.java.
5112 */
5113 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005114 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005115 final Phone defaultPhone = getDefaultPhone();
5116 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005117 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005118 return RILConstants.PREFERRED_NETWORK_MODE;
5119 }
5120
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005121 final long identity = Binder.clearCallingIdentity();
5122 try {
5123 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005124 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005125 } finally {
5126 Binder.restoreCallingIdentity(identity);
5127 }
Junda Liu84d15a22014-07-02 11:21:04 -07005128 }
5129
5130 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005131 * Get the preferred network type.
5132 * Used for device configuration by some CDMA operators.
5133 *
5134 * @return the preferred network type, defined in RILConstants.java.
5135 */
5136 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005137 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005138 TelephonyPermissions
5139 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5140 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005141
5142 final long identity = Binder.clearCallingIdentity();
5143 try {
5144 if (DBG) log("getPreferredNetworkType");
5145 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5146 int networkType = (result != null ? result[0] : -1);
5147 if (DBG) log("getPreferredNetworkType: " + networkType);
5148 return networkType;
5149 } finally {
5150 Binder.restoreCallingIdentity(identity);
5151 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005152 }
5153
5154 /**
5155 * Set the preferred network type.
5156 * Used for device configuration by some CDMA operators.
5157 *
5158 * @param networkType the preferred network type, defined in RILConstants.java.
5159 * @return true on success; false on any failure.
5160 */
5161 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005162 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005163 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5164 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005165
5166 final long identity = Binder.clearCallingIdentity();
5167 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005168 Settings.Global.putInt(mApp.getContentResolver(),
5169 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5170 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005171 } finally {
5172 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005173 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005174 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005175
5176 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005177 * Get the allowed network types that store in the telephony provider.
5178 *
5179 * @param subId the id of the subscription.
5180 * @return allowedNetworkTypes the allowed network types.
5181 */
5182 @Override
5183 public long getAllowedNetworkTypes(int subId) {
5184 TelephonyPermissions
5185 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5186 mApp, subId, "getAllowedNetworkTypes");
5187
5188 final long identity = Binder.clearCallingIdentity();
5189 try {
5190 return SubscriptionManager.getLongSubscriptionProperty(
5191 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5192 } finally {
5193 Binder.restoreCallingIdentity(identity);
5194 }
5195 }
5196
5197 /**
5198 * Set the allowed network types.
5199 *
5200 * @param subId the id of the subscription.
5201 * @param allowedNetworkTypes the allowed network types.
5202 * @return true on success; false on any failure.
5203 */
5204 @Override
5205 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5206 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5207 mApp, subId, "setAllowedNetworkTypes");
5208 final long identity = Binder.clearCallingIdentity();
5209 try {
5210 SubscriptionManager.setSubscriptionProperty(subId,
5211 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5212 String.valueOf(allowedNetworkTypes));
5213 return setPreferredNetworkTypesInternal(subId);
5214 } finally {
5215 Binder.restoreCallingIdentity(identity);
5216 }
5217 }
5218
5219 private boolean setPreferredNetworkTypesInternal(int subId) {
5220 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5221 Settings.Global.getInt(mApp.getContentResolver(),
5222 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5223 RILConstants.PREFERRED_NETWORK_MODE));
5224 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5225 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5226 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5227 (int) (networkTypeBitMask & allowedNetworkTypes));
5228
5229 if (DBG) {
5230 log("setPreferredNetworkTypesInternal: subId " + subId
5231 + " networkTypes " + networkTypeBitMask
5232 + " allowedNetworkTypes " + allowedNetworkTypes
5233 + " networkMode " + networkMode);
5234 }
5235
5236 Boolean success = (Boolean) sendRequest(
5237 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5238 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5239 return success;
5240 }
5241
5242 /**
Miaoa84611c2019-03-15 09:21:10 +08005243 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005244 *
Miaoa84611c2019-03-15 09:21:10 +08005245 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005246 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005247 * @hide
5248 */
5249 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005250 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005251 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005252 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005253 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005254 try {
Miaoa84611c2019-03-15 09:21:10 +08005255 if (phone != null) {
5256 return phone.hasMatchedTetherApnSetting();
5257 } else {
5258 return false;
5259 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005260 } finally {
5261 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005262 }
Junda Liu475951f2014-11-07 16:45:03 -08005263 }
5264
5265 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005266 * Set mobile data enabled
5267 * Used by the user through settings etc to turn on/off mobile data
5268 *
5269 * @param enable {@code true} turn turn data on, else {@code false}
5270 */
5271 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005272 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005273 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5274 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005275
5276 final long identity = Binder.clearCallingIdentity();
5277 try {
5278 int phoneId = mSubscriptionController.getPhoneId(subId);
5279 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5280 Phone phone = PhoneFactory.getPhone(phoneId);
5281 if (phone != null) {
5282 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005283 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005285 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 }
5287 } finally {
5288 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005289 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005290 }
5291
5292 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005293 * Get the user enabled state of Mobile Data.
5294 *
5295 * TODO: remove and use isUserDataEnabled.
5296 * This can't be removed now because some vendor codes
5297 * calls through ITelephony directly while they should
5298 * use TelephonyManager.
5299 *
5300 * @return true on enabled
5301 */
5302 @Override
5303 public boolean getDataEnabled(int subId) {
5304 return isUserDataEnabled(subId);
5305 }
5306
5307 /**
5308 * Get whether mobile data is enabled per user setting.
5309 *
5310 * There are other factors deciding whether mobile data is actually enabled, but they are
5311 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005312 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005313 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005314 *
5315 * @return {@code true} if data is enabled else {@code false}
5316 */
5317 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005318 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005319 try {
5320 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5321 null);
5322 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005323 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5324 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005325 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005326
5327 final long identity = Binder.clearCallingIdentity();
5328 try {
5329 int phoneId = mSubscriptionController.getPhoneId(subId);
5330 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5331 Phone phone = PhoneFactory.getPhone(phoneId);
5332 if (phone != null) {
5333 boolean retVal = phone.isUserDataEnabled();
5334 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5335 return retVal;
5336 } else {
5337 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5338 return false;
5339 }
5340 } finally {
5341 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005342 }
5343 }
5344
5345 /**
5346 * Get whether mobile data is enabled.
5347 *
5348 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5349 * whether mobile data is actually enabled.
5350 *
5351 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5352 *
5353 * @return {@code true} if data is enabled else {@code false}
5354 */
5355 @Override
5356 public boolean isDataEnabled(int subId) {
5357 try {
5358 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5359 null);
5360 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5362 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005363 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005364
5365 final long identity = Binder.clearCallingIdentity();
5366 try {
5367 int phoneId = mSubscriptionController.getPhoneId(subId);
5368 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5369 Phone phone = PhoneFactory.getPhone(phoneId);
5370 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005371 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005372 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5373 return retVal;
5374 } else {
5375 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5376 return false;
5377 }
5378 } finally {
5379 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005380 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005381 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005382
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005383 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5384 Phone phone) {
5385 //load access rules from carrier configs, and check those as well: b/139133814
5386 SubscriptionController subController = SubscriptionController.getInstance();
5387 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5388 || subController == null) return privilegeFromSim;
5389
5390 int uid = Binder.getCallingUid();
5391 PackageManager pkgMgr = phone.getContext().getPackageManager();
5392 String[] packages = pkgMgr.getPackagesForUid(uid);
5393
5394 final long identity = Binder.clearCallingIdentity();
5395 try {
5396 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5397 SubscriptionManager subManager = (SubscriptionManager)
5398 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5399 for (String pkg : packages) {
5400 if (subManager.canManageSubscription(subInfo, pkg)) {
5401 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5402 }
5403 }
5404 return privilegeFromSim;
5405 } finally {
5406 Binder.restoreCallingIdentity(identity);
5407 }
5408 }
5409
5410 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5411 String pkgName) {
5412 //load access rules from carrier configs, and check those as well: b/139133814
5413 SubscriptionController subController = SubscriptionController.getInstance();
5414 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5415 || subController == null) return privilegeFromSim;
5416
5417 final long identity = Binder.clearCallingIdentity();
5418 try {
5419 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5420 SubscriptionManager subManager = (SubscriptionManager)
5421 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5422 return subManager.canManageSubscription(subInfo, pkgName)
5423 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5424 } finally {
5425 Binder.restoreCallingIdentity(identity);
5426 }
5427 }
5428
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005429 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005430 public int getCarrierPrivilegeStatus(int subId) {
5431 final Phone phone = getPhone(subId);
5432 if (phone == null) {
5433 loge("getCarrierPrivilegeStatus: Invalid subId");
5434 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5435 }
5436 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005437 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005438 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005439 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5440 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005441
5442 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5443 card.getCarrierPrivilegeStatusForCurrentTransaction(
5444 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005445 }
Junda Liu29340342014-07-10 15:23:27 -07005446
5447 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005448 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005449 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005450 final Phone phone = getPhone(subId);
5451 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005452 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005453 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5454 }
5455 UiccProfile profile =
5456 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5457 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005458 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005459 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5460 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005461 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005462 profile.getCarrierPrivilegeStatusForUid(
5463 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005464 }
5465
5466 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005467 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5468 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005469 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005470 }
5471
5472 int phoneId = SubscriptionManager.getPhoneId(subId);
5473 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005474 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005475 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005476 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5477 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005478 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5479 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5480 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005481 }
5482
5483 @Override
5484 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005485 if (TextUtils.isEmpty(pkgName))
5486 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005487 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5488 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5489 UiccCard card = UiccController.getInstance().getUiccCard(i);
5490 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005491 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005492 continue;
5493 }
5494
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005495 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5496 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5497 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005498 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5499 break;
5500 }
5501 }
5502
5503 return result;
Junda Liu29340342014-07-10 15:23:27 -07005504 }
Derek Tan89e89d42014-07-08 17:00:10 -07005505
5506 @Override
Junda Liue64de782015-04-16 17:19:16 -07005507 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5508 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5509 loge("phoneId " + phoneId + " is not valid.");
5510 return null;
5511 }
5512 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005513 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005514 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005515 return null ;
5516 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005517 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005518 }
5519
Amith Yamasani6e118872016-02-19 12:53:51 -08005520 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005521 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005522 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005523 List<String> privilegedPackages = new ArrayList<>();
5524 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005525 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5526 // has UICC in that slot.
5527 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005528 if (card.hasCarrierPrivilegeRules()) {
5529 if (packages == null) {
5530 // Only check packages in user 0 for now
5531 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005532 PackageManager.MATCH_DISABLED_COMPONENTS
5533 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005534 | PackageManager.GET_SIGNING_CERTIFICATES,
5535 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005536 }
5537 for (int p = packages.size() - 1; p >= 0; p--) {
5538 PackageInfo pkgInfo = packages.get(p);
5539 if (pkgInfo != null && pkgInfo.packageName != null
5540 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005541 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005542 privilegedPackages.add(pkgInfo.packageName);
5543 }
5544 }
5545 }
5546 }
5547 return privilegedPackages;
5548 }
5549
chen xuf7e9fe82019-05-09 19:31:02 -07005550 @Override
5551 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005552 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5553
5554 final long identity = Binder.clearCallingIdentity();
5555
chen xuf7e9fe82019-05-09 19:31:02 -07005556 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005557 try {
5558 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5559 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5560 }
5561 } finally {
5562 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005563 }
5564 return privilegedPackages;
5565 }
5566
Wink Savilleb564aae2014-10-23 10:18:09 -07005567 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005568 final Phone phone = getPhone(subId);
5569 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005570 if (card == null) {
5571 loge("getIccId: No UICC");
5572 return null;
5573 }
5574 String iccId = card.getIccId();
5575 if (TextUtils.isEmpty(iccId)) {
5576 loge("getIccId: ICC ID is null or empty.");
5577 return null;
5578 }
5579 return iccId;
5580 }
5581
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005582 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005583 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5584 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08005585 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005586 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005587
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005588 final long identity = Binder.clearCallingIdentity();
5589 try {
5590 final String iccId = getIccId(subId);
5591 final Phone phone = getPhone(subId);
5592 if (phone == null) {
5593 return false;
5594 }
5595 final String subscriberId = phone.getSubscriberId();
5596
5597 if (DBG_MERGE) {
5598 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5599 + subscriberId + " to " + number);
5600 }
5601
5602 if (TextUtils.isEmpty(iccId)) {
5603 return false;
5604 }
5605
5606 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5607
5608 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5609 if (alphaTag == null) {
5610 editor.remove(alphaTagPrefKey);
5611 } else {
5612 editor.putString(alphaTagPrefKey, alphaTag);
5613 }
5614
5615 // Record both the line number and IMSI for this ICCID, since we need to
5616 // track all merged IMSIs based on line number
5617 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5618 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5619 if (number == null) {
5620 editor.remove(numberPrefKey);
5621 editor.remove(subscriberPrefKey);
5622 } else {
5623 editor.putString(numberPrefKey, number);
5624 editor.putString(subscriberPrefKey, subscriberId);
5625 }
5626
5627 editor.commit();
5628 return true;
5629 } finally {
5630 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005631 }
Derek Tan7226c842014-07-02 17:42:23 -07005632 }
5633
5634 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005635 public String getLine1NumberForDisplay(int subId, String callingPackage,
5636 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005637 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005638 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005639 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005640 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005641 return null;
5642 }
Derek Tan97ebb422014-09-05 16:55:38 -07005643
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005644 final long identity = Binder.clearCallingIdentity();
5645 try {
5646 String iccId = getIccId(subId);
5647 if (iccId != null) {
5648 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5649 if (DBG_MERGE) {
5650 log("getLine1NumberForDisplay returning "
5651 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5652 }
5653 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005654 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005655 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5656 return null;
5657 } finally {
5658 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005659 }
Derek Tan7226c842014-07-02 17:42:23 -07005660 }
5661
5662 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005663 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5664 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005665 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005666 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005667 return null;
5668 }
Derek Tan97ebb422014-09-05 16:55:38 -07005669
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005670 final long identity = Binder.clearCallingIdentity();
5671 try {
5672 String iccId = getIccId(subId);
5673 if (iccId != null) {
5674 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5675 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5676 }
5677 return null;
5678 } finally {
5679 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005680 }
Derek Tan7226c842014-07-02 17:42:23 -07005681 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005682
5683 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005684 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5685 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005686 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5687 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005688 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005689 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005690 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005691 return null;
5692 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005693
Jordan Liub49b04b2019-05-06 14:45:15 -07005694 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5695 // the process, where TelephonyManager was instantiated.
5696 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005697 final long identity = Binder.clearCallingIdentity();
5698 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005699 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005700 final TelephonyManager tele = TelephonyManager.from(context);
5701 final SubscriptionManager sub = SubscriptionManager.from(context);
5702
5703 // Figure out what subscribers are currently active
5704 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005705
Jordan Liub49b04b2019-05-06 14:45:15 -07005706 // Only consider subs which match the current subId
5707 // This logic can be simplified. See b/131189269 for progress.
5708 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005709 activeSubscriberIds.add(tele.getSubscriberId(subId));
5710 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005711
5712 // First pass, find a number override for an active subscriber
5713 String mergeNumber = null;
5714 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5715 for (String key : prefs.keySet()) {
5716 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5717 final String subscriberId = (String) prefs.get(key);
5718 if (activeSubscriberIds.contains(subscriberId)) {
5719 final String iccId = key.substring(
5720 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5721 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5722 mergeNumber = (String) prefs.get(numberKey);
5723 if (DBG_MERGE) {
5724 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5725 + " for active subscriber " + subscriberId);
5726 }
5727 if (!TextUtils.isEmpty(mergeNumber)) {
5728 break;
5729 }
5730 }
5731 }
5732 }
5733
5734 // Shortcut when no active merged subscribers
5735 if (TextUtils.isEmpty(mergeNumber)) {
5736 return null;
5737 }
5738
5739 // Second pass, find all subscribers under that line override
5740 final ArraySet<String> result = new ArraySet<>();
5741 for (String key : prefs.keySet()) {
5742 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5743 final String number = (String) prefs.get(key);
5744 if (mergeNumber.equals(number)) {
5745 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5746 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5747 final String subscriberId = (String) prefs.get(subscriberKey);
5748 if (!TextUtils.isEmpty(subscriberId)) {
5749 result.add(subscriberId);
5750 }
5751 }
5752 }
5753 }
5754
5755 final String[] resultArray = result.toArray(new String[result.size()]);
5756 Arrays.sort(resultArray);
5757 if (DBG_MERGE) {
5758 Slog.d(LOG_TAG,
5759 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5760 }
5761 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005762 } finally {
5763 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005764 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005765 }
5766
5767 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005768 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5769 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5770
5771 final long identity = Binder.clearCallingIdentity();
5772 try {
5773 final TelephonyManager telephonyManager = mApp.getSystemService(
5774 TelephonyManager.class);
5775 String subscriberId = telephonyManager.getSubscriberId(subId);
5776 if (subscriberId == null) {
5777 if (DBG) {
5778 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5779 + subId);
5780 }
5781 return null;
5782 }
5783
5784 final SubscriptionInfo info = SubscriptionController.getInstance()
5785 .getSubscriptionInfo(subId);
5786 final ParcelUuid groupUuid = info.getGroupUuid();
5787 // If it doesn't belong to any group, return just subscriberId of itself.
5788 if (groupUuid == null) {
5789 return new String[]{subscriberId};
5790 }
5791
5792 // Get all subscriberIds from the group.
5793 final List<String> mergedSubscriberIds = new ArrayList<>();
5794 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005795 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5796 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07005797 for (SubscriptionInfo subInfo : groupInfos) {
5798 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5799 if (subscriberId != null) {
5800 mergedSubscriberIds.add(subscriberId);
5801 }
5802 }
5803
5804 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5805 } finally {
5806 Binder.restoreCallingIdentity(identity);
5807
5808 }
5809 }
5810
5811 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005812 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08005813 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005814 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005815
5816 final long identity = Binder.clearCallingIdentity();
5817 try {
5818 final Phone phone = getPhone(subId);
5819 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5820 } finally {
5821 Binder.restoreCallingIdentity(identity);
5822 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005823 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005824
5825 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005826 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005827 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5828 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08005829 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5830 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005831
5832 final long identity = Binder.clearCallingIdentity();
5833 try {
5834 final Phone phone = getPhone(subId);
5835 if (phone == null) {
5836 return false;
5837 }
5838 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5839 cdmaNonRoamingList);
5840 } finally {
5841 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005842 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005843 }
5844
5845 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005846 @Deprecated
5847 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5848 enforceModifyPermission();
5849
5850 int returnValue = 0;
5851 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005852 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005853 if(result.exception == null) {
5854 if (result.result != null) {
5855 byte[] responseData = (byte[])(result.result);
5856 if(responseData.length > oemResp.length) {
5857 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5858 responseData.length + "bytes. Buffer Size is " +
5859 oemResp.length + "bytes.");
5860 }
5861 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5862 returnValue = responseData.length;
5863 }
5864 } else {
5865 CommandException ex = (CommandException) result.exception;
5866 returnValue = ex.getCommandError().ordinal();
5867 if(returnValue > 0) returnValue *= -1;
5868 }
5869 } catch (RuntimeException e) {
5870 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5871 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5872 if(returnValue > 0) returnValue *= -1;
5873 }
5874
5875 return returnValue;
5876 }
5877
5878 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005879 public void setRadioCapability(RadioAccessFamily[] rafs) {
5880 try {
5881 ProxyController.getInstance().setRadioCapability(rafs);
5882 } catch (RuntimeException e) {
5883 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5884 }
5885 }
5886
5887 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005888 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005889 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005890 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005891 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005892 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005893 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005894 final long identity = Binder.clearCallingIdentity();
5895 try {
chen xub97461a2018-10-26 14:17:57 -07005896 TelephonyPermissions
5897 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5898 mApp, phone.getSubId(), "getRadioAccessFamily");
5899 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005900 } finally {
5901 Binder.restoreCallingIdentity(identity);
5902 }
chen xub97461a2018-10-26 14:17:57 -07005903 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005904 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005905
5906 @Override
5907 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005908 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005909 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005910
5911 final long identity = Binder.clearCallingIdentity();
5912 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005913 ImsManager.getInstance(defaultPhone.getContext(),
5914 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005915 } finally {
5916 Binder.restoreCallingIdentity(identity);
5917 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005918 }
5919
5920 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005921 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005922 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005923 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5924 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005925 return false;
5926 }
Svet Ganovb320e182015-04-16 12:30:10 -07005927
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005928 final long identity = Binder.clearCallingIdentity();
5929 try {
5930 // Check the user preference and the system-level IMS setting. Even if the user has
5931 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5932 // In the long run, we may instead need to check if there exists a connection service
5933 // which can support video calling.
5934 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005935 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005936 return imsManager.isVtEnabledByPlatform()
5937 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5938 && imsManager.isVtEnabledByUser();
5939 } finally {
5940 Binder.restoreCallingIdentity(identity);
5941 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005942 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005943
Andrew Leea1239f22015-03-02 17:44:07 -08005944 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005945 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5946 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005947 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005948 mApp, subId, callingPackage, callingFeatureId,
5949 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005950 return false;
5951 }
5952
5953 final long identity = Binder.clearCallingIdentity();
5954 try {
5955 CarrierConfigManager configManager =
5956 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005957 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005958 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5959 } finally {
5960 Binder.restoreCallingIdentity(identity);
5961 }
Andrew Leea1239f22015-03-02 17:44:07 -08005962 }
5963
5964 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005965 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005966 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005967 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005968 return false;
5969 }
5970
5971 final long identity = Binder.clearCallingIdentity();
5972 try {
5973 CarrierConfigManager configManager =
5974 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005975 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005976 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5977 } finally {
5978 Binder.restoreCallingIdentity(identity);
5979 }
Andrew Leea1239f22015-03-02 17:44:07 -08005980 }
5981
Andrew Lee9431b832015-03-09 18:46:45 -07005982 @Override
5983 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07005984 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005985 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005986 }
5987
5988 @Override
5989 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005990 final long identity = Binder.clearCallingIdentity();
5991 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005992 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993 } finally {
5994 Binder.restoreCallingIdentity(identity);
5995 }
Andrew Lee9431b832015-03-09 18:46:45 -07005996 }
5997
Hall Liuf6668912018-10-31 17:05:23 -07005998 /**
5999 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6000 * support for the feature and device firmware support.
6001 *
6002 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6003 */
6004 @Override
6005 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006006 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006007 final Phone phone = getPhone(subscriptionId);
6008 if (phone == null) {
6009 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6010 return false;
6011 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006013 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006014 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6015 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006016 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006017 return isCarrierSupported && isDeviceSupported;
6018 } finally {
6019 Binder.restoreCallingIdentity(identity);
6020 }
Hall Liu98187582018-01-22 19:15:32 -08006021 }
6022
Hall Liuf6668912018-10-31 17:05:23 -07006023 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006024 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6025 * RTT setting, will return true if the device and carrier both support RTT.
6026 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006027 */
6028 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006029 final long identity = Binder.clearCallingIdentity();
6030 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006031 boolean isRttSupported = isRttSupported(subscriptionId);
6032 boolean isUserRttSettingOn = Settings.Secure.getInt(
6033 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6034 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6035 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6036 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006037 } finally {
6038 Binder.restoreCallingIdentity(identity);
6039 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006040 }
6041
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006042 @Deprecated
6043 @Override
6044 public String getDeviceId(String callingPackage) {
6045 return getDeviceIdWithFeature(callingPackage, null);
6046 }
6047
Sanket Padawe7310cc72015-01-14 09:53:20 -08006048 /**
6049 * Returns the unique device ID of phone, for example, the IMEI for
6050 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6051 *
6052 * <p>Requires Permission:
6053 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6054 */
6055 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006056 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006057 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006058 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006059 return null;
6060 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006061 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006062 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006063 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006064 return null;
6065 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006066
6067 final long identity = Binder.clearCallingIdentity();
6068 try {
6069 return phone.getDeviceId();
6070 } finally {
6071 Binder.restoreCallingIdentity(identity);
6072 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006073 }
6074
Ping Sunc67b7c22016-03-02 19:16:45 +08006075 /**
6076 * {@hide}
6077 * Returns the IMS Registration Status on a particular subid
6078 *
6079 * @param subId
6080 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006081 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006082 Phone phone = getPhone(subId);
6083 if (phone != null) {
6084 return phone.isImsRegistered();
6085 } else {
6086 return false;
6087 }
6088 }
6089
Santos Cordon7a1885b2015-02-03 11:15:19 -08006090 @Override
6091 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006092 final long identity = Binder.clearCallingIdentity();
6093 try {
6094 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6095 } finally {
6096 Binder.restoreCallingIdentity(identity);
6097 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006098 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006099
Tyler Gunnf70ed162019-04-03 15:28:53 -07006100 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006101 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006102 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006103 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006104 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006105 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6106 }
6107 final long identity = Binder.clearCallingIdentity();
6108 try {
6109 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6110 } finally {
6111 Binder.restoreCallingIdentity(identity);
6112 }
6113 }
6114
6115 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006116 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6117 final long identity = Binder.clearCallingIdentity();
6118 try {
6119 Phone phone = getPhone(subscriptionId);
6120 if (phone == null) {
6121 return null;
6122 }
6123 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6124 } finally {
6125 Binder.restoreCallingIdentity(identity);
6126 }
6127 }
6128
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006129 /**
6130 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006131 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006132 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006133 final long identity = Binder.clearCallingIdentity();
6134 try {
6135 Phone phone = getPhone(subId);
6136 if (phone != null) {
6137 return phone.isWifiCallingEnabled();
6138 } else {
6139 return false;
6140 }
6141 } finally {
6142 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006143 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006144 }
6145
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006146 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006147 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006148 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006149 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006150 final long identity = Binder.clearCallingIdentity();
6151 try {
6152 Phone phone = getPhone(subId);
6153 if (phone != null) {
6154 return phone.isVideoEnabled();
6155 } else {
6156 return false;
6157 }
6158 } finally {
6159 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006160 }
6161 }
6162
6163 /**
6164 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6165 * defined in {@link ImsRegistrationImplBase}.
6166 */
6167 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006168 final long identity = Binder.clearCallingIdentity();
6169 try {
6170 Phone phone = getPhone(subId);
6171 if (phone != null) {
6172 return phone.getImsRegistrationTech();
6173 } else {
6174 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6175 }
6176 } finally {
6177 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006178 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006179 }
6180
Stuart Scott8eef64f2015-04-08 15:13:54 -07006181 @Override
6182 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006183 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006184 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6185 return;
6186 }
6187
Svet Ganovcc087f82015-05-12 20:35:54 -07006188 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006189
Svet Ganovcc087f82015-05-12 20:35:54 -07006190 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006191 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6192 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006193 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006194 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006195 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006196 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6197 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006198 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006199 // There has been issues when Sms raw table somehow stores orphan
6200 // fragments. They lead to garbled message when new fragments come
6201 // in and combined with those stale ones. In case this happens again,
6202 // user can reset all network settings which will clean up this table.
6203 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006204 // Clean up IMS settings as well here.
6205 int slotId = getSlotIndex(subId);
6206 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6207 ImsManager.getInstance(mApp, slotId).factoryReset();
6208 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006209
6210 // Erase modem config if erase modem on network setting is enabled.
6211 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6212 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6213 if (configValue != null && Boolean.parseBoolean(configValue)) {
6214 sendEraseModemConfig(getDefaultPhone());
6215 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006216 } finally {
6217 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006218 }
6219 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006220
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006221 private void cleanUpSmsRawTable(Context context) {
6222 ContentResolver resolver = context.getContentResolver();
6223 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6224 resolver.delete(uri, null, null);
6225 }
6226
Narayan Kamath1c496c22015-04-16 14:40:19 +01006227 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006228 public String getSimLocaleForSubscriber(int subId) {
6229 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6230 final Phone phone = getPhone(subId);
6231 if (phone == null) {
6232 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006233 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006234 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006235 final long identity = Binder.clearCallingIdentity();
6236 try {
chen xu5d3637b2019-01-21 23:31:38 -08006237 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006238 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08006239 if (info == null) {
6240 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6241 return null;
6242 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006243 // Try and fetch the locale from the carrier properties or from the SIM language
6244 // preferences (EF-PL and EF-LI)...
6245 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006246 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006247 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6248 if (localeFromDefaultSim != null) {
6249 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6250 if (DBG) log("Using locale from subId: " + subId + " locale: "
6251 + localeFromDefaultSim);
6252 return localeFromDefaultSim.toLanguageTag();
6253 } else {
6254 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006255 }
6256 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006257
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006258 // The SIM language preferences only store a language (e.g. fr = French), not an
6259 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6260 // the SIM and carrier preferences does not include a country we add the country
6261 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006262 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006263 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006264 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006265 return mccLocale.toLanguageTag();
6266 }
6267
6268 if (DBG) log("No locale found - returning null");
6269 return null;
6270 } finally {
6271 Binder.restoreCallingIdentity(identity);
6272 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006273 }
6274
6275 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006276 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6277 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006278 }
6279
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006280 /**
6281 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6282 */
6283 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006284 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6285 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006286 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006287
Chenjie Yu1ba97252018-01-11 18:16:20 -08006288 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006289 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006290
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006291 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006292 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6293 * representing the state of the modem.
6294 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006295 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6296 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006297 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006298 */
6299 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006300 public void requestModemActivityInfo(ResultReceiver result) {
6301 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006302 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006303
6304 final long identity = Binder.clearCallingIdentity();
6305 try {
6306 ModemActivityInfo ret = null;
6307 synchronized (mLastModemActivityInfo) {
6308 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6309 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006310 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006311 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006312 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xu13851032019-09-10 18:49:52 -07006313 int[] txTimeMs = info.getTransmitTimeMillis();
6314 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006315 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xu13851032019-09-10 18:49:52 -07006316 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006317 }
6318 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006319 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6320 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006321 mLastModemActivityInfo.setIdleTimeMillis(
6322 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xu13851032019-09-10 18:49:52 -07006323 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6324 mLastModemActivityInfo.setReceiveTimeMillis(
6325 info.getReceiveTimeMillis() + mLastModemActivityInfo
6326 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006327 }
Chen Xu13851032019-09-10 18:49:52 -07006328
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006329 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6330 mLastModemActivityInfo.getSleepTimeMillis(),
6331 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xu13851032019-09-10 18:49:52 -07006332 mLastModemActivityInfo.getTransmitTimeMillis(),
6333 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006334 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006335 Bundle bundle = new Bundle();
6336 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6337 result.send(0, bundle);
6338 } finally {
6339 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006340 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006341 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006342
Siddharth Rayb8114062018-06-17 15:02:38 -07006343 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6344 // less than total activity duration.
6345 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6346 if (info == null) {
6347 return false;
6348 }
6349 int activityDurationMs =
6350 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6351 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006352 int[] txTimeMs = info.getTransmitTimeMillis();
6353 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6354 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006355 }
6356 return (info.isValid()
6357 && (info.getSleepTimeMillis() <= activityDurationMs)
6358 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006359 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006360 && (totalTxTimeMs <= activityDurationMs));
6361 }
6362
Jack Yu85bd38a2015-11-09 11:34:32 -08006363 /**
6364 * {@hide}
6365 * Returns the service state information on specified subscription.
6366 */
6367 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006368 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6369 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006370 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006371 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006372 return null;
6373 }
6374
Hall Liuf19c44f2018-11-27 14:38:17 -08006375 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6376 LocationAccessPolicy.checkLocationPermission(mApp,
6377 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6378 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006379 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006380 .setCallingPid(Binder.getCallingPid())
6381 .setCallingUid(Binder.getCallingUid())
6382 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006383 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006384 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6385 .build());
6386
6387 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6388 LocationAccessPolicy.checkLocationPermission(mApp,
6389 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6390 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006391 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006392 .setCallingPid(Binder.getCallingPid())
6393 .setCallingUid(Binder.getCallingUid())
6394 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006395 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006396 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6397 .build());
6398 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6399 boolean hasFinePermission =
6400 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6401 boolean hasCoarsePermission =
6402 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6403
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006404 final long identity = Binder.clearCallingIdentity();
6405 try {
6406 final Phone phone = getPhone(subId);
6407 if (phone == null) {
6408 return null;
6409 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006410
Hall Liuf19c44f2018-11-27 14:38:17 -08006411 ServiceState ss = phone.getServiceState();
6412
6413 // Scrub out the location info in ServiceState depending on what level of access
6414 // the caller has.
6415 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006416 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6417 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006418 } finally {
6419 Binder.restoreCallingIdentity(identity);
6420 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006421 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006422
6423 /**
6424 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6425 *
6426 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6427 * voicemail ringtone.
6428 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6429 * PhoneAccount.
6430 */
6431 @Override
6432 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006433 final long identity = Binder.clearCallingIdentity();
6434 try {
6435 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6436 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006437 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006438 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006439
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006440 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6441 } finally {
6442 Binder.restoreCallingIdentity(identity);
6443 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006444 }
6445
6446 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006447 * Sets the per-account voicemail ringtone.
6448 *
6449 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6450 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6451 *
6452 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6453 * voicemail ringtone.
6454 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6455 * PhoneAccount.
6456 */
6457 @Override
6458 public void setVoicemailRingtoneUri(String callingPackage,
6459 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006460 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006461 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006462 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6463 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006464 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6465 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6466 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006467 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006468
6469 final long identity = Binder.clearCallingIdentity();
6470 try {
6471 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6472 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006473 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006474 }
6475 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6476 } finally {
6477 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006478 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006479 }
6480
6481 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006482 * Returns whether vibration is set for voicemail notification in Phone settings.
6483 *
6484 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6485 * voicemail vibration setting.
6486 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6487 */
6488 @Override
6489 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006490 final long identity = Binder.clearCallingIdentity();
6491 try {
6492 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6493 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006494 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006495 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006496
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006497 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6498 } finally {
6499 Binder.restoreCallingIdentity(identity);
6500 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006501 }
6502
Youhan Wange64578a2016-05-02 15:32:42 -07006503 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006504 * Sets the per-account voicemail vibration.
6505 *
6506 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6507 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6508 *
6509 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6510 * voicemail vibration setting.
6511 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6512 * specific PhoneAccount.
6513 */
6514 @Override
6515 public void setVoicemailVibrationEnabled(String callingPackage,
6516 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006517 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006518 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006519 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6520 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006521 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6522 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6523 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006524 }
6525
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006526 final long identity = Binder.clearCallingIdentity();
6527 try {
6528 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6529 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006530 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006531 }
6532 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6533 } finally {
6534 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006535 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006536 }
6537
6538 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006539 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6540 *
6541 * @throws SecurityException if the caller does not have the required permission
6542 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006543 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006544 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006545 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006546 }
6547
6548 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006549 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6550 * permission.
6551 *
6552 * @throws SecurityException if the caller does not have the required permission
6553 */
6554 private void enforceSendSmsPermission() {
6555 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6556 }
6557
6558 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006559 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006560 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006561 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006562 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006563 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006564 final long identity = Binder.clearCallingIdentity();
6565 try {
6566 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006567 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006568 if (componentName == null) {
6569 throw new SecurityException(
6570 "Caller not current active visual voicemail package[null]");
6571 }
6572 String vvmPackage = componentName.getPackageName();
6573 if (!callingPackage.equals(vvmPackage)) {
6574 throw new SecurityException("Caller not current active visual voicemail package["
6575 + vvmPackage + "]");
6576 }
6577 } finally {
6578 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006579 }
6580 }
6581
6582 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006583 * Return the application ID for the app type.
6584 *
6585 * @param subId the subscription ID that this request applies to.
6586 * @param appType the uicc app type.
6587 * @return Application ID for specificied app type, or null if no uicc.
6588 */
6589 @Override
6590 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006591 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006592 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006593
6594 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006595 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006596 if (phone == null) {
6597 return null;
6598 }
6599 String aid = null;
6600 try {
6601 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6602 .getApplicationByType(appType).getAid();
6603 } catch (Exception e) {
6604 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6605 }
6606 return aid;
6607 } finally {
6608 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006609 }
Youhan Wange64578a2016-05-02 15:32:42 -07006610 }
6611
Youhan Wang4001d252016-05-11 10:29:41 -07006612 /**
6613 * Return the Electronic Serial Number.
6614 *
6615 * @param subId the subscription ID that this request applies to.
6616 * @return ESN or null if error.
6617 */
6618 @Override
6619 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006620 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006621 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006622
6623 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006624 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006625 if (phone == null) {
6626 return null;
6627 }
6628 String esn = null;
6629 try {
6630 esn = phone.getEsn();
6631 } catch (Exception e) {
6632 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6633 }
6634 return esn;
6635 } finally {
6636 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006637 }
Youhan Wang4001d252016-05-11 10:29:41 -07006638 }
6639
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006640 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006641 * Return the Preferred Roaming List Version.
6642 *
6643 * @param subId the subscription ID that this request applies to.
6644 * @return PRLVersion or null if error.
6645 */
6646 @Override
6647 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006648 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006649 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006650
6651 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006652 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006653 if (phone == null) {
6654 return null;
6655 }
6656 String cdmaPrlVersion = null;
6657 try {
6658 cdmaPrlVersion = phone.getCdmaPrlVersion();
6659 } catch (Exception e) {
6660 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6661 }
6662 return cdmaPrlVersion;
6663 } finally {
6664 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006665 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006666 }
6667
6668 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006669 * Get snapshot of Telephony histograms
6670 * @return List of Telephony histograms
6671 * @hide
6672 */
6673 @Override
6674 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6676 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006677
6678 final long identity = Binder.clearCallingIdentity();
6679 try {
6680 return RIL.getTelephonyRILTimingHistograms();
6681 } finally {
6682 Binder.restoreCallingIdentity(identity);
6683 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006684 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006685
6686 /**
6687 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006688 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6689 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006690 * Require system privileges. In the future we may add this to carrier APIs.
6691 *
Michele Berionne482f8202018-11-27 18:57:59 -08006692 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006693 */
6694 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006695 @TelephonyManager.SetCarrierRestrictionResult
6696 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006697 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006698 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006699
Michele Berionne482f8202018-11-27 18:57:59 -08006700 if (carrierRestrictionRules == null) {
6701 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006702 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006703
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006704 final long identity = Binder.clearCallingIdentity();
6705 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006706 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006707 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006708 } finally {
6709 Binder.restoreCallingIdentity(identity);
6710 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006711 }
6712
6713 /**
6714 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006715 * Get the allowed carrier list and the excluded carrier list, including the priority between
6716 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006717 * Require system privileges. In the future we may add this to carrier APIs.
6718 *
Michele Berionne482f8202018-11-27 18:57:59 -08006719 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006720 */
6721 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006722 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006723 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006724 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006725
6726 final long identity = Binder.clearCallingIdentity();
6727 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006728 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6729 if (response instanceof CarrierRestrictionRules) {
6730 return (CarrierRestrictionRules) response;
6731 }
6732 // Response is an Exception of some kind,
6733 // which is signalled to the user as a NULL retval
6734 return null;
6735 } catch (Exception e) {
6736 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6737 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006738 } finally {
6739 Binder.restoreCallingIdentity(identity);
6740 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006741 }
6742
fionaxu59545b42016-05-25 15:53:37 -07006743 /**
6744 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6745 * @param subId the subscription ID that this action applies to.
6746 * @param enabled control enable or disable metered apns.
6747 * {@hide}
6748 */
6749 @Override
6750 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6751 enforceModifyPermission();
6752 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006753
6754 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006755 if (phone == null) {
6756 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6757 return;
6758 }
6759 try {
6760 phone.carrierActionSetMeteredApnsEnabled(enabled);
6761 } catch (Exception e) {
6762 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006763 } finally {
6764 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006765 }
6766 }
6767
6768 /**
6769 * Action set from carrier signalling broadcast receivers to enable/disable radio
6770 * @param subId the subscription ID that this action applies to.
6771 * @param enabled control enable or disable radio.
6772 * {@hide}
6773 */
6774 @Override
6775 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6776 enforceModifyPermission();
6777 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006778
6779 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006780 if (phone == null) {
6781 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6782 return;
6783 }
6784 try {
6785 phone.carrierActionSetRadioEnabled(enabled);
6786 } catch (Exception e) {
6787 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006788 } finally {
6789 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006790 }
6791 }
6792
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006793 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006794 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6795 * network status based on which carrier apps could apply actions accordingly,
6796 * enable/disable default url handler for example.
6797 *
6798 * @param subId the subscription ID that this action applies to.
6799 * @param report control start/stop reporting the default network status.
6800 * {@hide}
6801 */
6802 @Override
6803 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6804 enforceModifyPermission();
6805 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006806
6807 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006808 if (phone == null) {
6809 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6810 return;
6811 }
6812 try {
6813 phone.carrierActionReportDefaultNetworkStatus(report);
6814 } catch (Exception e) {
6815 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006816 } finally {
6817 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006818 }
6819 }
6820
6821 /**
fionaxud9622282017-07-17 17:51:30 -07006822 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6823 * @param subId the subscription ID that this action applies to.
6824 * {@hide}
6825 */
6826 @Override
6827 public void carrierActionResetAll(int subId) {
6828 enforceModifyPermission();
6829 final Phone phone = getPhone(subId);
6830 if (phone == null) {
6831 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6832 return;
6833 }
6834 try {
6835 phone.carrierActionResetAll();
6836 } catch (Exception e) {
6837 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6838 }
6839 }
6840
6841 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006842 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6843 * bug report is being generated.
6844 */
6845 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006846 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006847 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6848 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006849 writer.println("Permission Denial: can't dump Phone from pid="
6850 + Binder.getCallingPid()
6851 + ", uid=" + Binder.getCallingUid()
6852 + "without permission "
6853 + android.Manifest.permission.DUMP);
6854 return;
6855 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006856 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006857 }
Jack Yueb89b242016-06-22 13:27:47 -07006858
Brad Ebingerdac2f002018-04-03 15:17:52 -07006859 @Override
6860 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6861 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6862 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006863 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6864 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006865 }
6866
Jack Yueb89b242016-06-22 13:27:47 -07006867 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006868 * Get aggregated video call data usage since boot.
6869 *
6870 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6871 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006872 * {@hide}
6873 */
6874 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006875 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006876 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6877 null);
6878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006879 final long identity = Binder.clearCallingIdentity();
6880 try {
6881 // NetworkStatsService keeps tracking the active network interface and identity. It
6882 // records the delta with the corresponding network identity.
6883 // We just return the total video call data usage snapshot since boot.
6884 Phone phone = getPhone(subId);
6885 if (phone != null) {
6886 return phone.getVtDataUsage(perUidStats);
6887 }
6888 return null;
6889 } finally {
6890 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006891 }
Jack Yueb89b242016-06-22 13:27:47 -07006892 }
Jack Yu75ab2952016-07-08 14:29:33 -07006893
6894 /**
6895 * Policy control of data connection. Usually used when data limit is passed.
6896 * @param enabled True if enabling the data, otherwise disabling.
6897 * @param subId Subscription index
6898 * {@hide}
6899 */
6900 @Override
6901 public void setPolicyDataEnabled(boolean enabled, int subId) {
6902 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006903
6904 final long identity = Binder.clearCallingIdentity();
6905 try {
6906 Phone phone = getPhone(subId);
6907 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006908 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006909 }
6910 } finally {
6911 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006912 }
6913 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006914
6915 /**
6916 * Get Client request stats
6917 * @return List of Client Request Stats
6918 * @hide
6919 */
6920 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006921 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6922 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006923 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006924 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006925 return null;
6926 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006927 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006928
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006929 final long identity = Binder.clearCallingIdentity();
6930 try {
6931 if (phone != null) {
6932 return phone.getClientRequestStats();
6933 }
6934
6935 return null;
6936 } finally {
6937 Binder.restoreCallingIdentity(identity);
6938 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006939 }
6940
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006941 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006942 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006943 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006944 }
Jack Yueb4124c2017-02-16 15:32:43 -08006945
6946 /**
Grace Chen70990072017-03-24 17:21:30 -07006947 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006948 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006949 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006950 * @param state State of SIM (power down, power up, pass through)
6951 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6952 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6953 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006954 *
6955 **/
6956 @Override
Grace Chen70990072017-03-24 17:21:30 -07006957 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006958 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006959 Phone phone = PhoneFactory.getPhone(slotIndex);
6960
vagdeviaf9a5b92018-08-15 16:01:53 -07006961 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6962
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006963 final long identity = Binder.clearCallingIdentity();
6964 try {
6965 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006966 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006967 }
6968 } finally {
6969 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006970 }
6971 }
Shuo Qiandd210312017-04-12 22:11:33 +00006972
Tyler Gunn65d45c22017-06-05 11:22:26 -07006973 private boolean isUssdApiAllowed(int subId) {
6974 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006975 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006976 if (configManager == null) {
6977 return false;
6978 }
6979 PersistableBundle pb = configManager.getConfigForSubId(subId);
6980 if (pb == null) {
6981 return false;
6982 }
6983 return pb.getBoolean(
6984 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6985 }
6986
Shuo Qiandd210312017-04-12 22:11:33 +00006987 /**
6988 * Check if phone is in emergency callback mode
6989 * @return true if phone is in emergency callback mode
6990 * @param subId sub id
6991 */
goneil9c5f4872017-12-05 14:07:56 -08006992 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006993 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006994 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006995 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006996
6997 final long identity = Binder.clearCallingIdentity();
6998 try {
6999 if (phone != null) {
7000 return phone.isInEcm();
7001 } else {
7002 return false;
7003 }
7004 } finally {
7005 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007006 }
7007 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007008
7009 /**
7010 * Get the current signal strength information for the given subscription.
7011 * Because this information is not updated when the device is in a low power state
7012 * it should not be relied-upon to be current.
7013 * @param subId Subscription index
7014 * @return the most recent cached signal strength info from the modem
7015 */
7016 @Override
7017 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007018 final long identity = Binder.clearCallingIdentity();
7019 try {
7020 Phone p = getPhone(subId);
7021 if (p == null) {
7022 return null;
7023 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007024
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007025 return p.getSignalStrength();
7026 } finally {
7027 Binder.restoreCallingIdentity(identity);
7028 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007029 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007030
Pengquan Meng77b7f132018-08-22 14:49:57 -07007031 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007032 * Get the current modem radio state for the given slot.
7033 * @param slotIndex slot index.
7034 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007035 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007036 * @return the current radio power state from the modem
7037 */
7038 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007039 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007040 Phone phone = PhoneFactory.getPhone(slotIndex);
7041 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007042 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7043 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007044 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7045 }
7046
7047 final long identity = Binder.clearCallingIdentity();
7048 try {
7049 return phone.getRadioPowerState();
7050 } finally {
7051 Binder.restoreCallingIdentity(identity);
7052 }
7053 }
7054 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7055 }
7056
7057 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007058 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7059 *
7060 * <p>Requires one of the following permissions:
7061 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7062 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7063 * privileges.
7064 *
7065 * @param subId subscription id
7066 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7067 * {@code false}.
7068 */
7069 @Override
7070 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007071 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7072 null /* message */);
7073
Pengquan Menga1bb6272018-09-06 09:59:22 -07007074 boolean isEnabled = false;
7075 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007076 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007077 Phone phone = getPhone(subId);
7078 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007079 } catch (Exception e) {
7080 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7081 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007082 } finally {
7083 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007084 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007085 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007086 }
7087
7088
7089 /**
7090 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7091 *
7092 * <p> Requires permission:
7093 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7094 * privileges.
7095 *
7096 * @param subId subscription id
7097 * @param isEnabled {@code true} means enable, {@code false} means disable.
7098 */
7099 @Override
7100 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7102 mApp, subId, "setDataRoamingEnabled");
7103
Pengquan Menga1bb6272018-09-06 09:59:22 -07007104 final long identity = Binder.clearCallingIdentity();
7105 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007106 Phone phone = getPhone(subId);
7107 if (phone != null) {
7108 phone.setDataRoamingEnabled(isEnabled);
7109 }
7110 } finally {
7111 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007112 }
7113 }
7114
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007115 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007116 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007117 TelephonyPermissions
7118 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007119 mApp, subId, "isManualNetworkSelectionAllowed");
7120
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007121 boolean isAllowed = true;
7122 final long identity = Binder.clearCallingIdentity();
7123 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007124 Phone phone = getPhone(subId);
7125 if (phone != null) {
7126 isAllowed = phone.isCspPlmnEnabled();
7127 }
7128 } finally {
7129 Binder.restoreCallingIdentity(identity);
7130 }
7131 return isAllowed;
7132 }
7133
7134 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007135 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007136 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007137 try {
7138 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007139 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007140 } catch (SecurityException e) {
7141 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7142 // has carrier privileges on an active UICC
7143 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7144 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007145 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007146 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007147 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007148
7149 final long identity = Binder.clearCallingIdentity();
7150 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007151 UiccController uiccController = UiccController.getInstance();
7152 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007153 if (hasReadPermission) {
7154 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007155 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007156
7157 // Remove private info if the caller doesn't have access
7158 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7159 for (UiccCardInfo cardInfo : cardInfos) {
7160 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7161 // is available
7162 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7163 if (card == null || card.getUiccProfile() == null) {
7164 // assume no access if the card or profile is unavailable
7165 filteredInfos.add(cardInfo.getUnprivileged());
7166 continue;
7167 }
7168 UiccProfile profile = card.getUiccProfile();
7169 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7170 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7171 filteredInfos.add(cardInfo);
7172 } else {
7173 filteredInfos.add(cardInfo.getUnprivileged());
7174 }
7175 }
7176 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007177 } finally {
7178 Binder.restoreCallingIdentity(identity);
7179 }
7180 }
7181
7182 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007183 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007184 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007185
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007186 final long identity = Binder.clearCallingIdentity();
7187 try {
7188 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7189 if (slots == null) {
7190 Rlog.i(LOG_TAG, "slots is null.");
7191 return null;
7192 }
7193
7194 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7195 for (int i = 0; i < slots.length; i++) {
7196 UiccSlot slot = slots[i];
7197 if (slot == null) {
7198 continue;
7199 }
7200
Jordan Liu7be7e652019-05-06 18:55:02 +00007201 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007202 UiccCard card = slot.getUiccCard();
7203 if (card != null) {
7204 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007205 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007206 cardId = slot.getEid();
7207 if (TextUtils.isEmpty(cardId)) {
7208 cardId = slot.getIccId();
7209 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007210 }
7211
Jordan Liu857451f2019-05-09 16:35:35 -07007212 if (cardId != null) {
7213 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7214 // if cardId is an EID, it's all digits so this is fine
7215 cardId = IccUtils.stripTrailingFs(cardId);
7216 }
7217
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007218 int cardState = 0;
7219 switch (slot.getCardState()) {
7220 case CARDSTATE_ABSENT:
7221 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7222 break;
7223 case CARDSTATE_PRESENT:
7224 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7225 break;
7226 case CARDSTATE_ERROR:
7227 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7228 break;
7229 case CARDSTATE_RESTRICTED:
7230 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7231 break;
7232 default:
7233 break;
7234
7235 }
7236
7237 infos[i] = new UiccSlotInfo(
7238 slot.isActive(),
7239 slot.isEuicc(),
7240 cardId,
7241 cardState,
7242 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007243 slot.isExtendedApduSupported(),
7244 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007245 }
7246 return infos;
7247 } finally {
7248 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007249 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007250 }
7251
7252 @Override
7253 public boolean switchSlots(int[] physicalSlots) {
7254 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007255
7256 final long identity = Binder.clearCallingIdentity();
7257 try {
7258 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7259 } finally {
7260 Binder.restoreCallingIdentity(identity);
7261 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007262 }
Jack Yu4c988042018-02-27 15:30:01 -08007263
7264 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007265 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007266 final long identity = Binder.clearCallingIdentity();
7267 try {
7268 return UiccController.getInstance().getCardIdForDefaultEuicc();
7269 } finally {
7270 Binder.restoreCallingIdentity(identity);
7271 }
7272 }
7273
7274 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007275 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7276 enforceModifyPermission();
7277 final Phone phone = getPhone(subId);
7278 if (phone == null) {
7279 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7280 return;
7281 }
7282
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007283 final long identity = Binder.clearCallingIdentity();
7284 try {
7285 phone.setRadioIndicationUpdateMode(filters, mode);
7286 } finally {
7287 Binder.restoreCallingIdentity(identity);
7288 }
Jack Yu4c988042018-02-27 15:30:01 -08007289 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007290
7291 /**
goneil47ffb6e2018-04-06 15:40:58 -07007292 * A test API to reload the UICC profile.
7293 *
7294 * <p>Requires that the calling app has permission
7295 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7296 * @hide
7297 */
7298 @Override
7299 public void refreshUiccProfile(int subId) {
7300 enforceModifyPermission();
7301
7302 final long identity = Binder.clearCallingIdentity();
7303 try {
7304 Phone phone = getPhone(subId);
7305 if (phone == null) {
7306 return;
7307 }
7308 UiccCard uiccCard = phone.getUiccCard();
7309 if (uiccCard == null) {
7310 return;
7311 }
7312 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7313 if (uiccProfile == null) {
7314 return;
7315 }
7316 uiccProfile.refresh();
7317 } finally {
7318 Binder.restoreCallingIdentity(identity);
7319 }
7320 }
7321
7322 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007323 * Returns false if the mobile data is disabled by default, otherwise return true.
7324 */
7325 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007326 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007327 }
7328
7329 /**
7330 * Returns true if the data roaming is enabled by default, i.e the system property
7331 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7332 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7333 */
7334 private boolean getDefaultDataRoamingEnabled(int subId) {
7335 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007336 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007337 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007338 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7339 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7340 return isDataRoamingEnabled;
7341 }
7342
7343 /**
7344 * Returns the default network type for the given {@code subId}, if the default network type is
7345 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7346 */
7347 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007348 List<Integer> list = TelephonyProperties.default_network();
7349 int phoneId = mSubscriptionController.getPhoneId(subId);
7350 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7351 return list.get(phoneId);
7352 }
7353 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007354 }
fionaxua13278b2018-03-21 00:08:13 -07007355
7356 @Override
7357 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007358 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007359 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007360
7361 final long identity = Binder.clearCallingIdentity();
7362 try {
7363 final Phone phone = getPhone(subId);
7364 if (phone == null) {
7365 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7366 return;
7367 }
chen xueaba88a2019-03-15 13:15:10 -07007368 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7369 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007370 } finally {
7371 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007372 }
fionaxua13278b2018-03-21 00:08:13 -07007373 }
7374
7375 @Override
7376 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007377 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007378
7379 final long identity = Binder.clearCallingIdentity();
7380 try {
7381 final Phone phone = getPhone(subId);
7382 if (phone == null) {
7383 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7384 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7385 }
7386 return phone.getCarrierIdListVersion();
7387 } finally {
7388 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007389 }
fionaxua13278b2018-03-21 00:08:13 -07007390 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007391
7392 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007393 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7394 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007395 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007396 mApp, subId, callingPackage, callingFeatureId,
7397 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007398 return -1;
7399 }
7400
7401 final long identity = Binder.clearCallingIdentity();
7402 try {
7403 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7404 } finally {
7405 Binder.restoreCallingIdentity(identity);
7406 }
7407 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007408
7409 @Override
7410 public int getCdmaRoamingMode(int subId) {
7411 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7412 mApp, subId, "getCdmaRoamingMode");
7413
7414 final long identity = Binder.clearCallingIdentity();
7415 try {
7416 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7417 } finally {
7418 Binder.restoreCallingIdentity(identity);
7419 }
7420 }
7421
7422 @Override
7423 public boolean setCdmaRoamingMode(int subId, int mode) {
7424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7425 mApp, subId, "setCdmaRoamingMode");
7426
7427 final long identity = Binder.clearCallingIdentity();
7428 try {
7429 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7430 } finally {
7431 Binder.restoreCallingIdentity(identity);
7432 }
7433 }
7434
7435 @Override
7436 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7437 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7438 mApp, subId, "setCdmaSubscriptionMode");
7439
7440 final long identity = Binder.clearCallingIdentity();
7441 try {
7442 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7443 } finally {
7444 Binder.restoreCallingIdentity(identity);
7445 }
7446 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007447
sqianc5eccab2018-10-19 18:46:41 -07007448 @Override
sqian8c685422019-02-22 15:55:18 -08007449 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007450 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007451 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007452 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7453 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007454 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7455 }
7456 final long identity = Binder.clearCallingIdentity();
7457 try {
sqian854d44b2018-12-12 16:48:18 -08007458 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7459 for (Phone phone: PhoneFactory.getPhones()) {
7460 if (phone.getEmergencyNumberTracker() != null
7461 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7462 emergencyNumberListInternal.put(
7463 phone.getSubId(),
7464 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7465 }
sqian11b7a0e2018-12-05 18:48:28 -08007466 }
sqian854d44b2018-12-12 16:48:18 -08007467 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007468 } finally {
7469 Binder.restoreCallingIdentity(identity);
7470 }
sqianc5eccab2018-10-19 18:46:41 -07007471 }
7472
7473 @Override
sqian8c685422019-02-22 15:55:18 -08007474 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007475 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007476 if (!exactMatch) {
7477 TelephonyPermissions
7478 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007479 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007480 }
7481 final long identity = Binder.clearCallingIdentity();
7482 try {
sqian854d44b2018-12-12 16:48:18 -08007483 for (Phone phone: PhoneFactory.getPhones()) {
7484 if (phone.getEmergencyNumberTracker() != null
7485 && phone.getEmergencyNumberTracker() != null) {
7486 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7487 number, exactMatch)) {
7488 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007489 }
7490 }
sqian11b7a0e2018-12-05 18:48:28 -08007491 }
7492 return false;
7493 } finally {
7494 Binder.restoreCallingIdentity(identity);
7495 }
7496 }
7497
sqianf4ca7ed2019-01-15 18:32:07 -08007498 /**
7499 * Update emergency number list for test mode.
7500 */
7501 @Override
7502 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7503 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7504 "updateEmergencyNumberListTestMode");
7505
7506 final long identity = Binder.clearCallingIdentity();
7507 try {
7508 for (Phone phone: PhoneFactory.getPhones()) {
7509 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7510 if (tracker != null) {
7511 tracker.executeEmergencyNumberTestModeCommand(action, num);
7512 }
7513 }
7514 } finally {
7515 Binder.restoreCallingIdentity(identity);
7516 }
7517 }
7518
7519 /**
7520 * Get the full emergency number list for test mode.
7521 */
7522 @Override
7523 public List<String> getEmergencyNumberListTestMode() {
7524 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7525 "getEmergencyNumberListTestMode");
7526
7527 final long identity = Binder.clearCallingIdentity();
7528 try {
7529 Set<String> emergencyNumbers = new HashSet<>();
7530 for (Phone phone: PhoneFactory.getPhones()) {
7531 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7532 if (tracker != null) {
7533 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7534 emergencyNumbers.add(num.getNumber());
7535 }
7536 }
7537 }
7538 return new ArrayList<>(emergencyNumbers);
7539 } finally {
7540 Binder.restoreCallingIdentity(identity);
7541 }
7542 }
7543
chen xud6b45bd2018-10-30 22:27:10 -07007544 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007545 public int getEmergencyNumberDbVersion(int subId) {
7546 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7547
7548 final long identity = Binder.clearCallingIdentity();
7549 try {
7550 final Phone phone = getPhone(subId);
7551 if (phone == null) {
7552 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7553 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7554 }
7555 return phone.getEmergencyNumberDbVersion();
7556 } finally {
7557 Binder.restoreCallingIdentity(identity);
7558 }
7559 }
7560
7561 @Override
7562 public void notifyOtaEmergencyNumberDbInstalled() {
7563 enforceModifyPermission();
7564
7565 final long identity = Binder.clearCallingIdentity();
7566 try {
7567 for (Phone phone: PhoneFactory.getPhones()) {
7568 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7569 if (tracker != null) {
7570 tracker.updateOtaEmergencyNumberDatabase();
7571 }
7572 }
7573 } finally {
7574 Binder.restoreCallingIdentity(identity);
7575 }
7576 }
7577
7578 @Override
7579 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7580 enforceActiveEmergencySessionPermission();
7581
7582 final long identity = Binder.clearCallingIdentity();
7583 try {
7584 for (Phone phone: PhoneFactory.getPhones()) {
7585 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7586 if (tracker != null) {
7587 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7588 }
7589 }
7590 } finally {
7591 Binder.restoreCallingIdentity(identity);
7592 }
7593 }
7594
7595 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007596 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7597 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7598 Phone phone = getPhone(subId);
7599 if (phone == null) {
7600 return null;
7601 }
7602 final long identity = Binder.clearCallingIdentity();
7603 try {
7604 UiccProfile profile = UiccController.getInstance()
7605 .getUiccProfileForPhone(phone.getPhoneId());
7606 if (profile != null) {
7607 return profile.getCertsFromCarrierPrivilegeAccessRules();
7608 }
7609 } finally {
7610 Binder.restoreCallingIdentity(identity);
7611 }
7612 return null;
7613 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007614
7615 /**
7616 * Enable or disable a modem stack.
7617 */
7618 @Override
7619 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7620 enforceModifyPermission();
7621
7622 final long identity = Binder.clearCallingIdentity();
7623 try {
7624 Phone phone = PhoneFactory.getPhone(slotIndex);
7625 if (phone == null) {
7626 return false;
7627 } else {
7628 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7629 }
7630 } finally {
7631 Binder.restoreCallingIdentity(identity);
7632 }
7633 }
Michelecea4cf22018-12-21 15:00:11 -08007634
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007635 /**
7636 * Whether a modem stack is enabled or not.
7637 */
7638 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007639 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7640 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007641 Phone phone = PhoneFactory.getPhone(slotIndex);
7642 if (phone == null) return false;
7643
7644 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007645 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7646 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007647 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7648 }
7649
7650 final long identity = Binder.clearCallingIdentity();
7651 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007652 try {
7653 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7654 } catch (NoSuchElementException ex) {
7655 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7656 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007657 } finally {
7658 Binder.restoreCallingIdentity(identity);
7659 }
7660 }
7661
Michelecea4cf22018-12-21 15:00:11 -08007662 @Override
Michele0ea7d782019-03-19 14:58:42 -07007663 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007664 enforceModifyPermission();
7665
7666 final long identity = Binder.clearCallingIdentity();
7667 try {
7668 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007669 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007670 .commit();
7671 } finally {
7672 Binder.restoreCallingIdentity(identity);
7673 }
7674 }
7675
7676 @Override
Michele0ea7d782019-03-19 14:58:42 -07007677 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007678 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007679 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007680 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7681 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007682 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007683 }
Michelecea4cf22018-12-21 15:00:11 -08007684
7685 final long identity = Binder.clearCallingIdentity();
7686 try {
Michele0ea7d782019-03-19 14:58:42 -07007687 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007688 } finally {
7689 Binder.restoreCallingIdentity(identity);
7690 }
7691 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007692
Michele0ea7d782019-03-19 14:58:42 -07007693 @TelephonyManager.IsMultiSimSupportedResult
7694 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007695 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7696 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7697 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007698 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7699 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007700 }
7701 // Check if the hardware supports multisim functionality. If usage of multisim is not
7702 // supported by the modem, indicate that it is restricted.
7703 PhoneCapability staticCapability =
7704 mPhoneConfigurationManager.getStaticPhoneCapability();
7705 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007706 loge("isMultiSimSupportedInternal: no static configuration available");
7707 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007708 }
Sarah Chin5f0ecd72019-12-06 10:24:18 -08007709 if (staticCapability.getLogicalModemUuids().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007710 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7711 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007712 }
7713 // Check if support of multiple SIMs is restricted by carrier
7714 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007715 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007716 }
7717
Michele0ea7d782019-03-19 14:58:42 -07007718 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007719 }
7720
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007721 /**
7722 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007723 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7724 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7725 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007726 * @param numOfSims number of active sims we want to switch to
7727 */
7728 @Override
7729 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007730 if (numOfSims == 1) {
7731 enforceModifyPermission();
7732 } else {
7733 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7734 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7735 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007736 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007737
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007738 try {
Michele30b57b22019-03-01 12:01:14 -08007739 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007740 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007741 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7742 return;
7743 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007744 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7745 } finally {
7746 Binder.restoreCallingIdentity(identity);
7747 }
7748 }
7749
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007750 @Override
7751 public boolean isApplicationOnUicc(int subId, int appType) {
7752 enforceReadPrivilegedPermission("isApplicationOnUicc");
7753 Phone phone = getPhone(subId);
7754 if (phone == null) {
7755 return false;
7756 }
7757 final long identity = Binder.clearCallingIdentity();
7758 try {
7759 UiccCard uiccCard = phone.getUiccCard();
7760 if (uiccCard == null) {
7761 return false;
7762 }
7763 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7764 if (uiccProfile == null) {
7765 return false;
7766 }
7767 if (TelephonyManager.APPTYPE_SIM <= appType
7768 && appType <= TelephonyManager.APPTYPE_ISIM) {
7769 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7770 }
7771 return false;
7772 } finally {
7773 Binder.restoreCallingIdentity(identity);
7774 }
7775 }
7776
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007777 /**
chen xub4baa772019-04-03 10:23:41 -07007778 * Get whether making changes to modem configurations will trigger reboot.
7779 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007780 */
7781 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007782 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7783 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007784 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007785 mApp, subId, callingPackage, callingFeatureId,
7786 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007787 return false;
7788 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007789 final long identity = Binder.clearCallingIdentity();
7790 try {
7791 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7792 } finally {
7793 Binder.restoreCallingIdentity(identity);
7794 }
7795 }
7796
Nathan Harold29f5f052019-02-15 13:41:57 -08007797 private void updateModemStateMetrics() {
7798 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7799 // TODO: check the state for each modem if the api is ready.
7800 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7801 }
7802
Pengquan Meng3889a572019-01-23 11:16:29 -08007803 @Override
7804 public int[] getSlotsMapping() {
7805 enforceReadPrivilegedPermission("getSlotsMapping");
7806
7807 final long identity = Binder.clearCallingIdentity();
7808 try {
7809 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7810 // All logical slots should have a mapping to a physical slot.
7811 int[] logicalSlotsMapping = new int[phoneCount];
7812 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7813 for (int i = 0; i < slotInfos.length; i++) {
7814 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7815 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7816 }
7817 }
7818 return logicalSlotsMapping;
7819 } finally {
7820 Binder.restoreCallingIdentity(identity);
7821 }
7822 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007823
7824 /**
7825 * Get the IRadio HAL Version
7826 */
7827 @Override
7828 public int getRadioHalVersion() {
7829 Phone phone = getDefaultPhone();
7830 if (phone == null) return -1;
7831 HalVersion hv = phone.getHalVersion();
7832 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7833 return hv.major * 100 + hv.minor;
7834 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007835
7836 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007837 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7838 * corresponding network requests on a subId.
7839 *
7840 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007841 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007842 * 2) APN is un-metered for this subscription, or
7843 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7844 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7845 *
7846 * @return whether data is allowed for a apn type.
7847 *
7848 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007849 */
7850 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007851 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07007852 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7853 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007854
7855 // Now that all security checks passes, perform the operation as ourselves.
7856 final long identity = Binder.clearCallingIdentity();
7857 try {
7858 Phone phone = getPhone(subId);
7859 if (phone == null) return false;
7860
Jack Yu41407ee2019-05-13 16:54:09 -07007861 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007862 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7863 } finally {
7864 Binder.restoreCallingIdentity(identity);
7865 }
7866 }
7867
7868 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007869 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007870 enforceReadPrivilegedPermission("isApnMetered");
7871
7872 // Now that all security checks passes, perform the operation as ourselves.
7873 final long identity = Binder.clearCallingIdentity();
7874 try {
7875 Phone phone = getPhone(subId);
7876 if (phone == null) return true; // By default return true.
7877
Jack Yu41407ee2019-05-13 16:54:09 -07007878 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007879 } finally {
7880 Binder.restoreCallingIdentity(identity);
7881 }
7882 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007883
7884 @Override
changbetty363e8ac2019-12-06 18:16:37 +08007885 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
7886 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
7887 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
7888 if (iccRecords == null) {
7889 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
7890 return false;
7891 }
7892 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
7893 }
7894
7895 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07007896 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7897 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7898 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7899 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7900 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7901 }
7902 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7903 Intent intent = new Intent();
7904 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7905 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7906 // Bring up choose default SMS subscription dialog right now
7907 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7908 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7909 mApp.startActivity(intent);
7910 }
chen xud5ca2d52019-05-28 15:20:57 -07007911
7912 @Override
7913 public String getMmsUAProfUrl(int subId) {
7914 //TODO investigate if this API should require proper permission check in R b/133791609
7915 final long identity = Binder.clearCallingIdentity();
7916 try {
7917 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7918 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7919 } finally {
7920 Binder.restoreCallingIdentity(identity);
7921 }
7922 }
7923
7924 @Override
7925 public String getMmsUserAgent(int subId) {
7926 //TODO investigate if this API should require proper permission check in R b/133791609
7927 final long identity = Binder.clearCallingIdentity();
7928 try {
7929 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7930 .getString(com.android.internal.R.string.config_mms_user_agent);
7931 } finally {
7932 Binder.restoreCallingIdentity(identity);
7933 }
7934 }
Jack Yub07d4972019-05-28 16:12:25 -07007935
7936 @Override
7937 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7938 enforceModifyPermission();
7939
7940 // Now that all security checks passes, perform the operation as ourselves.
7941 final long identity = Binder.clearCallingIdentity();
7942 try {
7943 Phone phone = getPhone(subId);
7944 if (phone == null) return false;
7945
7946 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7947 } finally {
7948 Binder.restoreCallingIdentity(identity);
7949 }
7950 }
7951
7952 @Override
7953 public boolean isDataAllowedInVoiceCall(int subId) {
7954 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7955
7956 // Now that all security checks passes, perform the operation as ourselves.
7957 final long identity = Binder.clearCallingIdentity();
7958 try {
7959 Phone phone = getPhone(subId);
7960 if (phone == null) return false;
7961
7962 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7963 } finally {
7964 Binder.restoreCallingIdentity(identity);
7965 }
7966 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007967
7968 /**
7969 * Updates whether conference event pacakge handling is enabled.
7970 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7971 * otherwise.
7972 */
7973 @Override
7974 public void setCepEnabled(boolean isCepEnabled) {
7975 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7976
7977 final long identity = Binder.clearCallingIdentity();
7978 try {
7979 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7980 for (Phone phone : PhoneFactory.getPhones()) {
7981 Phone defaultPhone = phone.getImsPhone();
7982 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7983 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7984 ImsPhoneCallTracker imsPhoneCallTracker =
7985 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7986 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7987 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7988 + imsPhone.getMsisdn());
7989 }
7990 }
7991 } finally {
7992 Binder.restoreCallingIdentity(identity);
7993 }
7994 }
allenwtsu46dcc572020-01-08 18:24:03 +08007995
7996 /**
7997 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
7998 *
7999 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8000 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8001 * before being read.
8002 */
8003 @Override
8004 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8005 isCompressed) {
8006 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8007 mApp, subId, "notifyRcsAutoConfigurationReceived");
8008 try {
8009 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8010 if (configBinder == null) {
8011 Rlog.e(LOG_TAG, "null result for getImsConfig");
8012 } else {
8013 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8014 }
8015 } catch (RemoteException e) {
8016 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8017 }
8018 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008019}