blob: b4cef7d3a34811ad5d4031944fe5e8b8efc44f3a [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
Brad Ebingerb2b65522019-03-15 13:48:47 -07002970 public boolean isInEmergencySmsMode() {
2971 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2972 final long identity = Binder.clearCallingIdentity();
2973 try {
2974 for (Phone phone : PhoneFactory.getPhones()) {
2975 if (phone.isInEmergencySmsMode()) {
2976 return true;
2977 }
2978 }
2979 } finally {
2980 Binder.restoreCallingIdentity(identity);
2981 }
2982 return false;
2983 }
2984
shilu366312e2019-12-17 09:28:10 -08002985 /**
2986 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
2987 * @param subId The subscription to use to check the configuration.
2988 * @param c The callback that will be used to send the result.
2989 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07002990 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002991 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2992 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08002993 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002994 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08002995
Brad Ebinger77b832e2019-10-17 17:03:22 -07002996 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2997 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2998 "IMS not available on device.");
2999 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003000 final long token = Binder.clearCallingIdentity();
3001 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003002 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003003 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003004 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003005 } catch (ImsException e) {
3006 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003007 } finally {
3008 Binder.restoreCallingIdentity(token);
3009 }
3010 }
3011
shilu366312e2019-12-17 09:28:10 -08003012 /**
3013 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3014 * @param subId The subscription to use to check the configuration.
3015 * @param c The callback that will be used to send the result.
3016 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003017 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003018 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
shilu366312e2019-12-17 09:28:10 -08003019 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003020 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003021 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3022 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3023 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003024 final long token = Binder.clearCallingIdentity();
3025 try {
3026 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3027 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3028 .removeRegistrationCallbackForSubscription(c, subId);
3029 } catch (ImsException e) {
3030 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3031 + "is inactive, ignoring unregister.");
3032 // If the subscription is no longer active, just return, since the callback
3033 // will already have been removed internally.
3034 } finally {
3035 Binder.restoreCallingIdentity(token);
3036 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003037 }
3038
Brad Ebinger774ba362019-10-22 17:36:18 -07003039 /**
3040 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3041 */
3042 @Override
3043 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3044 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3045 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3046 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3047 "IMS not available on device.");
3048 }
3049 final long token = Binder.clearCallingIdentity();
3050 try {
3051 Phone phone = getPhone(subId);
3052 if (phone == null) {
3053 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3054 + subId + "'");
3055 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3056 }
3057 phone.getImsRegistrationState(regState -> {
3058 try {
3059 consumer.accept((regState == null)
3060 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3061 } catch (RemoteException e) {
3062 // Ignore if the remote process is no longer available to call back.
3063 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3064 }
3065 });
3066 } finally {
3067 Binder.restoreCallingIdentity(token);
3068 }
3069 }
3070
3071 /**
3072 * Get the transport type for the IMS service registration state.
3073 */
3074 @Override
3075 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
shilu366312e2019-12-17 09:28:10 -08003076 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger774ba362019-10-22 17:36:18 -07003077 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3078 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3079 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3080 "IMS not available on device.");
3081 }
3082 final long token = Binder.clearCallingIdentity();
3083 try {
3084 Phone phone = getPhone(subId);
3085 if (phone == null) {
3086 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3087 + subId + "'");
3088 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3089 }
3090 phone.getImsRegistrationTech(regTech -> {
3091 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3092 int regTechConverted = (regTech == null)
3093 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3094 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3095 regTechConverted);
3096 try {
3097 consumer.accept(regTechConverted);
3098 } catch (RemoteException e) {
3099 // Ignore if the remote process is no longer available to call back.
3100 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3101 }
3102 });
3103 } finally {
3104 Binder.restoreCallingIdentity(token);
3105 }
3106 }
3107
shilu366312e2019-12-17 09:28:10 -08003108 /**
3109 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3110 * @param subId The subscription to use to check the configuration.
3111 * @param c The callback that will be used to send the result.
3112 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003113 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003114 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3115 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003116 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003117 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003118 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3119 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3120 "IMS not available on device.");
3121 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003122 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3123 final long token = Binder.clearCallingIdentity();
3124 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003125 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003126 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003127 } catch (ImsException e) {
3128 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003129 } finally {
3130 Binder.restoreCallingIdentity(token);
3131 }
3132 }
3133
shilu366312e2019-12-17 09:28:10 -08003134 /**
3135 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3136 * @param subId The subscription to use to check the configuration.
3137 * @param c The callback that will be used to send the result.
3138 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003139 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003140 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
shilu366312e2019-12-17 09:28:10 -08003141 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003142 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003143 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3144 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3145 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003146
3147 final long token = Binder.clearCallingIdentity();
3148 try {
3149 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3150 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003151 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003152 } catch (ImsException e) {
3153 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3154 + "is inactive, ignoring unregister.");
3155 // If the subscription is no longer active, just return, since the callback
3156 // will already have been removed internally.
3157 } finally {
3158 Binder.restoreCallingIdentity(token);
3159 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003160 }
3161
3162 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003163 public boolean isCapable(int subId, int capability, int regTech) {
3164 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003165 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3166 final long token = Binder.clearCallingIdentity();
3167 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003168 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003169 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003170 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003171 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3172 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003173 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003174 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3175 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003176 } finally {
3177 Binder.restoreCallingIdentity(token);
3178 }
3179 }
3180
3181 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003182 public boolean isAvailable(int subId, int capability, int regTech) {
3183 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003184 final long token = Binder.clearCallingIdentity();
3185 try {
3186 Phone phone = getPhone(subId);
3187 if (phone == null) return false;
3188 return phone.isImsCapabilityAvailable(capability, regTech);
3189 } finally {
3190 Binder.restoreCallingIdentity(token);
3191 }
3192 }
3193
Brad Ebinger77b832e2019-10-17 17:03:22 -07003194 /**
3195 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3196 * subscription.
3197 * @param subId The subscription to use to check the configuration.
3198 * @param callback The callback that will be used to send the result.
3199 * @param capability The MmTelFeature capability that will be used to send the result.
3200 * @param transportType The transport type of the MmTelFeature capability.
3201 */
3202 @Override
3203 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3204 int transportType) {
3205 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3206 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3207 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3208 "IMS not available on device.");
3209 }
3210 final long token = Binder.clearCallingIdentity();
3211 try {
3212 int slotId = getSlotIndex(subId);
3213 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3214 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3215 + subId + "'");
3216 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3217 }
3218 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3219 transportType, aBoolean -> {
3220 try {
3221 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3222 } catch (RemoteException e) {
3223 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3224 + "running. Ignore");
3225 }
3226 });
3227 } finally {
3228 Binder.restoreCallingIdentity(token);
3229 }
3230 }
3231
shilu366312e2019-12-17 09:28:10 -08003232 /**
3233 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3234 * @param subId The subscription to use to check the configuration.
3235 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003236 @Override
3237 public boolean isAdvancedCallingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003238 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
3239 enforceReadPrivilegedPermission("isAdvancedCallingSettingEnabled");
3240
Brad Ebinger35c841c2018-10-01 10:40:55 -07003241 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3242 final long token = Binder.clearCallingIdentity();
3243 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003244 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003245 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003246 } catch (ImsException e) {
3247 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003248 } finally {
3249 Binder.restoreCallingIdentity(token);
3250 }
3251 }
3252
3253 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003254 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003255 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003256 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003257 final long identity = Binder.clearCallingIdentity();
3258 try {
3259 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003260 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003261 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003262 } catch (ImsException e) {
3263 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003264 } finally {
3265 Binder.restoreCallingIdentity(identity);
3266 }
3267 }
3268
shilu366312e2019-12-17 09:28:10 -08003269 /**
3270 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3271 * @param subId The subscription to use to check the configuration.
3272 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003273 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003274 public boolean isVtSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003275 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003276 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003277 final long identity = Binder.clearCallingIdentity();
3278 try {
3279 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003280 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3281 } catch (ImsException e) {
3282 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003283 } finally {
3284 Binder.restoreCallingIdentity(identity);
3285 }
3286 }
3287
3288 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003289 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003291 "setVtSettingEnabled");
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.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003295 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003296 } 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
shilu366312e2019-12-17 09:28:10 -08003303 /**
3304 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3305 * @param subId The subscription to use to check the configuration.
3306 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003307 @Override
3308 public boolean isVoWiFiSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003309 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003310 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3311 final long identity = Binder.clearCallingIdentity();
3312 try {
3313 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003314 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003315 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003316 } catch (ImsException e) {
3317 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003318 } finally {
3319 Binder.restoreCallingIdentity(identity);
3320 }
3321 }
3322
3323 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003324 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003325 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003326 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003327 final long identity = Binder.clearCallingIdentity();
3328 try {
3329 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003330 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
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
shilu366312e2019-12-17 09:28:10 -08003338 /**
3339 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3340 * @param subId The subscription to use to check the configuration.
3341 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003342 @Override
3343 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003344 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003345 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3346 final long identity = Binder.clearCallingIdentity();
3347 try {
3348 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003349 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003350 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003351 } catch (ImsException e) {
3352 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003353 } finally {
3354 Binder.restoreCallingIdentity(identity);
3355 }
3356 }
3357
3358 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003359 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003361 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003362 final long identity = Binder.clearCallingIdentity();
3363 try {
3364 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003365 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003366 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003367 } catch (ImsException e) {
3368 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003369 } finally {
3370 Binder.restoreCallingIdentity(identity);
3371 }
3372 }
3373
3374 @Override
3375 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3377 "setVoWiFiNonPersistent");
3378 final long identity = Binder.clearCallingIdentity();
3379 try {
3380 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003381 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003382 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003383 } catch (ImsException e) {
3384 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003385 } finally {
3386 Binder.restoreCallingIdentity(identity);
3387 }
3388 }
3389
shilu366312e2019-12-17 09:28:10 -08003390 /**
3391 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3392 * @param subId The subscription to use to check the configuration.
3393 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003394 @Override
3395 public int getVoWiFiModeSetting(int subId) {
shilu366312e2019-12-17 09:28:10 -08003396 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003397 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3398 final long identity = Binder.clearCallingIdentity();
3399 try {
3400 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003401 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003402 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003403 } catch (ImsException e) {
3404 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003405 } finally {
3406 Binder.restoreCallingIdentity(identity);
3407 }
3408 }
3409
3410 @Override
3411 public void setVoWiFiModeSetting(int subId, int mode) {
3412 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3413 "setVoWiFiModeSetting");
3414 final long identity = Binder.clearCallingIdentity();
3415 try {
3416 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003417 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003418 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003419 } catch (ImsException e) {
3420 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003421 } finally {
3422 Binder.restoreCallingIdentity(identity);
3423 }
3424 }
3425
3426 @Override
3427 public int getVoWiFiRoamingModeSetting(int subId) {
3428 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
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 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003433 getSlotIndexOrException(subId)).getWfcMode(true /*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 void setVoWiFiRoamingModeSetting(int subId, int mode) {
3443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3444 "setVoWiFiRoamingModeSetting");
3445 final long identity = Binder.clearCallingIdentity();
3446 try {
3447 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003448 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003449 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003450 } catch (ImsException e) {
3451 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003452 } finally {
3453 Binder.restoreCallingIdentity(identity);
3454 }
3455 }
3456
3457 @Override
3458 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3459 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3460 "setRttCapabilityEnabled");
3461 final long identity = Binder.clearCallingIdentity();
3462 try {
3463 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003464 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3465 } 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
shilu366312e2019-12-17 09:28:10 -08003472 /**
3473 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3474 * @param subId The subscription to use to check the configuration.
3475 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003476 @Override
3477 public boolean isTtyOverVolteEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003478 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003479 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3480 final long identity = Binder.clearCallingIdentity();
3481 try {
3482 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003483 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003484 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003485 } catch (ImsException e) {
3486 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003487 } finally {
3488 Binder.restoreCallingIdentity(identity);
3489 }
3490 }
3491
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003492 @Override
3493 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3494 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3495 final long identity = Binder.clearCallingIdentity();
3496 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003497 if (!isImsAvailableOnDevice()) {
3498 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3499 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003500 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003501 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003502 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003503 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003504 } catch (ImsException e) {
3505 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003506 } finally {
3507 Binder.restoreCallingIdentity(identity);
3508 }
3509 }
3510
3511 @Override
3512 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3513 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3514 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003515 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3516 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3517 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003518 try {
3519 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003520 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003521 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003522 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003523 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3524 + "is inactive, ignoring unregister.");
3525 // If the subscription is no longer active, just return, since the callback will already
3526 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003527 } finally {
3528 Binder.restoreCallingIdentity(identity);
3529 }
3530 }
3531
allenwtsu99c623b2020-01-03 18:24:23 +08003532
3533 private void checkModifyPhoneStatePermission(int subId, String message) {
3534 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3535 message);
3536 }
3537
3538 private boolean isImsProvisioningRequired(int subId, int capability,
3539 boolean isMmtelCapability) {
3540 Phone phone = getPhone(subId);
3541 if (phone == null) {
3542 loge("phone instance null for subid " + subId);
3543 return false;
3544 }
3545 if (isMmtelCapability) {
3546 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3547 return false;
3548 }
3549 } else {
3550 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3551 return false;
3552 }
3553 }
3554 return true;
3555 }
3556
3557 @Override
3558 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3559 boolean isProvisioned) {
3560 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3561
3562 final long identity = Binder.clearCallingIdentity();
3563 try {
3564 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3565 if (!isImsProvisioningRequired(subId, capability, false)) {
3566 return;
3567 }
3568
3569 // this capability requires provisioning, route to the correct API.
3570 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3571 switch (capability) {
3572 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3573 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3574 ims.setEabProvisioned(isProvisioned);
3575 break;
3576 default: {
3577 throw new IllegalArgumentException("Tried to set provisioning for "
3578 + "rcs capability '" + capability + "', which does not require "
3579 + "provisioning.");
3580 }
3581 }
3582 } finally {
3583 Binder.restoreCallingIdentity(identity);
3584 }
3585
3586 }
3587
3588
3589 @Override
3590 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3591 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3592 final long identity = Binder.clearCallingIdentity();
3593 try {
3594 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3595 if (!isImsProvisioningRequired(subId, capability, false)) {
3596 return true;
3597 }
3598
3599 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3600 switch (capability) {
3601 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3602 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3603 return ims.isEabProvisionedOnDevice();
3604
3605 default: {
3606 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3607 + "capability '" + capability + "', which does not require "
3608 + "provisioning.");
3609 }
3610 }
3611
3612 } finally {
3613 Binder.restoreCallingIdentity(identity);
3614 }
3615 }
3616
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003617 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003618 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3619 boolean isProvisioned) {
3620 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3621 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3622 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3623 }
allenwtsu99c623b2020-01-03 18:24:23 +08003624 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003625 final long identity = Binder.clearCallingIdentity();
3626 try {
3627 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003628 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003629 return;
3630 }
3631
3632 // this capability requires provisioning, route to the correct API.
3633 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3634 switch (capability) {
3635 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3636 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3637 ims.setVolteProvisioned(isProvisioned);
3638 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3639 ims.setWfcProvisioned(isProvisioned);
3640 }
3641 break;
3642 }
3643 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3644 // There is currently no difference in VT provisioning type.
3645 ims.setVtProvisioned(isProvisioned);
3646 break;
3647 }
3648 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3649 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3650 // change the capability of the feature instead if needed.
3651 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3652 == isProvisioned) {
3653 // No change in provisioning.
3654 return;
3655 }
3656 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3657 try {
3658 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003659 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003660 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3661 + ", Exception" + e.getMessage());
3662 }
3663 break;
3664 }
3665 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003666 throw new IllegalArgumentException("Tried to set provisioning for "
3667 + "MmTel capability '" + capability + "', which does not require "
3668 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003669 }
3670 }
3671
3672 } finally {
3673 Binder.restoreCallingIdentity(identity);
3674 }
3675 }
3676
3677 @Override
3678 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3679 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3680 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3681 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3682 }
3683 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3684 final long identity = Binder.clearCallingIdentity();
3685 try {
3686 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003687 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003688 return true;
3689 }
3690
3691 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3692 switch (capability) {
3693 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3694 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3695 return ims.isVolteProvisionedOnDevice();
3696 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3697 return ims.isWfcProvisionedOnDevice();
3698 }
3699 // This should never happen, since we are checking tech above to make sure it
3700 // is either LTE or IWLAN.
3701 throw new IllegalArgumentException("Invalid radio technology for voice "
3702 + "capability.");
3703 }
3704 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3705 // There is currently no difference in VT provisioning type.
3706 return ims.isVtProvisionedOnDevice();
3707 }
3708 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3709 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3710 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3711 }
3712 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003713 throw new IllegalArgumentException(
3714 "Tried to get provisioning for MmTel capability '" + capability
3715 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003716 }
3717 }
3718
3719 } finally {
3720 Binder.restoreCallingIdentity(identity);
3721 }
3722 }
3723
3724 @Override
3725 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3726 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3727 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3728 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3729 }
3730 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3731 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3732 return (provisionedBits & capability) > 0;
3733 }
3734
3735 @Override
3736 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3737 boolean isProvisioned) {
3738 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3739 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3740 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3741 }
3742 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3743 "setProvisioningStatusForCapability");
3744 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3745 // If the current provisioning status for capability already matches isProvisioned,
3746 // do nothing.
3747 if (((provisionedBits & capability) > 0) == isProvisioned) {
3748 return;
3749 }
3750 if (isProvisioned) {
3751 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3752 } else {
3753 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3754 }
3755 }
3756
3757 /**
3758 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3759 * technology. The bitfield should mirror the bitfield defined by
3760 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3761 */
3762 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3763 String key = getMmTelProvisioningKey(subId, tech);
3764 // Default is no capabilities are provisioned.
3765 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3766 }
3767
3768 /**
3769 * Sets the MmTel capability provisioning bitfield (defined by
3770 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3771 * technology specified.
3772 *
3773 * Note: This is a synchronous command and should not be called on UI thread.
3774 */
3775 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3776 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3777 String key = getMmTelProvisioningKey(subId, tech);
3778 editor.putInt(key, newField);
3779 editor.commit();
3780 }
3781
3782 private static String getMmTelProvisioningKey(int subId, int tech) {
3783 // resulting key is provision_ims_mmtel_{subId}_{tech}
3784 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3785 }
3786
3787 /**
3788 * Query CarrierConfig to see if the specified capability requires provisioning for the
3789 * carrier associated with the subscription id.
3790 */
3791 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3792 int capability) {
3793 CarrierConfigManager configManager = new CarrierConfigManager(context);
3794 PersistableBundle c = configManager.getConfigForSubId(subId);
3795 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003796 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003797 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3798 false);
3799 boolean requireVoiceVtProvisioning = c.getBoolean(
3800 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3801
3802 // First check to make sure that the capability requires provisioning.
3803 switch (capability) {
3804 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3805 // intentional fallthrough
3806 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3807 if (requireVoiceVtProvisioning) {
3808 // Voice and Video requires provisioning
3809 return true;
3810 }
3811 break;
3812 }
3813 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3814 if (requireUtProvisioning) {
3815 // UT requires provisioning
3816 return true;
3817 }
3818 break;
3819 }
3820 }
3821 return false;
3822 }
3823
allenwtsu99c623b2020-01-03 18:24:23 +08003824 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
3825 int capability) {
3826 CarrierConfigManager configManager = new CarrierConfigManager(context);
3827 PersistableBundle c = configManager.getConfigForSubId(subId);
3828
3829 boolean requireRcsProvisioning = c.getBoolean(
3830 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
3831
3832 // First check to make sure that the capability requires provisioning.
3833 switch (capability) {
3834 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3835 // intentional fallthrough
3836 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
3837 if (requireRcsProvisioning) {
3838 // OPTION or PRESENCE requires provisioning
3839 return true;
3840 }
3841 break;
3842 }
3843 }
3844 return false;
3845 }
3846
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003847 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003848 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003849 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3850 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3851 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003852 enforceReadPrivilegedPermission("getImsProvisioningInt");
3853 final long identity = Binder.clearCallingIdentity();
3854 try {
3855 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003856 int slotId = getSlotIndex(subId);
3857 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3858 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3859 + subId + "' for key:" + key);
3860 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3861 }
3862 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003863 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003864 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3865 + subId + "' for key:" + key);
3866 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003867 } finally {
3868 Binder.restoreCallingIdentity(identity);
3869 }
3870 }
3871
3872 @Override
3873 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003874 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3875 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3876 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003877 enforceReadPrivilegedPermission("getImsProvisioningString");
3878 final long identity = Binder.clearCallingIdentity();
3879 try {
3880 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003881 int slotId = getSlotIndex(subId);
3882 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3883 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3884 + subId + "' for key:" + key);
3885 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3886 }
3887 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003888 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003889 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3890 + subId + "' for key:" + key);
3891 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003892 } finally {
3893 Binder.restoreCallingIdentity(identity);
3894 }
3895 }
3896
3897 @Override
3898 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003899 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3900 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3901 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003902 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3903 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003904 final long identity = Binder.clearCallingIdentity();
3905 try {
3906 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003907 int slotId = getSlotIndex(subId);
3908 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3909 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3910 + subId + "' for key:" + key);
3911 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3912 }
3913 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003914 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003915 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3916 + "' for key:" + key);
3917 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003918 } finally {
3919 Binder.restoreCallingIdentity(identity);
3920 }
3921 }
3922
3923 @Override
3924 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003925 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3926 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3927 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003928 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3929 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003930 final long identity = Binder.clearCallingIdentity();
3931 try {
3932 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003933 int slotId = getSlotIndex(subId);
3934 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3935 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3936 + subId + "' for key:" + key);
3937 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3938 }
3939 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003940 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003941 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3942 + "' for key:" + key);
3943 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003944 } finally {
3945 Binder.restoreCallingIdentity(identity);
3946 }
3947 }
3948
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003949 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003950 int slotId = SubscriptionManager.getSlotIndex(subId);
3951 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003952 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3953 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003954 }
3955 return slotId;
3956 }
3957
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003958 private int getSlotIndex(int subId) {
3959 int slotId = SubscriptionManager.getSlotIndex(subId);
3960 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3961 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3962 }
3963 return slotId;
3964 }
3965
Wink Saville36469e72014-06-11 15:17:00 -07003966 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003967 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003968 */
3969 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003970 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3971 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003972 final int targetSdk = getTargetSdk(callingPackage);
3973 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003974 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003975 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003976 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003977 mApp, subId, callingPackage, callingFeatureId,
3978 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003979 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3980 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003981
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003982 final long identity = Binder.clearCallingIdentity();
3983 try {
3984 final Phone phone = getPhone(subId);
3985 if (phone != null) {
3986 return phone.getServiceState().getDataNetworkType();
3987 } else {
3988 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3989 }
3990 } finally {
3991 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003992 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003993 }
3994
3995 /**
3996 * Returns the data network type
3997 */
3998 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003999 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4000 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4001 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004002 }
4003
4004 /**
4005 * Returns the data network type for a subId
4006 */
4007 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004008 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4009 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004010 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004011 mApp, subId, callingPackage, callingFeatureId,
4012 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004013 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4014 }
4015
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004016 final long identity = Binder.clearCallingIdentity();
4017 try {
4018 final Phone phone = getPhone(subId);
4019 if (phone != null) {
4020 return phone.getServiceState().getDataNetworkType();
4021 } else {
4022 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4023 }
4024 } finally {
4025 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004026 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004027 }
4028
4029 /**
Wink Saville36469e72014-06-11 15:17:00 -07004030 * Returns the Voice network type for a subId
4031 */
4032 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004033 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4034 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004035 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004036 mApp, subId, callingPackage, callingFeatureId,
4037 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004038 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4039 }
4040
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004041 final long identity = Binder.clearCallingIdentity();
4042 try {
4043 final Phone phone = getPhone(subId);
4044 if (phone != null) {
4045 return phone.getServiceState().getVoiceNetworkType();
4046 } else {
4047 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4048 }
4049 } finally {
4050 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004051 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004052 }
4053
4054 /**
4055 * @return true if a ICC card is present
4056 */
4057 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004058 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004059 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4060 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004061 }
4062
4063 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004064 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004065 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004066 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004067 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004068 final long identity = Binder.clearCallingIdentity();
4069 try {
4070 final Phone phone = PhoneFactory.getPhone(slotIndex);
4071 if (phone != null) {
4072 return phone.getIccCard().hasIccCard();
4073 } else {
4074 return false;
4075 }
4076 } finally {
4077 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004078 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004079 }
4080
4081 /**
4082 * Return if the current radio is LTE on CDMA. This
4083 * is a tri-state return value as for a period of time
4084 * the mode may be unknown.
4085 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004086 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004087 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004088 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004089 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004090 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004091 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4092 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4093 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004094 }
4095
Sanket Padawe356d7632015-06-22 14:03:32 -07004096 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004097 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4098 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004099 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004100 mApp, subId, callingPackage, callingFeatureId,
4101 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004102 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4103 }
4104
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004105 final long identity = Binder.clearCallingIdentity();
4106 try {
4107 final Phone phone = getPhone(subId);
4108 if (phone == null) {
4109 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4110 } else {
4111 return phone.getLteOnCdmaMode();
4112 }
4113 } finally {
4114 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004115 }
Wink Saville36469e72014-06-11 15:17:00 -07004116 }
4117
Wink Saville36469e72014-06-11 15:17:00 -07004118 /**
4119 * {@hide}
4120 * Returns Default subId, 0 in the case of single standby.
4121 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004122 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004123 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004124 }
4125
Shishir Agrawala9f32182016-04-12 12:00:16 -07004126 private int getSlotForDefaultSubscription() {
4127 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4128 }
4129
Wink Savilleb564aae2014-10-23 10:18:09 -07004130 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004131 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004132 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004133
Pengquan Menge92a50d2018-09-21 15:54:48 -07004134 private boolean isActiveSubscription(int subId) {
4135 return mSubscriptionController.isActiveSubId(subId);
4136 }
4137
Ihab Awadf2177b72013-11-25 13:33:23 -08004138 /**
4139 * @see android.telephony.TelephonyManager.WifiCallingChoices
4140 */
4141 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004142 final long identity = Binder.clearCallingIdentity();
4143 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004144 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004145 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4146 getWhenToMakeWifiCallsDefaultPreference());
4147 } finally {
4148 Binder.restoreCallingIdentity(identity);
4149 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004150 }
4151
4152 /**
4153 * @see android.telephony.TelephonyManager.WifiCallingChoices
4154 */
4155 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004156 final long identity = Binder.clearCallingIdentity();
4157 try {
4158 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004159 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004160 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4161 } finally {
4162 Binder.restoreCallingIdentity(identity);
4163 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004164 }
4165
Sailesh Nepald1e68152013-12-12 19:08:02 -08004166 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004167 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004168 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004169 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004170
Jordan Liu4c733742019-02-28 12:03:40 -08004171 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4172 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4173 if (phoneId == -1) {
4174 throw new IllegalArgumentException("Given slot index: " + slotIndex
4175 + " does not correspond to an active phone");
4176 }
4177 return PhoneFactory.getPhone(phoneId);
4178 }
4179
Shishir Agrawal566b7612013-10-28 14:41:00 -07004180 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004181 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4182 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004183 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4184 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004185 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004186 if (DBG) {
4187 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4188 }
4189 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4190 p2);
4191 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004192
Jordan Liu4c733742019-02-28 12:03:40 -08004193
4194 @Override
4195 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4196 int slotIndex, String callingPackage, String aid, int p2) {
4197 enforceModifyPermission();
4198 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4199 if (DBG) {
4200 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4201 }
4202 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4203 callingPackage, aid, p2);
4204 }
4205
4206 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4207 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004208 final long identity = Binder.clearCallingIdentity();
4209 try {
4210 if (TextUtils.equals(ISDR_AID, aid)) {
4211 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004212 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4213 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004214 if (bestComponent == null
4215 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4216 loge("The calling package is not allowed to access ISD-R.");
4217 throw new SecurityException(
4218 "The calling package is not allowed to access ISD-R.");
4219 }
Derek Tan740e1672017-06-27 14:56:27 -07004220 }
Derek Tan740e1672017-06-27 14:56:27 -07004221
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004222 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004223 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4224 null /* workSource */);
4225 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004226 return response;
4227 } finally {
4228 Binder.restoreCallingIdentity(identity);
4229 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004230 }
4231
4232 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004233 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4235 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004236 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4237 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4238 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004239
Jordan Liu4c733742019-02-28 12:03:40 -08004240 @Override
4241 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4242 enforceModifyPermission();
4243 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4244 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4245 channel);
4246 }
4247
4248 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004249 final long identity = Binder.clearCallingIdentity();
4250 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004251 if (channel < 0) {
4252 return false;
4253 }
Jordan Liu4c733742019-02-28 12:03:40 -08004254 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4255 null /* workSource */);
4256 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004257 return success;
4258 } finally {
4259 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004260 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004261 }
4262
4263 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004264 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004265 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4267 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004268 if (DBG) {
4269 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4270 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4271 + p3 + " data=" + data);
4272 }
4273 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4274 command, p1, p2, p3, data);
4275 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004276
Jordan Liu4c733742019-02-28 12:03:40 -08004277 @Override
4278 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4279 int command, int p1, int p2, int p3, String data) {
4280 enforceModifyPermission();
4281 if (DBG) {
4282 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4283 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4284 + p3 + " data=" + data);
4285 }
4286 return iccTransmitApduLogicalChannelWithPermission(
4287 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4288 data);
4289 }
4290
4291 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4292 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004293 final long identity = Binder.clearCallingIdentity();
4294 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004295 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004296 return "";
4297 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004298
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004299 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004300 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4301 null /* workSource */);
4302 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004303
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004304 // Append the returned status code to the end of the response payload.
4305 String s = Integer.toHexString(
4306 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4307 if (response.payload != null) {
4308 s = IccUtils.bytesToHexString(response.payload) + s;
4309 }
4310 return s;
4311 } finally {
4312 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004313 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004314 }
Jake Hambye994d462014-02-03 13:10:13 -08004315
Evan Charltonc66da362014-05-16 14:06:40 -07004316 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004317 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4318 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004319 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4320 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004321 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004322 if (DBG) {
4323 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4324 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4325 }
4326 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4327 cla, command, p1, p2, p3, data);
4328 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004329
Jordan Liu4c733742019-02-28 12:03:40 -08004330 @Override
4331 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4332 int command, int p1, int p2, int p3, String data) {
4333 enforceModifyPermission();
4334 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4335 if (DBG) {
4336 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4337 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4338 + " data=" + data);
4339 }
4340
4341 return iccTransmitApduBasicChannelWithPermission(
4342 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4343 p2, p3, data);
4344 }
4345
4346 // open APDU basic channel assuming the caller has sufficient permissions
4347 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4348 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004349 final long identity = Binder.clearCallingIdentity();
4350 try {
4351 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4352 && TextUtils.equals(ISDR_AID, data)) {
4353 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004354 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4355 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004356 if (bestComponent == null
4357 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4358 loge("The calling package is not allowed to select ISD-R.");
4359 throw new SecurityException(
4360 "The calling package is not allowed to select ISD-R.");
4361 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004362 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004363
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004364 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004365 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4366 null /* workSource */);
4367 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004368
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004369 // Append the returned status code to the end of the response payload.
4370 String s = Integer.toHexString(
4371 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4372 if (response.payload != null) {
4373 s = IccUtils.bytesToHexString(response.payload) + s;
4374 }
4375 return s;
4376 } finally {
4377 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004378 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004379 }
4380
4381 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004382 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004383 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004384 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4385 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004386
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004387 final long identity = Binder.clearCallingIdentity();
4388 try {
4389 if (DBG) {
4390 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4391 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4392 }
4393
4394 IccIoResult response =
4395 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4396 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4397 subId);
4398
4399 if (DBG) {
4400 log("Exchange SIM_IO [R]" + response);
4401 }
4402
4403 byte[] result = null;
4404 int length = 2;
4405 if (response.payload != null) {
4406 length = 2 + response.payload.length;
4407 result = new byte[length];
4408 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4409 } else {
4410 result = new byte[length];
4411 }
4412
4413 result[length - 1] = (byte) response.sw2;
4414 result[length - 2] = (byte) response.sw1;
4415 return result;
4416 } finally {
4417 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004418 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004419 }
4420
Nathan Haroldb3014052017-01-25 15:57:32 -08004421 /**
4422 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4423 * on a particular subscription
4424 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004425 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4426 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004427 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004428 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004429 return null;
4430 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004431
4432 final long identity = Binder.clearCallingIdentity();
4433 try {
4434 if (appType != TelephonyManager.APPTYPE_USIM
4435 && appType != TelephonyManager.APPTYPE_SIM) {
4436 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4437 return null;
4438 }
4439 Object response = sendRequest(
4440 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4441 if (response instanceof String[]) {
4442 return (String[]) response;
4443 }
yincheng zhaod698b842019-09-06 17:06:54 -07004444 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004445 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004446 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004447 } finally {
4448 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004449 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004450 }
4451
yincheng zhaod698b842019-09-06 17:06:54 -07004452 /**
4453 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4454 * subscription.
4455 *
4456 * @param subId the id of the subscription.
4457 * @param appType the uicc app type, must be USIM or SIM.
4458 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4459 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004460 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004461 * @return number of fplmns that is successfully written to the SIM.
4462 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004463 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4464 String callingFeatureId) {
4465 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4466 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004467 if (DBG) logv("no permissions for setForbiddenplmns");
4468 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4469 }
4470 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4471 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4472 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4473 }
4474 if (fplmns == null) {
4475 throw new IllegalArgumentException("Fplmn List provided is null");
4476 }
4477 for (String fplmn : fplmns) {
4478 if (!CellIdentity.isValidPlmn(fplmn)) {
4479 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4480 }
4481 }
4482 final long identity = Binder.clearCallingIdentity();
4483 try {
4484 Object response = sendRequest(
4485 CMD_SET_FORBIDDEN_PLMNS,
4486 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4487 subId);
4488 return (int) response;
4489 } finally {
4490 Binder.restoreCallingIdentity(identity);
4491 }
4492 }
4493
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004494 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004495 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004496 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4497 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004498
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004499 final long identity = Binder.clearCallingIdentity();
4500 try {
4501 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4502 if (response.payload == null) {
4503 return "";
4504 }
Evan Charltonc66da362014-05-16 14:06:40 -07004505
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004506 // Append the returned status code to the end of the response payload.
4507 String s = Integer.toHexString(
4508 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4509 s = IccUtils.bytesToHexString(response.payload) + s;
4510 return s;
4511 } finally {
4512 Binder.restoreCallingIdentity(identity);
4513 }
Evan Charltonc66da362014-05-16 14:06:40 -07004514 }
4515
Jake Hambye994d462014-02-03 13:10:13 -08004516 /**
4517 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4518 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4519 *
4520 * @param itemID the ID of the item to read
4521 * @return the NV item as a String, or null on error.
4522 */
4523 @Override
4524 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004525 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4527 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004528
4529 final long identity = Binder.clearCallingIdentity();
4530 try {
4531 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004532 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004533 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4534 return value;
4535 } finally {
4536 Binder.restoreCallingIdentity(identity);
4537 }
Jake Hambye994d462014-02-03 13:10:13 -08004538 }
4539
4540 /**
4541 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4542 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4543 *
4544 * @param itemID the ID of the item to read
4545 * @param itemValue the value to write, as a String
4546 * @return true on success; false on any failure
4547 */
4548 @Override
4549 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004550 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004551 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4552 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004553
4554 final long identity = Binder.clearCallingIdentity();
4555 try {
4556 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4557 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004558 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004559 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4560 return success;
4561 } finally {
4562 Binder.restoreCallingIdentity(identity);
4563 }
Jake Hambye994d462014-02-03 13:10:13 -08004564 }
4565
4566 /**
4567 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4568 * Used for device configuration by some CDMA operators.
4569 *
4570 * @param preferredRoamingList byte array containing the new PRL
4571 * @return true on success; false on any failure
4572 */
4573 @Override
4574 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4576 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004577
4578 final long identity = Binder.clearCallingIdentity();
4579 try {
4580 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4581 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4582 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4583 return success;
4584 } finally {
4585 Binder.restoreCallingIdentity(identity);
4586 }
Jake Hambye994d462014-02-03 13:10:13 -08004587 }
4588
4589 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004590 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004591 * Used for device configuration by some CDMA operators.
4592 *
chen xu6dac5ab2018-10-26 17:39:23 -07004593 * @param slotIndex - device slot.
4594 *
Jake Hambye994d462014-02-03 13:10:13 -08004595 * @return true on success; false on any failure
4596 */
4597 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004598 public boolean resetModemConfig(int slotIndex) {
4599 Phone phone = PhoneFactory.getPhone(slotIndex);
4600 if (phone != null) {
4601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4602 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004603
chen xu6dac5ab2018-10-26 17:39:23 -07004604 final long identity = Binder.clearCallingIdentity();
4605 try {
4606 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4607 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4608 return success;
4609 } finally {
4610 Binder.restoreCallingIdentity(identity);
4611 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004612 }
chen xu6dac5ab2018-10-26 17:39:23 -07004613 return false;
4614 }
4615
4616 /**
4617 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4618 *
4619 * @param slotIndex - device slot.
4620 *
4621 * @return true on success; false on any failure
4622 */
4623 @Override
4624 public boolean rebootModem(int slotIndex) {
4625 Phone phone = PhoneFactory.getPhone(slotIndex);
4626 if (phone != null) {
4627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4628 mApp, phone.getSubId(), "rebootModem");
4629
4630 final long identity = Binder.clearCallingIdentity();
4631 try {
4632 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4633 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4634 return success;
4635 } finally {
4636 Binder.restoreCallingIdentity(identity);
4637 }
4638 }
4639 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004640 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004641
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004642 public String[] getPcscfAddress(String apnType, String callingPackage,
4643 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004644 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004645 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4646 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004647 return new String[0];
4648 }
4649
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004650 final long identity = Binder.clearCallingIdentity();
4651 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004652 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004653 } finally {
4654 Binder.restoreCallingIdentity(identity);
4655 }
Wink Saville36469e72014-06-11 15:17:00 -07004656 }
4657
Brad Ebinger51f743a2017-01-23 13:50:20 -08004658 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004659 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4660 * {@link #disableIms(int)}.
4661 * @param slotIndex device slot.
4662 */
4663 public void resetIms(int slotIndex) {
4664 enforceModifyPermission();
4665
4666 final long identity = Binder.clearCallingIdentity();
4667 try {
4668 if (mImsResolver == null) {
4669 // may happen if the does not support IMS.
4670 return;
4671 }
4672 mImsResolver.disableIms(slotIndex);
4673 mImsResolver.enableIms(slotIndex);
4674 } finally {
4675 Binder.restoreCallingIdentity(identity);
4676 }
4677 }
4678
4679 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004680 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4681 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004682 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004683 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004684 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004685
4686 final long identity = Binder.clearCallingIdentity();
4687 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004688 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004689 // may happen if the device does not support IMS.
4690 return;
4691 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004692 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004693 } finally {
4694 Binder.restoreCallingIdentity(identity);
4695 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004696 }
4697
4698 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004699 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4700 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004701 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004702 public void disableIms(int slotId) {
4703 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004704
4705 final long identity = Binder.clearCallingIdentity();
4706 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004707 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004708 // may happen if the device does not support IMS.
4709 return;
4710 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004711 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004712 } finally {
4713 Binder.restoreCallingIdentity(identity);
4714 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004715 }
4716
4717 /**
4718 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4719 * feature or {@link null} if the service is not available. If the feature is available, the
4720 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4721 */
4722 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004723 IImsServiceFeatureCallback callback) {
4724 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004725
4726 final long identity = Binder.clearCallingIdentity();
4727 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004728 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004729 // may happen if the device does not support IMS.
4730 return null;
4731 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004732 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004733 } finally {
4734 Binder.restoreCallingIdentity(identity);
4735 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004736 }
4737
4738 /**
4739 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4740 * feature during emergency calling or {@link null} if the service is not available. If the
4741 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4742 * listener for feature updates.
4743 */
4744 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4745 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004746
4747 final long identity = Binder.clearCallingIdentity();
4748 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004749 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004750 // may happen if the device does not support IMS.
4751 return null;
4752 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004753 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004754 } finally {
4755 Binder.restoreCallingIdentity(identity);
4756 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004757 }
4758
Brad Ebinger5f64b052017-12-14 14:26:15 -08004759 /**
4760 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004761 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004762 */
4763 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4764 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004765
4766 final long identity = Binder.clearCallingIdentity();
4767 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004768 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004769 // may happen if the device does not support IMS.
4770 return null;
4771 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004772 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004773 } finally {
4774 Binder.restoreCallingIdentity(identity);
4775 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004776 }
4777
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004778 /**
4779 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004780 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004781 */
4782 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4783 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004784
4785 final long identity = Binder.clearCallingIdentity();
4786 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004787 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004788 // may happen if the device does not support IMS.
4789 return null;
4790 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004791 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004792 } finally {
4793 Binder.restoreCallingIdentity(identity);
4794 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004795 }
4796
Brad Ebinger884c07b2018-02-15 16:17:40 -08004797 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004798 * Sets the ImsService Package Name that Telephony will bind to.
4799 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08004800 * @param slotIndex the slot ID that the ImsService should bind for.
4801 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004802 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004803 * @param featureTypes An integer array of feature types associated with a packageName.
4804 * @param packageName The name of the package that the current configuration will be replaced
4805 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004806 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004807 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004808 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4809 int[] featureTypes, String packageName) {
4810 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4811 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4813 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08004814 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004815
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004816 final long identity = Binder.clearCallingIdentity();
4817 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004818 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004819 // may happen if the device does not support IMS.
4820 return false;
4821 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004822 Map<Integer, String> featureConfig = new HashMap<>();
4823 for (int featureType : featureTypes) {
4824 featureConfig.put(featureType, packageName);
4825 }
4826 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4827 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004828 } finally {
4829 Binder.restoreCallingIdentity(identity);
4830 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004831 }
4832
4833 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08004834 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004835 *
4836 * @param slotId The slot that the ImsService is associated with.
4837 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4838 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004839 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004840 * @return the package name of the ImsService configuration.
4841 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004842 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4843 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004844 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08004845 TelephonyPermissions
4846 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4847 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4848 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004849
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004850 final long identity = Binder.clearCallingIdentity();
4851 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004852 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004853 // may happen if the device does not support IMS.
4854 return "";
4855 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004856 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004857 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4858 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004859 } finally {
4860 Binder.restoreCallingIdentity(identity);
4861 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004862 }
4863
Brad Ebinger77b832e2019-10-17 17:03:22 -07004864 /**
4865 * Get the MmTelFeature state associated with the requested subscription id.
4866 * @param subId The subscription that the MmTelFeature is associated with.
4867 * @param callback A callback with an integer containing the
4868 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4869 */
4870 @Override
4871 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4872 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4873 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4874 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4875 "IMS not available on device.");
4876 }
4877 final long token = Binder.clearCallingIdentity();
4878 try {
4879 int slotId = getSlotIndex(subId);
4880 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4881 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4882 + subId + "'");
4883 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4884 }
4885 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4886 try {
4887 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4888 } catch (RemoteException e) {
4889 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4890 + "Ignore");
4891 }
4892 });
4893 } finally {
4894 Binder.restoreCallingIdentity(token);
4895 }
4896 }
4897
Wink Saville36469e72014-06-11 15:17:00 -07004898 public void setImsRegistrationState(boolean registered) {
4899 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004900
4901 final long identity = Binder.clearCallingIdentity();
4902 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004903 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004904 } finally {
4905 Binder.restoreCallingIdentity(identity);
4906 }
Wink Saville36469e72014-06-11 15:17:00 -07004907 }
4908
4909 /**
Stuart Scott54788802015-03-30 13:18:01 -07004910 * Set the network selection mode to automatic.
4911 *
4912 */
4913 @Override
4914 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004915 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4916 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004917
4918 final long identity = Binder.clearCallingIdentity();
4919 try {
shilufc958392020-01-20 11:36:01 -08004920 if (!isActiveSubscription(subId)) {
4921 return;
4922 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004923 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4924 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4925 } finally {
4926 Binder.restoreCallingIdentity(identity);
4927 }
Stuart Scott54788802015-03-30 13:18:01 -07004928 }
4929
Pengquan Mengea84e042018-09-20 14:57:26 -07004930 /**
4931 * Ask the radio to connect to the input network and change selection mode to manual.
4932 *
4933 * @param subId the id of the subscription.
4934 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4935 * the operator to attach to.
4936 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4937 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4938 * normal network selection next time.
4939 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004940 */
4941 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004942 public boolean setNetworkSelectionModeManual(
4943 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004944 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4945 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004946
4947 if (!isActiveSubscription(subId)) {
4948 return false;
4949 }
4950
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004951 final long identity = Binder.clearCallingIdentity();
4952 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004953 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004954 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004955 if (DBG) {
4956 log("setNetworkSelectionModeManual: subId: " + subId
4957 + " operator: " + operatorInfo);
4958 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004959 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4960 } finally {
4961 Binder.restoreCallingIdentity(identity);
4962 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004963 }
4964
4965 /**
4966 * Scans for available networks.
4967 */
4968 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004969 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4970 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4972 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004973 LocationAccessPolicy.LocationPermissionResult locationResult =
4974 LocationAccessPolicy.checkLocationPermission(mApp,
4975 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4976 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004977 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004978 .setCallingPid(Binder.getCallingPid())
4979 .setCallingUid(Binder.getCallingUid())
4980 .setMethod("getCellNetworkScanResults")
4981 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4982 .build());
4983 switch (locationResult) {
4984 case DENIED_HARD:
4985 throw new SecurityException("Not allowed to access scan results -- location");
4986 case DENIED_SOFT:
4987 return null;
4988 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004989
Pengquan Menga1bb6272018-09-06 09:59:22 -07004990 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004991 try {
4992 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004993 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004994 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004995 } finally {
4996 Binder.restoreCallingIdentity(identity);
4997 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004998 }
4999
5000 /**
yinxub1bed742017-04-17 11:45:04 -07005001 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005002 *
yinxub1bed742017-04-17 11:45:04 -07005003 * @param subId id of the subscription
5004 * @param request contains the radio access networks with bands/channels to scan
5005 * @param messenger callback messenger for scan results or errors
5006 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005007 * @return the id of the requested scan which can be used to stop the scan.
5008 */
5009 @Override
5010 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005011 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5013 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005014 LocationAccessPolicy.LocationPermissionResult locationResult =
5015 LocationAccessPolicy.checkLocationPermission(mApp,
5016 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5017 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005018 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005019 .setCallingPid(Binder.getCallingPid())
5020 .setCallingUid(Binder.getCallingUid())
5021 .setMethod("requestNetworkScan")
5022 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5023 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005024 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005025 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005026 if (e != null) {
5027 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5028 throw e;
5029 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005030 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005031 return TelephonyScanManager.INVALID_SCAN_ID;
5032 }
5033 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005034 }
Hall Liu912dfd32019-04-25 14:02:26 -07005035 int callingUid = Binder.getCallingUid();
5036 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005037 final long identity = Binder.clearCallingIdentity();
5038 try {
5039 return mNetworkScanRequestTracker.startNetworkScan(
5040 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005041 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005042 } finally {
5043 Binder.restoreCallingIdentity(identity);
5044 }
yinxu504e1392017-04-12 16:03:22 -07005045 }
5046
Hall Liub2ac8ef2019-02-28 15:56:23 -08005047 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005048 NetworkScanRequest request, int subId) {
5049 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5050 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5051 boolean hasNetworkScanPermission =
5052 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5053 == PERMISSION_GRANTED;
5054
5055 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5056 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5057 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005058 }
5059
5060 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5061 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005062 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5063 return new SecurityException("Specific channels must not be"
5064 + " scanned without location access.");
5065 }
5066 }
5067 }
5068
Hall Liub2ac8ef2019-02-28 15:56:23 -08005069 return null;
5070 }
5071
yinxu504e1392017-04-12 16:03:22 -07005072 /**
5073 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005074 *
5075 * @param subId id of the subscription
5076 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005077 */
5078 @Override
5079 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5081 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005082
Hall Liu912dfd32019-04-25 14:02:26 -07005083 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005084 final long identity = Binder.clearCallingIdentity();
5085 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005086 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005087 } finally {
5088 Binder.restoreCallingIdentity(identity);
5089 }
yinxu504e1392017-04-12 16:03:22 -07005090 }
5091
5092 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005093 * Get the calculated preferred network type.
5094 * Used for debugging incorrect network type.
5095 *
5096 * @return the preferred network type, defined in RILConstants.java.
5097 */
5098 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005099 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005100 final Phone defaultPhone = getDefaultPhone();
5101 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005102 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005103 return RILConstants.PREFERRED_NETWORK_MODE;
5104 }
5105
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005106 final long identity = Binder.clearCallingIdentity();
5107 try {
5108 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005109 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005110 } finally {
5111 Binder.restoreCallingIdentity(identity);
5112 }
Junda Liu84d15a22014-07-02 11:21:04 -07005113 }
5114
5115 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005116 * Get the preferred network type.
5117 * Used for device configuration by some CDMA operators.
5118 *
5119 * @return the preferred network type, defined in RILConstants.java.
5120 */
5121 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005122 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005123 TelephonyPermissions
5124 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5125 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005126
5127 final long identity = Binder.clearCallingIdentity();
5128 try {
5129 if (DBG) log("getPreferredNetworkType");
5130 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5131 int networkType = (result != null ? result[0] : -1);
5132 if (DBG) log("getPreferredNetworkType: " + networkType);
5133 return networkType;
5134 } finally {
5135 Binder.restoreCallingIdentity(identity);
5136 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005137 }
5138
5139 /**
5140 * Set the preferred network type.
5141 * Used for device configuration by some CDMA operators.
5142 *
5143 * @param networkType the preferred network type, defined in RILConstants.java.
5144 * @return true on success; false on any failure.
5145 */
5146 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005147 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005148 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5149 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005150
5151 final long identity = Binder.clearCallingIdentity();
5152 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005153 Settings.Global.putInt(mApp.getContentResolver(),
5154 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5155 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005156 } finally {
5157 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005158 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005159 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005160
5161 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005162 * Get the allowed network types that store in the telephony provider.
5163 *
5164 * @param subId the id of the subscription.
5165 * @return allowedNetworkTypes the allowed network types.
5166 */
5167 @Override
5168 public long getAllowedNetworkTypes(int subId) {
5169 TelephonyPermissions
5170 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5171 mApp, subId, "getAllowedNetworkTypes");
5172
5173 final long identity = Binder.clearCallingIdentity();
5174 try {
5175 return SubscriptionManager.getLongSubscriptionProperty(
5176 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5177 } finally {
5178 Binder.restoreCallingIdentity(identity);
5179 }
5180 }
5181
5182 /**
5183 * Set the allowed network types.
5184 *
5185 * @param subId the id of the subscription.
5186 * @param allowedNetworkTypes the allowed network types.
5187 * @return true on success; false on any failure.
5188 */
5189 @Override
5190 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5191 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5192 mApp, subId, "setAllowedNetworkTypes");
5193 final long identity = Binder.clearCallingIdentity();
5194 try {
5195 SubscriptionManager.setSubscriptionProperty(subId,
5196 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5197 String.valueOf(allowedNetworkTypes));
5198 return setPreferredNetworkTypesInternal(subId);
5199 } finally {
5200 Binder.restoreCallingIdentity(identity);
5201 }
5202 }
5203
5204 private boolean setPreferredNetworkTypesInternal(int subId) {
5205 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5206 Settings.Global.getInt(mApp.getContentResolver(),
5207 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5208 RILConstants.PREFERRED_NETWORK_MODE));
5209 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5210 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5211 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5212 (int) (networkTypeBitMask & allowedNetworkTypes));
5213
5214 if (DBG) {
5215 log("setPreferredNetworkTypesInternal: subId " + subId
5216 + " networkTypes " + networkTypeBitMask
5217 + " allowedNetworkTypes " + allowedNetworkTypes
5218 + " networkMode " + networkMode);
5219 }
5220
5221 Boolean success = (Boolean) sendRequest(
5222 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5223 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5224 return success;
5225 }
5226
5227 /**
Miaoa84611c2019-03-15 09:21:10 +08005228 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005229 *
Miaoa84611c2019-03-15 09:21:10 +08005230 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005231 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005232 * @hide
5233 */
5234 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005235 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005236 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005237 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005238 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005239 try {
Miaoa84611c2019-03-15 09:21:10 +08005240 if (phone != null) {
5241 return phone.hasMatchedTetherApnSetting();
5242 } else {
5243 return false;
5244 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005245 } finally {
5246 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005247 }
Junda Liu475951f2014-11-07 16:45:03 -08005248 }
5249
5250 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005251 * Set mobile data enabled
5252 * Used by the user through settings etc to turn on/off mobile data
5253 *
5254 * @param enable {@code true} turn turn data on, else {@code false}
5255 */
5256 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005257 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5259 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005260
5261 final long identity = Binder.clearCallingIdentity();
5262 try {
5263 int phoneId = mSubscriptionController.getPhoneId(subId);
5264 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5265 Phone phone = PhoneFactory.getPhone(phoneId);
5266 if (phone != null) {
5267 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005268 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005269 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005270 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005271 }
5272 } finally {
5273 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005274 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005275 }
5276
5277 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005278 * Get the user enabled state of Mobile Data.
5279 *
5280 * TODO: remove and use isUserDataEnabled.
5281 * This can't be removed now because some vendor codes
5282 * calls through ITelephony directly while they should
5283 * use TelephonyManager.
5284 *
5285 * @return true on enabled
5286 */
5287 @Override
5288 public boolean getDataEnabled(int subId) {
5289 return isUserDataEnabled(subId);
5290 }
5291
5292 /**
5293 * Get whether mobile data is enabled per user setting.
5294 *
5295 * There are other factors deciding whether mobile data is actually enabled, but they are
5296 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005297 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005298 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005299 *
5300 * @return {@code true} if data is enabled else {@code false}
5301 */
5302 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005303 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005304 try {
5305 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5306 null);
5307 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5309 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005310 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005311
5312 final long identity = Binder.clearCallingIdentity();
5313 try {
5314 int phoneId = mSubscriptionController.getPhoneId(subId);
5315 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5316 Phone phone = PhoneFactory.getPhone(phoneId);
5317 if (phone != null) {
5318 boolean retVal = phone.isUserDataEnabled();
5319 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5320 return retVal;
5321 } else {
5322 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5323 return false;
5324 }
5325 } finally {
5326 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005327 }
5328 }
5329
5330 /**
5331 * Get whether mobile data is enabled.
5332 *
5333 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5334 * whether mobile data is actually enabled.
5335 *
5336 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5337 *
5338 * @return {@code true} if data is enabled else {@code false}
5339 */
5340 @Override
5341 public boolean isDataEnabled(int subId) {
5342 try {
5343 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5344 null);
5345 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5347 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005348 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005349
5350 final long identity = Binder.clearCallingIdentity();
5351 try {
5352 int phoneId = mSubscriptionController.getPhoneId(subId);
5353 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5354 Phone phone = PhoneFactory.getPhone(phoneId);
5355 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005356 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005357 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5358 return retVal;
5359 } else {
5360 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5361 return false;
5362 }
5363 } finally {
5364 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005365 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005366 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005367
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005368 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5369 Phone phone) {
5370 //load access rules from carrier configs, and check those as well: b/139133814
5371 SubscriptionController subController = SubscriptionController.getInstance();
5372 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5373 || subController == null) return privilegeFromSim;
5374
5375 int uid = Binder.getCallingUid();
5376 PackageManager pkgMgr = phone.getContext().getPackageManager();
5377 String[] packages = pkgMgr.getPackagesForUid(uid);
5378
5379 final long identity = Binder.clearCallingIdentity();
5380 try {
5381 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5382 SubscriptionManager subManager = (SubscriptionManager)
5383 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5384 for (String pkg : packages) {
5385 if (subManager.canManageSubscription(subInfo, pkg)) {
5386 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5387 }
5388 }
5389 return privilegeFromSim;
5390 } finally {
5391 Binder.restoreCallingIdentity(identity);
5392 }
5393 }
5394
5395 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5396 String pkgName) {
5397 //load access rules from carrier configs, and check those as well: b/139133814
5398 SubscriptionController subController = SubscriptionController.getInstance();
5399 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5400 || subController == null) return privilegeFromSim;
5401
5402 final long identity = Binder.clearCallingIdentity();
5403 try {
5404 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5405 SubscriptionManager subManager = (SubscriptionManager)
5406 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5407 return subManager.canManageSubscription(subInfo, pkgName)
5408 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5409 } finally {
5410 Binder.restoreCallingIdentity(identity);
5411 }
5412 }
5413
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005414 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005415 public int getCarrierPrivilegeStatus(int subId) {
5416 final Phone phone = getPhone(subId);
5417 if (phone == null) {
5418 loge("getCarrierPrivilegeStatus: Invalid subId");
5419 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5420 }
5421 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005422 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005423 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005424 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5425 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005426
5427 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5428 card.getCarrierPrivilegeStatusForCurrentTransaction(
5429 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005430 }
Junda Liu29340342014-07-10 15:23:27 -07005431
5432 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005433 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005434 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005435 final Phone phone = getPhone(subId);
5436 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005437 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005438 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5439 }
5440 UiccProfile profile =
5441 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5442 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005443 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005444 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5445 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005446 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005447 profile.getCarrierPrivilegeStatusForUid(
5448 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005449 }
5450
5451 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005452 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5453 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005454 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005455 }
5456
5457 int phoneId = SubscriptionManager.getPhoneId(subId);
5458 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005459 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005460 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005461 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5462 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005463 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5464 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5465 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005466 }
5467
5468 @Override
5469 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005470 if (TextUtils.isEmpty(pkgName))
5471 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005472 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5473 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5474 UiccCard card = UiccController.getInstance().getUiccCard(i);
5475 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005476 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005477 continue;
5478 }
5479
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005480 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5481 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5482 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005483 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5484 break;
5485 }
5486 }
5487
5488 return result;
Junda Liu29340342014-07-10 15:23:27 -07005489 }
Derek Tan89e89d42014-07-08 17:00:10 -07005490
5491 @Override
Junda Liue64de782015-04-16 17:19:16 -07005492 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5493 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5494 loge("phoneId " + phoneId + " is not valid.");
5495 return null;
5496 }
5497 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005498 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005499 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005500 return null ;
5501 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005502 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005503 }
5504
Amith Yamasani6e118872016-02-19 12:53:51 -08005505 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005506 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005507 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005508 List<String> privilegedPackages = new ArrayList<>();
5509 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005510 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5511 // has UICC in that slot.
5512 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005513 if (card.hasCarrierPrivilegeRules()) {
5514 if (packages == null) {
5515 // Only check packages in user 0 for now
5516 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005517 PackageManager.MATCH_DISABLED_COMPONENTS
5518 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005519 | PackageManager.GET_SIGNING_CERTIFICATES,
5520 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005521 }
5522 for (int p = packages.size() - 1; p >= 0; p--) {
5523 PackageInfo pkgInfo = packages.get(p);
5524 if (pkgInfo != null && pkgInfo.packageName != null
5525 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005526 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005527 privilegedPackages.add(pkgInfo.packageName);
5528 }
5529 }
5530 }
5531 }
5532 return privilegedPackages;
5533 }
5534
chen xuf7e9fe82019-05-09 19:31:02 -07005535 @Override
5536 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005537 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5538
5539 final long identity = Binder.clearCallingIdentity();
5540
chen xuf7e9fe82019-05-09 19:31:02 -07005541 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005542 try {
5543 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5544 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5545 }
5546 } finally {
5547 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005548 }
5549 return privilegedPackages;
5550 }
5551
Wink Savilleb564aae2014-10-23 10:18:09 -07005552 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005553 final Phone phone = getPhone(subId);
5554 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005555 if (card == null) {
5556 loge("getIccId: No UICC");
5557 return null;
5558 }
5559 String iccId = card.getIccId();
5560 if (TextUtils.isEmpty(iccId)) {
5561 loge("getIccId: ICC ID is null or empty.");
5562 return null;
5563 }
5564 return iccId;
5565 }
5566
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005567 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005568 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5569 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08005570 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005571 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005572
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005573 final long identity = Binder.clearCallingIdentity();
5574 try {
5575 final String iccId = getIccId(subId);
5576 final Phone phone = getPhone(subId);
5577 if (phone == null) {
5578 return false;
5579 }
5580 final String subscriberId = phone.getSubscriberId();
5581
5582 if (DBG_MERGE) {
5583 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5584 + subscriberId + " to " + number);
5585 }
5586
5587 if (TextUtils.isEmpty(iccId)) {
5588 return false;
5589 }
5590
5591 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5592
5593 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5594 if (alphaTag == null) {
5595 editor.remove(alphaTagPrefKey);
5596 } else {
5597 editor.putString(alphaTagPrefKey, alphaTag);
5598 }
5599
5600 // Record both the line number and IMSI for this ICCID, since we need to
5601 // track all merged IMSIs based on line number
5602 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5603 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5604 if (number == null) {
5605 editor.remove(numberPrefKey);
5606 editor.remove(subscriberPrefKey);
5607 } else {
5608 editor.putString(numberPrefKey, number);
5609 editor.putString(subscriberPrefKey, subscriberId);
5610 }
5611
5612 editor.commit();
5613 return true;
5614 } finally {
5615 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005616 }
Derek Tan7226c842014-07-02 17:42:23 -07005617 }
5618
5619 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005620 public String getLine1NumberForDisplay(int subId, String callingPackage,
5621 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005622 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005623 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005624 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005625 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005626 return null;
5627 }
Derek Tan97ebb422014-09-05 16:55:38 -07005628
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005629 final long identity = Binder.clearCallingIdentity();
5630 try {
5631 String iccId = getIccId(subId);
5632 if (iccId != null) {
5633 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5634 if (DBG_MERGE) {
5635 log("getLine1NumberForDisplay returning "
5636 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5637 }
5638 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005639 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005640 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5641 return null;
5642 } finally {
5643 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005644 }
Derek Tan7226c842014-07-02 17:42:23 -07005645 }
5646
5647 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005648 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5649 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005650 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005651 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005652 return null;
5653 }
Derek Tan97ebb422014-09-05 16:55:38 -07005654
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005655 final long identity = Binder.clearCallingIdentity();
5656 try {
5657 String iccId = getIccId(subId);
5658 if (iccId != null) {
5659 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5660 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5661 }
5662 return null;
5663 } finally {
5664 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005665 }
Derek Tan7226c842014-07-02 17:42:23 -07005666 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005667
5668 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005669 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5670 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005671 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5672 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005673 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005674 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005675 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005676 return null;
5677 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005678
Jordan Liub49b04b2019-05-06 14:45:15 -07005679 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5680 // the process, where TelephonyManager was instantiated.
5681 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005682 final long identity = Binder.clearCallingIdentity();
5683 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005684 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005685 final TelephonyManager tele = TelephonyManager.from(context);
5686 final SubscriptionManager sub = SubscriptionManager.from(context);
5687
5688 // Figure out what subscribers are currently active
5689 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005690
Jordan Liub49b04b2019-05-06 14:45:15 -07005691 // Only consider subs which match the current subId
5692 // This logic can be simplified. See b/131189269 for progress.
5693 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005694 activeSubscriberIds.add(tele.getSubscriberId(subId));
5695 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005696
5697 // First pass, find a number override for an active subscriber
5698 String mergeNumber = null;
5699 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5700 for (String key : prefs.keySet()) {
5701 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5702 final String subscriberId = (String) prefs.get(key);
5703 if (activeSubscriberIds.contains(subscriberId)) {
5704 final String iccId = key.substring(
5705 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5706 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5707 mergeNumber = (String) prefs.get(numberKey);
5708 if (DBG_MERGE) {
5709 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5710 + " for active subscriber " + subscriberId);
5711 }
5712 if (!TextUtils.isEmpty(mergeNumber)) {
5713 break;
5714 }
5715 }
5716 }
5717 }
5718
5719 // Shortcut when no active merged subscribers
5720 if (TextUtils.isEmpty(mergeNumber)) {
5721 return null;
5722 }
5723
5724 // Second pass, find all subscribers under that line override
5725 final ArraySet<String> result = new ArraySet<>();
5726 for (String key : prefs.keySet()) {
5727 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5728 final String number = (String) prefs.get(key);
5729 if (mergeNumber.equals(number)) {
5730 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5731 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5732 final String subscriberId = (String) prefs.get(subscriberKey);
5733 if (!TextUtils.isEmpty(subscriberId)) {
5734 result.add(subscriberId);
5735 }
5736 }
5737 }
5738 }
5739
5740 final String[] resultArray = result.toArray(new String[result.size()]);
5741 Arrays.sort(resultArray);
5742 if (DBG_MERGE) {
5743 Slog.d(LOG_TAG,
5744 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5745 }
5746 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005747 } finally {
5748 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005749 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005750 }
5751
5752 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005753 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5754 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5755
5756 final long identity = Binder.clearCallingIdentity();
5757 try {
5758 final TelephonyManager telephonyManager = mApp.getSystemService(
5759 TelephonyManager.class);
5760 String subscriberId = telephonyManager.getSubscriberId(subId);
5761 if (subscriberId == null) {
5762 if (DBG) {
5763 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5764 + subId);
5765 }
5766 return null;
5767 }
5768
5769 final SubscriptionInfo info = SubscriptionController.getInstance()
5770 .getSubscriptionInfo(subId);
5771 final ParcelUuid groupUuid = info.getGroupUuid();
5772 // If it doesn't belong to any group, return just subscriberId of itself.
5773 if (groupUuid == null) {
5774 return new String[]{subscriberId};
5775 }
5776
5777 // Get all subscriberIds from the group.
5778 final List<String> mergedSubscriberIds = new ArrayList<>();
5779 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005780 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5781 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07005782 for (SubscriptionInfo subInfo : groupInfos) {
5783 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5784 if (subscriberId != null) {
5785 mergedSubscriberIds.add(subscriberId);
5786 }
5787 }
5788
5789 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5790 } finally {
5791 Binder.restoreCallingIdentity(identity);
5792
5793 }
5794 }
5795
5796 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005797 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08005798 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005799 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005800
5801 final long identity = Binder.clearCallingIdentity();
5802 try {
5803 final Phone phone = getPhone(subId);
5804 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5805 } finally {
5806 Binder.restoreCallingIdentity(identity);
5807 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005808 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005809
5810 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005811 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005812 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5813 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08005814 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5815 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005816
5817 final long identity = Binder.clearCallingIdentity();
5818 try {
5819 final Phone phone = getPhone(subId);
5820 if (phone == null) {
5821 return false;
5822 }
5823 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5824 cdmaNonRoamingList);
5825 } finally {
5826 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005827 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005828 }
5829
5830 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005831 @Deprecated
5832 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5833 enforceModifyPermission();
5834
5835 int returnValue = 0;
5836 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005837 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005838 if(result.exception == null) {
5839 if (result.result != null) {
5840 byte[] responseData = (byte[])(result.result);
5841 if(responseData.length > oemResp.length) {
5842 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5843 responseData.length + "bytes. Buffer Size is " +
5844 oemResp.length + "bytes.");
5845 }
5846 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5847 returnValue = responseData.length;
5848 }
5849 } else {
5850 CommandException ex = (CommandException) result.exception;
5851 returnValue = ex.getCommandError().ordinal();
5852 if(returnValue > 0) returnValue *= -1;
5853 }
5854 } catch (RuntimeException e) {
5855 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5856 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5857 if(returnValue > 0) returnValue *= -1;
5858 }
5859
5860 return returnValue;
5861 }
5862
5863 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005864 public void setRadioCapability(RadioAccessFamily[] rafs) {
5865 try {
5866 ProxyController.getInstance().setRadioCapability(rafs);
5867 } catch (RuntimeException e) {
5868 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5869 }
5870 }
5871
5872 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005873 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005874 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005875 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005876 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005877 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005878 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005879 final long identity = Binder.clearCallingIdentity();
5880 try {
chen xub97461a2018-10-26 14:17:57 -07005881 TelephonyPermissions
5882 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5883 mApp, phone.getSubId(), "getRadioAccessFamily");
5884 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005885 } finally {
5886 Binder.restoreCallingIdentity(identity);
5887 }
chen xub97461a2018-10-26 14:17:57 -07005888 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005889 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005890
5891 @Override
5892 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005893 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005894 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005895
5896 final long identity = Binder.clearCallingIdentity();
5897 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005898 ImsManager.getInstance(defaultPhone.getContext(),
5899 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005900 } finally {
5901 Binder.restoreCallingIdentity(identity);
5902 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005903 }
5904
5905 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005906 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005907 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005908 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5909 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005910 return false;
5911 }
Svet Ganovb320e182015-04-16 12:30:10 -07005912
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005913 final long identity = Binder.clearCallingIdentity();
5914 try {
5915 // Check the user preference and the system-level IMS setting. Even if the user has
5916 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5917 // In the long run, we may instead need to check if there exists a connection service
5918 // which can support video calling.
5919 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005920 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005921 return imsManager.isVtEnabledByPlatform()
5922 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5923 && imsManager.isVtEnabledByUser();
5924 } finally {
5925 Binder.restoreCallingIdentity(identity);
5926 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005927 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005928
Andrew Leea1239f22015-03-02 17:44:07 -08005929 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005930 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5931 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005932 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005933 mApp, subId, callingPackage, callingFeatureId,
5934 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005935 return false;
5936 }
5937
5938 final long identity = Binder.clearCallingIdentity();
5939 try {
5940 CarrierConfigManager configManager =
5941 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005942 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005943 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5944 } finally {
5945 Binder.restoreCallingIdentity(identity);
5946 }
Andrew Leea1239f22015-03-02 17:44:07 -08005947 }
5948
5949 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005950 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005951 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005952 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005953 return false;
5954 }
5955
5956 final long identity = Binder.clearCallingIdentity();
5957 try {
5958 CarrierConfigManager configManager =
5959 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005960 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005961 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5962 } finally {
5963 Binder.restoreCallingIdentity(identity);
5964 }
Andrew Leea1239f22015-03-02 17:44:07 -08005965 }
5966
Andrew Lee9431b832015-03-09 18:46:45 -07005967 @Override
5968 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07005969 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005970 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005971 }
5972
5973 @Override
5974 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005975 final long identity = Binder.clearCallingIdentity();
5976 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005977 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005978 } finally {
5979 Binder.restoreCallingIdentity(identity);
5980 }
Andrew Lee9431b832015-03-09 18:46:45 -07005981 }
5982
Hall Liuf6668912018-10-31 17:05:23 -07005983 /**
5984 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5985 * support for the feature and device firmware support.
5986 *
5987 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5988 */
5989 @Override
5990 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005991 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005992 final Phone phone = getPhone(subscriptionId);
5993 if (phone == null) {
5994 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5995 return false;
5996 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005997 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005998 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005999 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6000 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006001 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006002 return isCarrierSupported && isDeviceSupported;
6003 } finally {
6004 Binder.restoreCallingIdentity(identity);
6005 }
Hall Liu98187582018-01-22 19:15:32 -08006006 }
6007
Hall Liuf6668912018-10-31 17:05:23 -07006008 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006009 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6010 * RTT setting, will return true if the device and carrier both support RTT.
6011 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006012 */
6013 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006014 final long identity = Binder.clearCallingIdentity();
6015 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006016 boolean isRttSupported = isRttSupported(subscriptionId);
6017 boolean isUserRttSettingOn = Settings.Secure.getInt(
6018 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6019 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6020 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6021 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006022 } finally {
6023 Binder.restoreCallingIdentity(identity);
6024 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006025 }
6026
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006027 @Deprecated
6028 @Override
6029 public String getDeviceId(String callingPackage) {
6030 return getDeviceIdWithFeature(callingPackage, null);
6031 }
6032
Sanket Padawe7310cc72015-01-14 09:53:20 -08006033 /**
6034 * Returns the unique device ID of phone, for example, the IMEI for
6035 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6036 *
6037 * <p>Requires Permission:
6038 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6039 */
6040 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006041 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006042 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006043 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006044 return null;
6045 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006046 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006047 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006048 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006049 return null;
6050 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006051
6052 final long identity = Binder.clearCallingIdentity();
6053 try {
6054 return phone.getDeviceId();
6055 } finally {
6056 Binder.restoreCallingIdentity(identity);
6057 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006058 }
6059
Ping Sunc67b7c22016-03-02 19:16:45 +08006060 /**
6061 * {@hide}
6062 * Returns the IMS Registration Status on a particular subid
6063 *
6064 * @param subId
6065 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006066 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006067 Phone phone = getPhone(subId);
6068 if (phone != null) {
6069 return phone.isImsRegistered();
6070 } else {
6071 return false;
6072 }
6073 }
6074
Santos Cordon7a1885b2015-02-03 11:15:19 -08006075 @Override
6076 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006077 final long identity = Binder.clearCallingIdentity();
6078 try {
6079 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6080 } finally {
6081 Binder.restoreCallingIdentity(identity);
6082 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006083 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006084
Tyler Gunnf70ed162019-04-03 15:28:53 -07006085 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006086 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006087 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006088 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006089 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006090 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6091 }
6092 final long identity = Binder.clearCallingIdentity();
6093 try {
6094 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6095 } finally {
6096 Binder.restoreCallingIdentity(identity);
6097 }
6098 }
6099
6100 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006101 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6102 final long identity = Binder.clearCallingIdentity();
6103 try {
6104 Phone phone = getPhone(subscriptionId);
6105 if (phone == null) {
6106 return null;
6107 }
6108 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6109 } finally {
6110 Binder.restoreCallingIdentity(identity);
6111 }
6112 }
6113
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006114 /**
6115 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006116 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006117 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006118 final long identity = Binder.clearCallingIdentity();
6119 try {
6120 Phone phone = getPhone(subId);
6121 if (phone != null) {
6122 return phone.isWifiCallingEnabled();
6123 } else {
6124 return false;
6125 }
6126 } finally {
6127 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006128 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006129 }
6130
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006131 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006132 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006133 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006134 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135 final long identity = Binder.clearCallingIdentity();
6136 try {
6137 Phone phone = getPhone(subId);
6138 if (phone != null) {
6139 return phone.isVideoEnabled();
6140 } else {
6141 return false;
6142 }
6143 } finally {
6144 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006145 }
6146 }
6147
6148 /**
6149 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6150 * defined in {@link ImsRegistrationImplBase}.
6151 */
6152 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006153 final long identity = Binder.clearCallingIdentity();
6154 try {
6155 Phone phone = getPhone(subId);
6156 if (phone != null) {
6157 return phone.getImsRegistrationTech();
6158 } else {
6159 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6160 }
6161 } finally {
6162 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006163 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006164 }
6165
Stuart Scott8eef64f2015-04-08 15:13:54 -07006166 @Override
6167 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006168 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006169 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6170 return;
6171 }
6172
Svet Ganovcc087f82015-05-12 20:35:54 -07006173 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006174
Svet Ganovcc087f82015-05-12 20:35:54 -07006175 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006176 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6177 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006178 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006179 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006180 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006181 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6182 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006183 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006184 // There has been issues when Sms raw table somehow stores orphan
6185 // fragments. They lead to garbled message when new fragments come
6186 // in and combined with those stale ones. In case this happens again,
6187 // user can reset all network settings which will clean up this table.
6188 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006189 // Clean up IMS settings as well here.
6190 int slotId = getSlotIndex(subId);
6191 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6192 ImsManager.getInstance(mApp, slotId).factoryReset();
6193 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006194
6195 // Erase modem config if erase modem on network setting is enabled.
6196 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6197 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6198 if (configValue != null && Boolean.parseBoolean(configValue)) {
6199 sendEraseModemConfig(getDefaultPhone());
6200 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006201 } finally {
6202 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006203 }
6204 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006205
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006206 private void cleanUpSmsRawTable(Context context) {
6207 ContentResolver resolver = context.getContentResolver();
6208 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6209 resolver.delete(uri, null, null);
6210 }
6211
Narayan Kamath1c496c22015-04-16 14:40:19 +01006212 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006213 public String getSimLocaleForSubscriber(int subId) {
6214 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6215 final Phone phone = getPhone(subId);
6216 if (phone == null) {
6217 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006218 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006219 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006220 final long identity = Binder.clearCallingIdentity();
6221 try {
chen xu5d3637b2019-01-21 23:31:38 -08006222 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006223 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08006224 if (info == null) {
6225 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6226 return null;
6227 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006228 // Try and fetch the locale from the carrier properties or from the SIM language
6229 // preferences (EF-PL and EF-LI)...
6230 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006231 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006232 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6233 if (localeFromDefaultSim != null) {
6234 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6235 if (DBG) log("Using locale from subId: " + subId + " locale: "
6236 + localeFromDefaultSim);
6237 return localeFromDefaultSim.toLanguageTag();
6238 } else {
6239 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006240 }
6241 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006242
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006243 // The SIM language preferences only store a language (e.g. fr = French), not an
6244 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6245 // the SIM and carrier preferences does not include a country we add the country
6246 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006247 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006248 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006249 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006250 return mccLocale.toLanguageTag();
6251 }
6252
6253 if (DBG) log("No locale found - returning null");
6254 return null;
6255 } finally {
6256 Binder.restoreCallingIdentity(identity);
6257 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006258 }
6259
6260 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006261 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6262 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006263 }
6264
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006265 /**
6266 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6267 */
6268 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006269 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6270 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006271 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006272
Chenjie Yu1ba97252018-01-11 18:16:20 -08006273 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006274 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006275
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006276 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006277 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6278 * representing the state of the modem.
6279 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006280 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6281 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006282 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006283 */
6284 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006285 public void requestModemActivityInfo(ResultReceiver result) {
6286 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006287 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006288
6289 final long identity = Binder.clearCallingIdentity();
6290 try {
6291 ModemActivityInfo ret = null;
6292 synchronized (mLastModemActivityInfo) {
6293 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6294 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006295 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006296 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006297 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xu13851032019-09-10 18:49:52 -07006298 int[] txTimeMs = info.getTransmitTimeMillis();
6299 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006300 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xu13851032019-09-10 18:49:52 -07006301 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006302 }
6303 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006304 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6305 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006306 mLastModemActivityInfo.setIdleTimeMillis(
6307 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xu13851032019-09-10 18:49:52 -07006308 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6309 mLastModemActivityInfo.setReceiveTimeMillis(
6310 info.getReceiveTimeMillis() + mLastModemActivityInfo
6311 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006312 }
Chen Xu13851032019-09-10 18:49:52 -07006313
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006314 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6315 mLastModemActivityInfo.getSleepTimeMillis(),
6316 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xu13851032019-09-10 18:49:52 -07006317 mLastModemActivityInfo.getTransmitTimeMillis(),
6318 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006319 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006320 Bundle bundle = new Bundle();
6321 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6322 result.send(0, bundle);
6323 } finally {
6324 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006325 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006326 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006327
Siddharth Rayb8114062018-06-17 15:02:38 -07006328 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6329 // less than total activity duration.
6330 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6331 if (info == null) {
6332 return false;
6333 }
6334 int activityDurationMs =
6335 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6336 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006337 int[] txTimeMs = info.getTransmitTimeMillis();
6338 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6339 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006340 }
6341 return (info.isValid()
6342 && (info.getSleepTimeMillis() <= activityDurationMs)
6343 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006344 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006345 && (totalTxTimeMs <= activityDurationMs));
6346 }
6347
Jack Yu85bd38a2015-11-09 11:34:32 -08006348 /**
6349 * {@hide}
6350 * Returns the service state information on specified subscription.
6351 */
6352 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006353 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6354 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006355 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006356 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006357 return null;
6358 }
6359
Hall Liuf19c44f2018-11-27 14:38:17 -08006360 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6361 LocationAccessPolicy.checkLocationPermission(mApp,
6362 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6363 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006364 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006365 .setCallingPid(Binder.getCallingPid())
6366 .setCallingUid(Binder.getCallingUid())
6367 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006368 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006369 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6370 .build());
6371
6372 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6373 LocationAccessPolicy.checkLocationPermission(mApp,
6374 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6375 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006376 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006377 .setCallingPid(Binder.getCallingPid())
6378 .setCallingUid(Binder.getCallingUid())
6379 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006380 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006381 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6382 .build());
6383 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6384 boolean hasFinePermission =
6385 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6386 boolean hasCoarsePermission =
6387 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6388
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006389 final long identity = Binder.clearCallingIdentity();
6390 try {
6391 final Phone phone = getPhone(subId);
6392 if (phone == null) {
6393 return null;
6394 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006395
Hall Liuf19c44f2018-11-27 14:38:17 -08006396 ServiceState ss = phone.getServiceState();
6397
6398 // Scrub out the location info in ServiceState depending on what level of access
6399 // the caller has.
6400 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006401 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6402 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006403 } finally {
6404 Binder.restoreCallingIdentity(identity);
6405 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006406 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006407
6408 /**
6409 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6410 *
6411 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6412 * voicemail ringtone.
6413 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6414 * PhoneAccount.
6415 */
6416 @Override
6417 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006418 final long identity = Binder.clearCallingIdentity();
6419 try {
6420 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6421 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006422 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006423 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006424
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006425 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6426 } finally {
6427 Binder.restoreCallingIdentity(identity);
6428 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006429 }
6430
6431 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006432 * Sets the per-account voicemail ringtone.
6433 *
6434 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6435 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6436 *
6437 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6438 * voicemail ringtone.
6439 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6440 * PhoneAccount.
6441 */
6442 @Override
6443 public void setVoicemailRingtoneUri(String callingPackage,
6444 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006445 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006446 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006447 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6448 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006449 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6450 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6451 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006452 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006453
6454 final long identity = Binder.clearCallingIdentity();
6455 try {
6456 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6457 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006458 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006459 }
6460 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6461 } finally {
6462 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006463 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006464 }
6465
6466 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006467 * Returns whether vibration is set for voicemail notification in Phone settings.
6468 *
6469 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6470 * voicemail vibration setting.
6471 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6472 */
6473 @Override
6474 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006475 final long identity = Binder.clearCallingIdentity();
6476 try {
6477 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6478 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006479 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006480 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006481
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006482 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6483 } finally {
6484 Binder.restoreCallingIdentity(identity);
6485 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006486 }
6487
Youhan Wange64578a2016-05-02 15:32:42 -07006488 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006489 * Sets the per-account voicemail vibration.
6490 *
6491 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6492 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6493 *
6494 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6495 * voicemail vibration setting.
6496 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6497 * specific PhoneAccount.
6498 */
6499 @Override
6500 public void setVoicemailVibrationEnabled(String callingPackage,
6501 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006502 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006503 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006504 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6505 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006506 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6507 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6508 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006509 }
6510
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006511 final long identity = Binder.clearCallingIdentity();
6512 try {
6513 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6514 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006515 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006516 }
6517 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6518 } finally {
6519 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006520 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006521 }
6522
6523 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006524 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6525 *
6526 * @throws SecurityException if the caller does not have the required permission
6527 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006528 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006529 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006530 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006531 }
6532
6533 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006534 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6535 * permission.
6536 *
6537 * @throws SecurityException if the caller does not have the required permission
6538 */
6539 private void enforceSendSmsPermission() {
6540 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6541 }
6542
6543 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006544 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006545 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006546 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006547 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006548 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006549 final long identity = Binder.clearCallingIdentity();
6550 try {
6551 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006552 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006553 if (componentName == null) {
6554 throw new SecurityException(
6555 "Caller not current active visual voicemail package[null]");
6556 }
6557 String vvmPackage = componentName.getPackageName();
6558 if (!callingPackage.equals(vvmPackage)) {
6559 throw new SecurityException("Caller not current active visual voicemail package["
6560 + vvmPackage + "]");
6561 }
6562 } finally {
6563 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006564 }
6565 }
6566
6567 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006568 * Return the application ID for the app type.
6569 *
6570 * @param subId the subscription ID that this request applies to.
6571 * @param appType the uicc app type.
6572 * @return Application ID for specificied app type, or null if no uicc.
6573 */
6574 @Override
6575 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006576 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006577 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006578
6579 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006580 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006581 if (phone == null) {
6582 return null;
6583 }
6584 String aid = null;
6585 try {
6586 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6587 .getApplicationByType(appType).getAid();
6588 } catch (Exception e) {
6589 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6590 }
6591 return aid;
6592 } finally {
6593 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006594 }
Youhan Wange64578a2016-05-02 15:32:42 -07006595 }
6596
Youhan Wang4001d252016-05-11 10:29:41 -07006597 /**
6598 * Return the Electronic Serial Number.
6599 *
6600 * @param subId the subscription ID that this request applies to.
6601 * @return ESN or null if error.
6602 */
6603 @Override
6604 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006605 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006606 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006607
6608 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006609 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006610 if (phone == null) {
6611 return null;
6612 }
6613 String esn = null;
6614 try {
6615 esn = phone.getEsn();
6616 } catch (Exception e) {
6617 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6618 }
6619 return esn;
6620 } finally {
6621 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006622 }
Youhan Wang4001d252016-05-11 10:29:41 -07006623 }
6624
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006625 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006626 * Return the Preferred Roaming List Version.
6627 *
6628 * @param subId the subscription ID that this request applies to.
6629 * @return PRLVersion or null if error.
6630 */
6631 @Override
6632 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006633 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006634 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006635
6636 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006637 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006638 if (phone == null) {
6639 return null;
6640 }
6641 String cdmaPrlVersion = null;
6642 try {
6643 cdmaPrlVersion = phone.getCdmaPrlVersion();
6644 } catch (Exception e) {
6645 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6646 }
6647 return cdmaPrlVersion;
6648 } finally {
6649 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006650 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006651 }
6652
6653 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006654 * Get snapshot of Telephony histograms
6655 * @return List of Telephony histograms
6656 * @hide
6657 */
6658 @Override
6659 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6661 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006662
6663 final long identity = Binder.clearCallingIdentity();
6664 try {
6665 return RIL.getTelephonyRILTimingHistograms();
6666 } finally {
6667 Binder.restoreCallingIdentity(identity);
6668 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006669 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006670
6671 /**
6672 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006673 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6674 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006675 * Require system privileges. In the future we may add this to carrier APIs.
6676 *
Michele Berionne482f8202018-11-27 18:57:59 -08006677 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006678 */
6679 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006680 @TelephonyManager.SetCarrierRestrictionResult
6681 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006682 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006683 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006684
Michele Berionne482f8202018-11-27 18:57:59 -08006685 if (carrierRestrictionRules == null) {
6686 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006687 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006688
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006689 final long identity = Binder.clearCallingIdentity();
6690 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006691 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006692 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006693 } finally {
6694 Binder.restoreCallingIdentity(identity);
6695 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006696 }
6697
6698 /**
6699 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006700 * Get the allowed carrier list and the excluded carrier list, including the priority between
6701 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006702 * Require system privileges. In the future we may add this to carrier APIs.
6703 *
Michele Berionne482f8202018-11-27 18:57:59 -08006704 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006705 */
6706 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006707 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006708 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006709 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006710
6711 final long identity = Binder.clearCallingIdentity();
6712 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006713 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6714 if (response instanceof CarrierRestrictionRules) {
6715 return (CarrierRestrictionRules) response;
6716 }
6717 // Response is an Exception of some kind,
6718 // which is signalled to the user as a NULL retval
6719 return null;
6720 } catch (Exception e) {
6721 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6722 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006723 } finally {
6724 Binder.restoreCallingIdentity(identity);
6725 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006726 }
6727
fionaxu59545b42016-05-25 15:53:37 -07006728 /**
6729 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6730 * @param subId the subscription ID that this action applies to.
6731 * @param enabled control enable or disable metered apns.
6732 * {@hide}
6733 */
6734 @Override
6735 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6736 enforceModifyPermission();
6737 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006738
6739 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006740 if (phone == null) {
6741 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6742 return;
6743 }
6744 try {
6745 phone.carrierActionSetMeteredApnsEnabled(enabled);
6746 } catch (Exception e) {
6747 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006748 } finally {
6749 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006750 }
6751 }
6752
6753 /**
6754 * Action set from carrier signalling broadcast receivers to enable/disable radio
6755 * @param subId the subscription ID that this action applies to.
6756 * @param enabled control enable or disable radio.
6757 * {@hide}
6758 */
6759 @Override
6760 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6761 enforceModifyPermission();
6762 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006763
6764 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006765 if (phone == null) {
6766 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6767 return;
6768 }
6769 try {
6770 phone.carrierActionSetRadioEnabled(enabled);
6771 } catch (Exception e) {
6772 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006773 } finally {
6774 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006775 }
6776 }
6777
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006778 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006779 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6780 * network status based on which carrier apps could apply actions accordingly,
6781 * enable/disable default url handler for example.
6782 *
6783 * @param subId the subscription ID that this action applies to.
6784 * @param report control start/stop reporting the default network status.
6785 * {@hide}
6786 */
6787 @Override
6788 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6789 enforceModifyPermission();
6790 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006791
6792 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006793 if (phone == null) {
6794 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6795 return;
6796 }
6797 try {
6798 phone.carrierActionReportDefaultNetworkStatus(report);
6799 } catch (Exception e) {
6800 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006801 } finally {
6802 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006803 }
6804 }
6805
6806 /**
fionaxud9622282017-07-17 17:51:30 -07006807 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6808 * @param subId the subscription ID that this action applies to.
6809 * {@hide}
6810 */
6811 @Override
6812 public void carrierActionResetAll(int subId) {
6813 enforceModifyPermission();
6814 final Phone phone = getPhone(subId);
6815 if (phone == null) {
6816 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6817 return;
6818 }
6819 try {
6820 phone.carrierActionResetAll();
6821 } catch (Exception e) {
6822 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6823 }
6824 }
6825
6826 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006827 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6828 * bug report is being generated.
6829 */
6830 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006831 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006832 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6833 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006834 writer.println("Permission Denial: can't dump Phone from pid="
6835 + Binder.getCallingPid()
6836 + ", uid=" + Binder.getCallingUid()
6837 + "without permission "
6838 + android.Manifest.permission.DUMP);
6839 return;
6840 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006841 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006842 }
Jack Yueb89b242016-06-22 13:27:47 -07006843
Brad Ebingerdac2f002018-04-03 15:17:52 -07006844 @Override
6845 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6846 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6847 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006848 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6849 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006850 }
6851
Jack Yueb89b242016-06-22 13:27:47 -07006852 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006853 * Get aggregated video call data usage since boot.
6854 *
6855 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6856 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006857 * {@hide}
6858 */
6859 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006860 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006861 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6862 null);
6863
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006864 final long identity = Binder.clearCallingIdentity();
6865 try {
6866 // NetworkStatsService keeps tracking the active network interface and identity. It
6867 // records the delta with the corresponding network identity.
6868 // We just return the total video call data usage snapshot since boot.
6869 Phone phone = getPhone(subId);
6870 if (phone != null) {
6871 return phone.getVtDataUsage(perUidStats);
6872 }
6873 return null;
6874 } finally {
6875 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006876 }
Jack Yueb89b242016-06-22 13:27:47 -07006877 }
Jack Yu75ab2952016-07-08 14:29:33 -07006878
6879 /**
6880 * Policy control of data connection. Usually used when data limit is passed.
6881 * @param enabled True if enabling the data, otherwise disabling.
6882 * @param subId Subscription index
6883 * {@hide}
6884 */
6885 @Override
6886 public void setPolicyDataEnabled(boolean enabled, int subId) {
6887 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006888
6889 final long identity = Binder.clearCallingIdentity();
6890 try {
6891 Phone phone = getPhone(subId);
6892 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006893 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006894 }
6895 } finally {
6896 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006897 }
6898 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006899
6900 /**
6901 * Get Client request stats
6902 * @return List of Client Request Stats
6903 * @hide
6904 */
6905 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006906 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6907 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006908 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006909 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006910 return null;
6911 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006912 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006913
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006914 final long identity = Binder.clearCallingIdentity();
6915 try {
6916 if (phone != null) {
6917 return phone.getClientRequestStats();
6918 }
6919
6920 return null;
6921 } finally {
6922 Binder.restoreCallingIdentity(identity);
6923 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006924 }
6925
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006926 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006927 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006928 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006929 }
Jack Yueb4124c2017-02-16 15:32:43 -08006930
6931 /**
Grace Chen70990072017-03-24 17:21:30 -07006932 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006933 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006934 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006935 * @param state State of SIM (power down, power up, pass through)
6936 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6937 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6938 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006939 *
6940 **/
6941 @Override
Grace Chen70990072017-03-24 17:21:30 -07006942 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006943 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006944 Phone phone = PhoneFactory.getPhone(slotIndex);
6945
vagdeviaf9a5b92018-08-15 16:01:53 -07006946 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6947
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006948 final long identity = Binder.clearCallingIdentity();
6949 try {
6950 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006951 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006952 }
6953 } finally {
6954 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006955 }
6956 }
Shuo Qiandd210312017-04-12 22:11:33 +00006957
Tyler Gunn65d45c22017-06-05 11:22:26 -07006958 private boolean isUssdApiAllowed(int subId) {
6959 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006960 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006961 if (configManager == null) {
6962 return false;
6963 }
6964 PersistableBundle pb = configManager.getConfigForSubId(subId);
6965 if (pb == null) {
6966 return false;
6967 }
6968 return pb.getBoolean(
6969 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6970 }
6971
Shuo Qiandd210312017-04-12 22:11:33 +00006972 /**
6973 * Check if phone is in emergency callback mode
6974 * @return true if phone is in emergency callback mode
6975 * @param subId sub id
6976 */
goneil9c5f4872017-12-05 14:07:56 -08006977 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006978 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006979 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006980 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006981
6982 final long identity = Binder.clearCallingIdentity();
6983 try {
6984 if (phone != null) {
6985 return phone.isInEcm();
6986 } else {
6987 return false;
6988 }
6989 } finally {
6990 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006991 }
6992 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006993
6994 /**
6995 * Get the current signal strength information for the given subscription.
6996 * Because this information is not updated when the device is in a low power state
6997 * it should not be relied-upon to be current.
6998 * @param subId Subscription index
6999 * @return the most recent cached signal strength info from the modem
7000 */
7001 @Override
7002 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007003 final long identity = Binder.clearCallingIdentity();
7004 try {
7005 Phone p = getPhone(subId);
7006 if (p == null) {
7007 return null;
7008 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007009
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007010 return p.getSignalStrength();
7011 } finally {
7012 Binder.restoreCallingIdentity(identity);
7013 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007014 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007015
Pengquan Meng77b7f132018-08-22 14:49:57 -07007016 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007017 * Get the current modem radio state for the given slot.
7018 * @param slotIndex slot index.
7019 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007020 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007021 * @return the current radio power state from the modem
7022 */
7023 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007024 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007025 Phone phone = PhoneFactory.getPhone(slotIndex);
7026 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007027 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7028 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007029 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7030 }
7031
7032 final long identity = Binder.clearCallingIdentity();
7033 try {
7034 return phone.getRadioPowerState();
7035 } finally {
7036 Binder.restoreCallingIdentity(identity);
7037 }
7038 }
7039 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7040 }
7041
7042 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007043 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7044 *
7045 * <p>Requires one of the following permissions:
7046 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7047 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7048 * privileges.
7049 *
7050 * @param subId subscription id
7051 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7052 * {@code false}.
7053 */
7054 @Override
7055 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007056 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7057 null /* message */);
7058
Pengquan Menga1bb6272018-09-06 09:59:22 -07007059 boolean isEnabled = false;
7060 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007061 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007062 Phone phone = getPhone(subId);
7063 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007064 } catch (Exception e) {
7065 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7066 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007067 } finally {
7068 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007069 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007070 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007071 }
7072
7073
7074 /**
7075 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7076 *
7077 * <p> Requires permission:
7078 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7079 * privileges.
7080 *
7081 * @param subId subscription id
7082 * @param isEnabled {@code true} means enable, {@code false} means disable.
7083 */
7084 @Override
7085 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7087 mApp, subId, "setDataRoamingEnabled");
7088
Pengquan Menga1bb6272018-09-06 09:59:22 -07007089 final long identity = Binder.clearCallingIdentity();
7090 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007091 Phone phone = getPhone(subId);
7092 if (phone != null) {
7093 phone.setDataRoamingEnabled(isEnabled);
7094 }
7095 } finally {
7096 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007097 }
7098 }
7099
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007100 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007101 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007102 TelephonyPermissions
7103 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007104 mApp, subId, "isManualNetworkSelectionAllowed");
7105
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007106 boolean isAllowed = true;
7107 final long identity = Binder.clearCallingIdentity();
7108 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007109 Phone phone = getPhone(subId);
7110 if (phone != null) {
7111 isAllowed = phone.isCspPlmnEnabled();
7112 }
7113 } finally {
7114 Binder.restoreCallingIdentity(identity);
7115 }
7116 return isAllowed;
7117 }
7118
7119 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007120 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007121 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007122 try {
7123 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007124 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007125 } catch (SecurityException e) {
7126 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7127 // has carrier privileges on an active UICC
7128 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7129 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007130 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007131 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007132 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007133
7134 final long identity = Binder.clearCallingIdentity();
7135 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007136 UiccController uiccController = UiccController.getInstance();
7137 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007138 if (hasReadPermission) {
7139 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007140 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007141
7142 // Remove private info if the caller doesn't have access
7143 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7144 for (UiccCardInfo cardInfo : cardInfos) {
7145 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7146 // is available
7147 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7148 if (card == null || card.getUiccProfile() == null) {
7149 // assume no access if the card or profile is unavailable
7150 filteredInfos.add(cardInfo.getUnprivileged());
7151 continue;
7152 }
7153 UiccProfile profile = card.getUiccProfile();
7154 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7155 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7156 filteredInfos.add(cardInfo);
7157 } else {
7158 filteredInfos.add(cardInfo.getUnprivileged());
7159 }
7160 }
7161 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007162 } finally {
7163 Binder.restoreCallingIdentity(identity);
7164 }
7165 }
7166
7167 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007168 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007169 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007170
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007171 final long identity = Binder.clearCallingIdentity();
7172 try {
7173 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7174 if (slots == null) {
7175 Rlog.i(LOG_TAG, "slots is null.");
7176 return null;
7177 }
7178
7179 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7180 for (int i = 0; i < slots.length; i++) {
7181 UiccSlot slot = slots[i];
7182 if (slot == null) {
7183 continue;
7184 }
7185
Jordan Liu7be7e652019-05-06 18:55:02 +00007186 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007187 UiccCard card = slot.getUiccCard();
7188 if (card != null) {
7189 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007190 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007191 cardId = slot.getEid();
7192 if (TextUtils.isEmpty(cardId)) {
7193 cardId = slot.getIccId();
7194 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007195 }
7196
Jordan Liu857451f2019-05-09 16:35:35 -07007197 if (cardId != null) {
7198 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7199 // if cardId is an EID, it's all digits so this is fine
7200 cardId = IccUtils.stripTrailingFs(cardId);
7201 }
7202
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007203 int cardState = 0;
7204 switch (slot.getCardState()) {
7205 case CARDSTATE_ABSENT:
7206 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7207 break;
7208 case CARDSTATE_PRESENT:
7209 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7210 break;
7211 case CARDSTATE_ERROR:
7212 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7213 break;
7214 case CARDSTATE_RESTRICTED:
7215 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7216 break;
7217 default:
7218 break;
7219
7220 }
7221
7222 infos[i] = new UiccSlotInfo(
7223 slot.isActive(),
7224 slot.isEuicc(),
7225 cardId,
7226 cardState,
7227 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007228 slot.isExtendedApduSupported(),
7229 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007230 }
7231 return infos;
7232 } finally {
7233 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007234 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007235 }
7236
7237 @Override
7238 public boolean switchSlots(int[] physicalSlots) {
7239 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007240
7241 final long identity = Binder.clearCallingIdentity();
7242 try {
7243 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7244 } finally {
7245 Binder.restoreCallingIdentity(identity);
7246 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007247 }
Jack Yu4c988042018-02-27 15:30:01 -08007248
7249 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007250 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007251 final long identity = Binder.clearCallingIdentity();
7252 try {
7253 return UiccController.getInstance().getCardIdForDefaultEuicc();
7254 } finally {
7255 Binder.restoreCallingIdentity(identity);
7256 }
7257 }
7258
7259 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007260 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7261 enforceModifyPermission();
7262 final Phone phone = getPhone(subId);
7263 if (phone == null) {
7264 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7265 return;
7266 }
7267
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007268 final long identity = Binder.clearCallingIdentity();
7269 try {
7270 phone.setRadioIndicationUpdateMode(filters, mode);
7271 } finally {
7272 Binder.restoreCallingIdentity(identity);
7273 }
Jack Yu4c988042018-02-27 15:30:01 -08007274 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007275
7276 /**
goneil47ffb6e2018-04-06 15:40:58 -07007277 * A test API to reload the UICC profile.
7278 *
7279 * <p>Requires that the calling app has permission
7280 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7281 * @hide
7282 */
7283 @Override
7284 public void refreshUiccProfile(int subId) {
7285 enforceModifyPermission();
7286
7287 final long identity = Binder.clearCallingIdentity();
7288 try {
7289 Phone phone = getPhone(subId);
7290 if (phone == null) {
7291 return;
7292 }
7293 UiccCard uiccCard = phone.getUiccCard();
7294 if (uiccCard == null) {
7295 return;
7296 }
7297 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7298 if (uiccProfile == null) {
7299 return;
7300 }
7301 uiccProfile.refresh();
7302 } finally {
7303 Binder.restoreCallingIdentity(identity);
7304 }
7305 }
7306
7307 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007308 * Returns false if the mobile data is disabled by default, otherwise return true.
7309 */
7310 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007311 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007312 }
7313
7314 /**
7315 * Returns true if the data roaming is enabled by default, i.e the system property
7316 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7317 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7318 */
7319 private boolean getDefaultDataRoamingEnabled(int subId) {
7320 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007321 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007322 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007323 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7324 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7325 return isDataRoamingEnabled;
7326 }
7327
7328 /**
7329 * Returns the default network type for the given {@code subId}, if the default network type is
7330 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7331 */
7332 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007333 List<Integer> list = TelephonyProperties.default_network();
7334 int phoneId = mSubscriptionController.getPhoneId(subId);
7335 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7336 return list.get(phoneId);
7337 }
7338 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007339 }
fionaxua13278b2018-03-21 00:08:13 -07007340
7341 @Override
7342 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007343 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007344 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007345
7346 final long identity = Binder.clearCallingIdentity();
7347 try {
7348 final Phone phone = getPhone(subId);
7349 if (phone == null) {
7350 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7351 return;
7352 }
chen xueaba88a2019-03-15 13:15:10 -07007353 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7354 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007355 } finally {
7356 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007357 }
fionaxua13278b2018-03-21 00:08:13 -07007358 }
7359
7360 @Override
7361 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007362 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007363
7364 final long identity = Binder.clearCallingIdentity();
7365 try {
7366 final Phone phone = getPhone(subId);
7367 if (phone == null) {
7368 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7369 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7370 }
7371 return phone.getCarrierIdListVersion();
7372 } finally {
7373 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007374 }
fionaxua13278b2018-03-21 00:08:13 -07007375 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007376
7377 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007378 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7379 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007380 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007381 mApp, subId, callingPackage, callingFeatureId,
7382 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007383 return -1;
7384 }
7385
7386 final long identity = Binder.clearCallingIdentity();
7387 try {
7388 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7389 } finally {
7390 Binder.restoreCallingIdentity(identity);
7391 }
7392 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007393
7394 @Override
7395 public int getCdmaRoamingMode(int subId) {
7396 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7397 mApp, subId, "getCdmaRoamingMode");
7398
7399 final long identity = Binder.clearCallingIdentity();
7400 try {
7401 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7402 } finally {
7403 Binder.restoreCallingIdentity(identity);
7404 }
7405 }
7406
7407 @Override
7408 public boolean setCdmaRoamingMode(int subId, int mode) {
7409 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7410 mApp, subId, "setCdmaRoamingMode");
7411
7412 final long identity = Binder.clearCallingIdentity();
7413 try {
7414 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7415 } finally {
7416 Binder.restoreCallingIdentity(identity);
7417 }
7418 }
7419
7420 @Override
7421 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7422 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7423 mApp, subId, "setCdmaSubscriptionMode");
7424
7425 final long identity = Binder.clearCallingIdentity();
7426 try {
7427 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7428 } finally {
7429 Binder.restoreCallingIdentity(identity);
7430 }
7431 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007432
sqianc5eccab2018-10-19 18:46:41 -07007433 @Override
sqian8c685422019-02-22 15:55:18 -08007434 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007435 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007436 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007437 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7438 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007439 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7440 }
7441 final long identity = Binder.clearCallingIdentity();
7442 try {
sqian854d44b2018-12-12 16:48:18 -08007443 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7444 for (Phone phone: PhoneFactory.getPhones()) {
7445 if (phone.getEmergencyNumberTracker() != null
7446 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7447 emergencyNumberListInternal.put(
7448 phone.getSubId(),
7449 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7450 }
sqian11b7a0e2018-12-05 18:48:28 -08007451 }
sqian854d44b2018-12-12 16:48:18 -08007452 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007453 } finally {
7454 Binder.restoreCallingIdentity(identity);
7455 }
sqianc5eccab2018-10-19 18:46:41 -07007456 }
7457
7458 @Override
sqian8c685422019-02-22 15:55:18 -08007459 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007460 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007461 if (!exactMatch) {
7462 TelephonyPermissions
7463 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007464 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007465 }
7466 final long identity = Binder.clearCallingIdentity();
7467 try {
sqian854d44b2018-12-12 16:48:18 -08007468 for (Phone phone: PhoneFactory.getPhones()) {
7469 if (phone.getEmergencyNumberTracker() != null
7470 && phone.getEmergencyNumberTracker() != null) {
7471 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7472 number, exactMatch)) {
7473 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007474 }
7475 }
sqian11b7a0e2018-12-05 18:48:28 -08007476 }
7477 return false;
7478 } finally {
7479 Binder.restoreCallingIdentity(identity);
7480 }
7481 }
7482
sqianf4ca7ed2019-01-15 18:32:07 -08007483 /**
7484 * Update emergency number list for test mode.
7485 */
7486 @Override
7487 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7488 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7489 "updateEmergencyNumberListTestMode");
7490
7491 final long identity = Binder.clearCallingIdentity();
7492 try {
7493 for (Phone phone: PhoneFactory.getPhones()) {
7494 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7495 if (tracker != null) {
7496 tracker.executeEmergencyNumberTestModeCommand(action, num);
7497 }
7498 }
7499 } finally {
7500 Binder.restoreCallingIdentity(identity);
7501 }
7502 }
7503
7504 /**
7505 * Get the full emergency number list for test mode.
7506 */
7507 @Override
7508 public List<String> getEmergencyNumberListTestMode() {
7509 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7510 "getEmergencyNumberListTestMode");
7511
7512 final long identity = Binder.clearCallingIdentity();
7513 try {
7514 Set<String> emergencyNumbers = new HashSet<>();
7515 for (Phone phone: PhoneFactory.getPhones()) {
7516 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7517 if (tracker != null) {
7518 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7519 emergencyNumbers.add(num.getNumber());
7520 }
7521 }
7522 }
7523 return new ArrayList<>(emergencyNumbers);
7524 } finally {
7525 Binder.restoreCallingIdentity(identity);
7526 }
7527 }
7528
chen xud6b45bd2018-10-30 22:27:10 -07007529 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007530 public int getEmergencyNumberDbVersion(int subId) {
7531 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7532
7533 final long identity = Binder.clearCallingIdentity();
7534 try {
7535 final Phone phone = getPhone(subId);
7536 if (phone == null) {
7537 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7538 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7539 }
7540 return phone.getEmergencyNumberDbVersion();
7541 } finally {
7542 Binder.restoreCallingIdentity(identity);
7543 }
7544 }
7545
7546 @Override
7547 public void notifyOtaEmergencyNumberDbInstalled() {
7548 enforceModifyPermission();
7549
7550 final long identity = Binder.clearCallingIdentity();
7551 try {
7552 for (Phone phone: PhoneFactory.getPhones()) {
7553 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7554 if (tracker != null) {
7555 tracker.updateOtaEmergencyNumberDatabase();
7556 }
7557 }
7558 } finally {
7559 Binder.restoreCallingIdentity(identity);
7560 }
7561 }
7562
7563 @Override
7564 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7565 enforceActiveEmergencySessionPermission();
7566
7567 final long identity = Binder.clearCallingIdentity();
7568 try {
7569 for (Phone phone: PhoneFactory.getPhones()) {
7570 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7571 if (tracker != null) {
7572 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7573 }
7574 }
7575 } finally {
7576 Binder.restoreCallingIdentity(identity);
7577 }
7578 }
7579
7580 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007581 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7582 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7583 Phone phone = getPhone(subId);
7584 if (phone == null) {
7585 return null;
7586 }
7587 final long identity = Binder.clearCallingIdentity();
7588 try {
7589 UiccProfile profile = UiccController.getInstance()
7590 .getUiccProfileForPhone(phone.getPhoneId());
7591 if (profile != null) {
7592 return profile.getCertsFromCarrierPrivilegeAccessRules();
7593 }
7594 } finally {
7595 Binder.restoreCallingIdentity(identity);
7596 }
7597 return null;
7598 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007599
7600 /**
7601 * Enable or disable a modem stack.
7602 */
7603 @Override
7604 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7605 enforceModifyPermission();
7606
7607 final long identity = Binder.clearCallingIdentity();
7608 try {
7609 Phone phone = PhoneFactory.getPhone(slotIndex);
7610 if (phone == null) {
7611 return false;
7612 } else {
7613 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7614 }
7615 } finally {
7616 Binder.restoreCallingIdentity(identity);
7617 }
7618 }
Michelecea4cf22018-12-21 15:00:11 -08007619
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007620 /**
7621 * Whether a modem stack is enabled or not.
7622 */
7623 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007624 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7625 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007626 Phone phone = PhoneFactory.getPhone(slotIndex);
7627 if (phone == null) return false;
7628
7629 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007630 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7631 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007632 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7633 }
7634
7635 final long identity = Binder.clearCallingIdentity();
7636 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007637 try {
7638 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7639 } catch (NoSuchElementException ex) {
7640 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7641 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007642 } finally {
7643 Binder.restoreCallingIdentity(identity);
7644 }
7645 }
7646
Michelecea4cf22018-12-21 15:00:11 -08007647 @Override
Michele0ea7d782019-03-19 14:58:42 -07007648 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007649 enforceModifyPermission();
7650
7651 final long identity = Binder.clearCallingIdentity();
7652 try {
7653 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007654 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007655 .commit();
7656 } finally {
7657 Binder.restoreCallingIdentity(identity);
7658 }
7659 }
7660
7661 @Override
Michele0ea7d782019-03-19 14:58:42 -07007662 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007663 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007664 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007665 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7666 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007667 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007668 }
Michelecea4cf22018-12-21 15:00:11 -08007669
7670 final long identity = Binder.clearCallingIdentity();
7671 try {
Michele0ea7d782019-03-19 14:58:42 -07007672 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007673 } finally {
7674 Binder.restoreCallingIdentity(identity);
7675 }
7676 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007677
Michele0ea7d782019-03-19 14:58:42 -07007678 @TelephonyManager.IsMultiSimSupportedResult
7679 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007680 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7681 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7682 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007683 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7684 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007685 }
7686 // Check if the hardware supports multisim functionality. If usage of multisim is not
7687 // supported by the modem, indicate that it is restricted.
7688 PhoneCapability staticCapability =
7689 mPhoneConfigurationManager.getStaticPhoneCapability();
7690 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007691 loge("isMultiSimSupportedInternal: no static configuration available");
7692 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007693 }
7694 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007695 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7696 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007697 }
7698 // Check if support of multiple SIMs is restricted by carrier
7699 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007700 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007701 }
7702
Michele0ea7d782019-03-19 14:58:42 -07007703 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007704 }
7705
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007706 /**
7707 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007708 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7709 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7710 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007711 * @param numOfSims number of active sims we want to switch to
7712 */
7713 @Override
7714 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007715 if (numOfSims == 1) {
7716 enforceModifyPermission();
7717 } else {
7718 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7719 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7720 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007721 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007722
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007723 try {
Michele30b57b22019-03-01 12:01:14 -08007724 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007725 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007726 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7727 return;
7728 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007729 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7730 } finally {
7731 Binder.restoreCallingIdentity(identity);
7732 }
7733 }
7734
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007735 @Override
7736 public boolean isApplicationOnUicc(int subId, int appType) {
7737 enforceReadPrivilegedPermission("isApplicationOnUicc");
7738 Phone phone = getPhone(subId);
7739 if (phone == null) {
7740 return false;
7741 }
7742 final long identity = Binder.clearCallingIdentity();
7743 try {
7744 UiccCard uiccCard = phone.getUiccCard();
7745 if (uiccCard == null) {
7746 return false;
7747 }
7748 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7749 if (uiccProfile == null) {
7750 return false;
7751 }
7752 if (TelephonyManager.APPTYPE_SIM <= appType
7753 && appType <= TelephonyManager.APPTYPE_ISIM) {
7754 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7755 }
7756 return false;
7757 } finally {
7758 Binder.restoreCallingIdentity(identity);
7759 }
7760 }
7761
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007762 /**
chen xub4baa772019-04-03 10:23:41 -07007763 * Get whether making changes to modem configurations will trigger reboot.
7764 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007765 */
7766 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007767 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7768 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007769 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007770 mApp, subId, callingPackage, callingFeatureId,
7771 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007772 return false;
7773 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007774 final long identity = Binder.clearCallingIdentity();
7775 try {
7776 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7777 } finally {
7778 Binder.restoreCallingIdentity(identity);
7779 }
7780 }
7781
Nathan Harold29f5f052019-02-15 13:41:57 -08007782 private void updateModemStateMetrics() {
7783 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7784 // TODO: check the state for each modem if the api is ready.
7785 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7786 }
7787
Pengquan Meng3889a572019-01-23 11:16:29 -08007788 @Override
7789 public int[] getSlotsMapping() {
7790 enforceReadPrivilegedPermission("getSlotsMapping");
7791
7792 final long identity = Binder.clearCallingIdentity();
7793 try {
7794 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7795 // All logical slots should have a mapping to a physical slot.
7796 int[] logicalSlotsMapping = new int[phoneCount];
7797 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7798 for (int i = 0; i < slotInfos.length; i++) {
7799 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7800 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7801 }
7802 }
7803 return logicalSlotsMapping;
7804 } finally {
7805 Binder.restoreCallingIdentity(identity);
7806 }
7807 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007808
7809 /**
7810 * Get the IRadio HAL Version
7811 */
7812 @Override
7813 public int getRadioHalVersion() {
7814 Phone phone = getDefaultPhone();
7815 if (phone == null) return -1;
7816 HalVersion hv = phone.getHalVersion();
7817 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7818 return hv.major * 100 + hv.minor;
7819 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007820
7821 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08007822 * Get the current calling package name.
7823 * @return the current calling package name
7824 */
7825 @Override
7826 public String getCurrentPackageName() {
7827 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
7828 }
7829
7830 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007831 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7832 * corresponding network requests on a subId.
7833 *
7834 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007835 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007836 * 2) APN is un-metered for this subscription, or
7837 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7838 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7839 *
7840 * @return whether data is allowed for a apn type.
7841 *
7842 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007843 */
7844 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007845 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07007846 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7847 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007848
7849 // Now that all security checks passes, perform the operation as ourselves.
7850 final long identity = Binder.clearCallingIdentity();
7851 try {
7852 Phone phone = getPhone(subId);
7853 if (phone == null) return false;
7854
Jack Yu41407ee2019-05-13 16:54:09 -07007855 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007856 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7857 } finally {
7858 Binder.restoreCallingIdentity(identity);
7859 }
7860 }
7861
7862 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007863 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007864 enforceReadPrivilegedPermission("isApnMetered");
7865
7866 // Now that all security checks passes, perform the operation as ourselves.
7867 final long identity = Binder.clearCallingIdentity();
7868 try {
7869 Phone phone = getPhone(subId);
7870 if (phone == null) return true; // By default return true.
7871
Jack Yu41407ee2019-05-13 16:54:09 -07007872 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007873 } finally {
7874 Binder.restoreCallingIdentity(identity);
7875 }
7876 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007877
7878 @Override
changbetty363e8ac2019-12-06 18:16:37 +08007879 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
7880 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
7881 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
7882 if (iccRecords == null) {
7883 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
7884 return false;
7885 }
7886 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
7887 }
7888
7889 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07007890 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08007891 if (callingPackage == null) {
7892 callingPackage = getCurrentPackageName();
7893 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007894 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7895 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7896 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7897 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7898 }
7899 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7900 Intent intent = new Intent();
7901 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7902 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7903 // Bring up choose default SMS subscription dialog right now
7904 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7905 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7906 mApp.startActivity(intent);
7907 }
chen xud5ca2d52019-05-28 15:20:57 -07007908
7909 @Override
7910 public String getMmsUAProfUrl(int subId) {
7911 //TODO investigate if this API should require proper permission check in R b/133791609
7912 final long identity = Binder.clearCallingIdentity();
7913 try {
7914 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7915 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7916 } finally {
7917 Binder.restoreCallingIdentity(identity);
7918 }
7919 }
7920
7921 @Override
7922 public String getMmsUserAgent(int subId) {
7923 //TODO investigate if this API should require proper permission check in R b/133791609
7924 final long identity = Binder.clearCallingIdentity();
7925 try {
7926 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7927 .getString(com.android.internal.R.string.config_mms_user_agent);
7928 } finally {
7929 Binder.restoreCallingIdentity(identity);
7930 }
7931 }
Jack Yub07d4972019-05-28 16:12:25 -07007932
7933 @Override
7934 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7935 enforceModifyPermission();
7936
7937 // Now that all security checks passes, perform the operation as ourselves.
7938 final long identity = Binder.clearCallingIdentity();
7939 try {
7940 Phone phone = getPhone(subId);
7941 if (phone == null) return false;
7942
7943 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7944 } finally {
7945 Binder.restoreCallingIdentity(identity);
7946 }
7947 }
7948
7949 @Override
7950 public boolean isDataAllowedInVoiceCall(int subId) {
7951 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7952
7953 // Now that all security checks passes, perform the operation as ourselves.
7954 final long identity = Binder.clearCallingIdentity();
7955 try {
7956 Phone phone = getPhone(subId);
7957 if (phone == null) return false;
7958
7959 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7960 } finally {
7961 Binder.restoreCallingIdentity(identity);
7962 }
7963 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007964
7965 /**
7966 * Updates whether conference event pacakge handling is enabled.
7967 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7968 * otherwise.
7969 */
7970 @Override
7971 public void setCepEnabled(boolean isCepEnabled) {
7972 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7973
7974 final long identity = Binder.clearCallingIdentity();
7975 try {
7976 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7977 for (Phone phone : PhoneFactory.getPhones()) {
7978 Phone defaultPhone = phone.getImsPhone();
7979 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7980 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7981 ImsPhoneCallTracker imsPhoneCallTracker =
7982 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7983 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7984 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7985 + imsPhone.getMsisdn());
7986 }
7987 }
7988 } finally {
7989 Binder.restoreCallingIdentity(identity);
7990 }
7991 }
allenwtsu46dcc572020-01-08 18:24:03 +08007992
7993 /**
7994 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
7995 *
7996 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
7997 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
7998 * before being read.
7999 */
8000 @Override
8001 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8002 isCompressed) {
8003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8004 mApp, subId, "notifyRcsAutoConfigurationReceived");
8005 try {
8006 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8007 if (configBinder == null) {
8008 Rlog.e(LOG_TAG, "null result for getImsConfig");
8009 } else {
8010 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8011 }
8012 } catch (RemoteException e) {
8013 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8014 }
8015 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008016}