blob: 97802138da3e0a9c073eef1ded408c81af85afa6 [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) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002955 if (!isActiveSubscription(subId)) {
2956 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2957 }
2958
Pengquan Menga1bb6272018-09-06 09:59:22 -07002959 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2960 }
2961
Brad Ebinger35c841c2018-10-01 10:40:55 -07002962 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002963 public boolean isInEmergencySmsMode() {
2964 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2965 final long identity = Binder.clearCallingIdentity();
2966 try {
2967 for (Phone phone : PhoneFactory.getPhones()) {
2968 if (phone.isInEmergencySmsMode()) {
2969 return true;
2970 }
2971 }
2972 } finally {
2973 Binder.restoreCallingIdentity(identity);
2974 }
2975 return false;
2976 }
2977
2978 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002979 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2980 throws RemoteException {
2981 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07002982 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2983 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2984 "IMS not available on device.");
2985 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002986 final long token = Binder.clearCallingIdentity();
2987 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002988 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002989 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002990 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002991 } catch (ImsException e) {
2992 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002993 } finally {
2994 Binder.restoreCallingIdentity(token);
2995 }
2996 }
2997
2998 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002999 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
3000 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003001 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3002 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3003 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003004 final long token = Binder.clearCallingIdentity();
3005 try {
3006 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3007 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3008 .removeRegistrationCallbackForSubscription(c, subId);
3009 } catch (ImsException e) {
3010 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3011 + "is inactive, ignoring unregister.");
3012 // If the subscription is no longer active, just return, since the callback
3013 // will already have been removed internally.
3014 } finally {
3015 Binder.restoreCallingIdentity(token);
3016 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003017 }
3018
Brad Ebinger774ba362019-10-22 17:36:18 -07003019 /**
3020 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3021 */
3022 @Override
3023 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3024 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3025 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3026 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3027 "IMS not available on device.");
3028 }
3029 final long token = Binder.clearCallingIdentity();
3030 try {
3031 Phone phone = getPhone(subId);
3032 if (phone == null) {
3033 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3034 + subId + "'");
3035 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3036 }
3037 phone.getImsRegistrationState(regState -> {
3038 try {
3039 consumer.accept((regState == null)
3040 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3041 } catch (RemoteException e) {
3042 // Ignore if the remote process is no longer available to call back.
3043 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3044 }
3045 });
3046 } finally {
3047 Binder.restoreCallingIdentity(token);
3048 }
3049 }
3050
3051 /**
3052 * Get the transport type for the IMS service registration state.
3053 */
3054 @Override
3055 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3056 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3057 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3058 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3059 "IMS not available on device.");
3060 }
3061 final long token = Binder.clearCallingIdentity();
3062 try {
3063 Phone phone = getPhone(subId);
3064 if (phone == null) {
3065 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3066 + subId + "'");
3067 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3068 }
3069 phone.getImsRegistrationTech(regTech -> {
3070 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3071 int regTechConverted = (regTech == null)
3072 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3073 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3074 regTechConverted);
3075 try {
3076 consumer.accept(regTechConverted);
3077 } catch (RemoteException e) {
3078 // Ignore if the remote process is no longer available to call back.
3079 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3080 }
3081 });
3082 } finally {
3083 Binder.restoreCallingIdentity(token);
3084 }
3085 }
3086
Brad Ebinger35c841c2018-10-01 10:40:55 -07003087 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003088 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3089 throws RemoteException {
3090 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003091 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3092 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3093 "IMS not available on device.");
3094 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003095 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3096 final long token = Binder.clearCallingIdentity();
3097 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003098 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003099 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003100 } catch (ImsException e) {
3101 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003102 } finally {
3103 Binder.restoreCallingIdentity(token);
3104 }
3105 }
3106
3107 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003108 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3109 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003110 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3111 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3112 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003113
3114 final long token = Binder.clearCallingIdentity();
3115 try {
3116 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3117 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003118 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003119 } catch (ImsException e) {
3120 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3121 + "is inactive, ignoring unregister.");
3122 // If the subscription is no longer active, just return, since the callback
3123 // will already have been removed internally.
3124 } finally {
3125 Binder.restoreCallingIdentity(token);
3126 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003127 }
3128
3129 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003130 public boolean isCapable(int subId, int capability, int regTech) {
3131 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003132 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3133 final long token = Binder.clearCallingIdentity();
3134 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003135 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003136 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003137 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003138 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3139 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003140 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003141 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3142 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003143 } finally {
3144 Binder.restoreCallingIdentity(token);
3145 }
3146 }
3147
3148 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003149 public boolean isAvailable(int subId, int capability, int regTech) {
3150 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003151 final long token = Binder.clearCallingIdentity();
3152 try {
3153 Phone phone = getPhone(subId);
3154 if (phone == null) return false;
3155 return phone.isImsCapabilityAvailable(capability, regTech);
3156 } finally {
3157 Binder.restoreCallingIdentity(token);
3158 }
3159 }
3160
Brad Ebinger77b832e2019-10-17 17:03:22 -07003161 /**
3162 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3163 * subscription.
3164 * @param subId The subscription to use to check the configuration.
3165 * @param callback The callback that will be used to send the result.
3166 * @param capability The MmTelFeature capability that will be used to send the result.
3167 * @param transportType The transport type of the MmTelFeature capability.
3168 */
3169 @Override
3170 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3171 int transportType) {
3172 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3173 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3174 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3175 "IMS not available on device.");
3176 }
3177 final long token = Binder.clearCallingIdentity();
3178 try {
3179 int slotId = getSlotIndex(subId);
3180 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3181 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3182 + subId + "'");
3183 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3184 }
3185 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3186 transportType, aBoolean -> {
3187 try {
3188 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3189 } catch (RemoteException e) {
3190 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3191 + "running. Ignore");
3192 }
3193 });
3194 } finally {
3195 Binder.restoreCallingIdentity(token);
3196 }
3197 }
3198
Brad Ebinger35c841c2018-10-01 10:40:55 -07003199 @Override
3200 public boolean isAdvancedCallingSettingEnabled(int subId) {
3201 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3202 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3203 final long token = Binder.clearCallingIdentity();
3204 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003205 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003206 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003207 } catch (ImsException e) {
3208 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003209 } finally {
3210 Binder.restoreCallingIdentity(token);
3211 }
3212 }
3213
3214 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003215 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003216 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003217 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003218 final long identity = Binder.clearCallingIdentity();
3219 try {
3220 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003221 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003222 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003223 } catch (ImsException e) {
3224 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003225 } finally {
3226 Binder.restoreCallingIdentity(identity);
3227 }
3228 }
3229
3230 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003231 public boolean isVtSettingEnabled(int subId) {
3232 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003233 final long identity = Binder.clearCallingIdentity();
3234 try {
3235 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003236 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3237 } catch (ImsException e) {
3238 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003239 } finally {
3240 Binder.restoreCallingIdentity(identity);
3241 }
3242 }
3243
3244 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003245 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003246 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003247 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003248 final long identity = Binder.clearCallingIdentity();
3249 try {
3250 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003251 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003252 } catch (ImsException e) {
3253 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003254 } finally {
3255 Binder.restoreCallingIdentity(identity);
3256 }
3257 }
3258
3259 @Override
3260 public boolean isVoWiFiSettingEnabled(int subId) {
3261 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3262 final long identity = Binder.clearCallingIdentity();
3263 try {
3264 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003265 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003266 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003267 } catch (ImsException e) {
3268 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003269 } finally {
3270 Binder.restoreCallingIdentity(identity);
3271 }
3272 }
3273
3274 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003275 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003277 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003278 final long identity = Binder.clearCallingIdentity();
3279 try {
3280 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003281 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003282 } catch (ImsException e) {
3283 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003284 } finally {
3285 Binder.restoreCallingIdentity(identity);
3286 }
3287 }
3288
3289 @Override
3290 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3291 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3292 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 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003296 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003297 } catch (ImsException e) {
3298 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003299 } finally {
3300 Binder.restoreCallingIdentity(identity);
3301 }
3302 }
3303
3304 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003305 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003306 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003307 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003308 final long identity = Binder.clearCallingIdentity();
3309 try {
3310 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003311 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003312 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003313 } catch (ImsException e) {
3314 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003315 } finally {
3316 Binder.restoreCallingIdentity(identity);
3317 }
3318 }
3319
3320 @Override
3321 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3322 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3323 "setVoWiFiNonPersistent");
3324 final long identity = Binder.clearCallingIdentity();
3325 try {
3326 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003327 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003328 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003329 } catch (ImsException e) {
3330 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003331 } finally {
3332 Binder.restoreCallingIdentity(identity);
3333 }
3334 }
3335
3336 @Override
3337 public int getVoWiFiModeSetting(int subId) {
3338 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3339 final long identity = Binder.clearCallingIdentity();
3340 try {
3341 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003342 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003343 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003344 } catch (ImsException e) {
3345 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003346 } finally {
3347 Binder.restoreCallingIdentity(identity);
3348 }
3349 }
3350
3351 @Override
3352 public void setVoWiFiModeSetting(int subId, int mode) {
3353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3354 "setVoWiFiModeSetting");
3355 final long identity = Binder.clearCallingIdentity();
3356 try {
3357 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003358 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003359 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003360 } catch (ImsException e) {
3361 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003362 } finally {
3363 Binder.restoreCallingIdentity(identity);
3364 }
3365 }
3366
3367 @Override
3368 public int getVoWiFiRoamingModeSetting(int subId) {
3369 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3370 final long identity = Binder.clearCallingIdentity();
3371 try {
3372 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003373 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003374 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003375 } catch (ImsException e) {
3376 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003377 } finally {
3378 Binder.restoreCallingIdentity(identity);
3379 }
3380 }
3381
3382 @Override
3383 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3384 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3385 "setVoWiFiRoamingModeSetting");
3386 final long identity = Binder.clearCallingIdentity();
3387 try {
3388 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003389 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003390 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003391 } catch (ImsException e) {
3392 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003393 } finally {
3394 Binder.restoreCallingIdentity(identity);
3395 }
3396 }
3397
3398 @Override
3399 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3400 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3401 "setRttCapabilityEnabled");
3402 final long identity = Binder.clearCallingIdentity();
3403 try {
3404 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003405 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3406 } catch (ImsException e) {
3407 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003408 } finally {
3409 Binder.restoreCallingIdentity(identity);
3410 }
3411 }
3412
3413 @Override
3414 public boolean isTtyOverVolteEnabled(int subId) {
3415 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3416 final long identity = Binder.clearCallingIdentity();
3417 try {
3418 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003419 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003420 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003421 } catch (ImsException e) {
3422 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003423 } finally {
3424 Binder.restoreCallingIdentity(identity);
3425 }
3426 }
3427
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003428 @Override
3429 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3430 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3431 final long identity = Binder.clearCallingIdentity();
3432 try {
Peter Wang050bb052020-01-13 23:33:09 -08003433 if (isImsAvailableOnDevice()) {
3434 throw new ImsException("IMS not available on device.",
3435 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
3436 }
3437
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003438 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003439 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003440 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003441 } catch (ImsException e) {
3442 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003443 } finally {
3444 Binder.restoreCallingIdentity(identity);
3445 }
3446 }
3447
3448 @Override
3449 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3450 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3451 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003452 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3453 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3454 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003455 try {
3456 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003457 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003458 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003459 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003460 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3461 + "is inactive, ignoring unregister.");
3462 // If the subscription is no longer active, just return, since the callback will already
3463 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003464 } finally {
3465 Binder.restoreCallingIdentity(identity);
3466 }
3467 }
3468
allenwtsu99c623b2020-01-03 18:24:23 +08003469
3470 private void checkModifyPhoneStatePermission(int subId, String message) {
3471 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3472 message);
3473 }
3474
3475 private boolean isImsProvisioningRequired(int subId, int capability,
3476 boolean isMmtelCapability) {
3477 Phone phone = getPhone(subId);
3478 if (phone == null) {
3479 loge("phone instance null for subid " + subId);
3480 return false;
3481 }
3482 if (isMmtelCapability) {
3483 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3484 return false;
3485 }
3486 } else {
3487 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3488 return false;
3489 }
3490 }
3491 return true;
3492 }
3493
3494 @Override
3495 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3496 boolean isProvisioned) {
3497 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3498
3499 final long identity = Binder.clearCallingIdentity();
3500 try {
3501 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3502 if (!isImsProvisioningRequired(subId, capability, false)) {
3503 return;
3504 }
3505
3506 // this capability requires provisioning, route to the correct API.
3507 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3508 switch (capability) {
3509 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3510 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3511 ims.setEabProvisioned(isProvisioned);
3512 break;
3513 default: {
3514 throw new IllegalArgumentException("Tried to set provisioning for "
3515 + "rcs capability '" + capability + "', which does not require "
3516 + "provisioning.");
3517 }
3518 }
3519 } finally {
3520 Binder.restoreCallingIdentity(identity);
3521 }
3522
3523 }
3524
3525
3526 @Override
3527 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3528 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3529 final long identity = Binder.clearCallingIdentity();
3530 try {
3531 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3532 if (!isImsProvisioningRequired(subId, capability, false)) {
3533 return true;
3534 }
3535
3536 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3537 switch (capability) {
3538 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3539 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3540 return ims.isEabProvisionedOnDevice();
3541
3542 default: {
3543 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3544 + "capability '" + capability + "', which does not require "
3545 + "provisioning.");
3546 }
3547 }
3548
3549 } finally {
3550 Binder.restoreCallingIdentity(identity);
3551 }
3552 }
3553
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003554 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003555 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3556 boolean isProvisioned) {
3557 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3558 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3559 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3560 }
allenwtsu99c623b2020-01-03 18:24:23 +08003561 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003562 final long identity = Binder.clearCallingIdentity();
3563 try {
3564 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003565 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003566 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 MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3573 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3574 ims.setVolteProvisioned(isProvisioned);
3575 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3576 ims.setWfcProvisioned(isProvisioned);
3577 }
3578 break;
3579 }
3580 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3581 // There is currently no difference in VT provisioning type.
3582 ims.setVtProvisioned(isProvisioned);
3583 break;
3584 }
3585 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3586 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3587 // change the capability of the feature instead if needed.
3588 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3589 == isProvisioned) {
3590 // No change in provisioning.
3591 return;
3592 }
3593 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3594 try {
3595 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003596 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003597 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3598 + ", Exception" + e.getMessage());
3599 }
3600 break;
3601 }
3602 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003603 throw new IllegalArgumentException("Tried to set provisioning for "
3604 + "MmTel capability '" + capability + "', which does not require "
3605 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003606 }
3607 }
3608
3609 } finally {
3610 Binder.restoreCallingIdentity(identity);
3611 }
3612 }
3613
3614 @Override
3615 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3616 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3617 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3618 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3619 }
3620 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3621 final long identity = Binder.clearCallingIdentity();
3622 try {
3623 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003624 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003625 return true;
3626 }
3627
3628 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3629 switch (capability) {
3630 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3631 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3632 return ims.isVolteProvisionedOnDevice();
3633 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3634 return ims.isWfcProvisionedOnDevice();
3635 }
3636 // This should never happen, since we are checking tech above to make sure it
3637 // is either LTE or IWLAN.
3638 throw new IllegalArgumentException("Invalid radio technology for voice "
3639 + "capability.");
3640 }
3641 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3642 // There is currently no difference in VT provisioning type.
3643 return ims.isVtProvisionedOnDevice();
3644 }
3645 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3646 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3647 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3648 }
3649 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003650 throw new IllegalArgumentException(
3651 "Tried to get provisioning for MmTel capability '" + capability
3652 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003653 }
3654 }
3655
3656 } finally {
3657 Binder.restoreCallingIdentity(identity);
3658 }
3659 }
3660
3661 @Override
3662 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3663 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3664 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3665 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3666 }
3667 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3668 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3669 return (provisionedBits & capability) > 0;
3670 }
3671
3672 @Override
3673 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3674 boolean isProvisioned) {
3675 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3676 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3677 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3678 }
3679 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3680 "setProvisioningStatusForCapability");
3681 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3682 // If the current provisioning status for capability already matches isProvisioned,
3683 // do nothing.
3684 if (((provisionedBits & capability) > 0) == isProvisioned) {
3685 return;
3686 }
3687 if (isProvisioned) {
3688 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3689 } else {
3690 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3691 }
3692 }
3693
3694 /**
3695 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3696 * technology. The bitfield should mirror the bitfield defined by
3697 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3698 */
3699 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3700 String key = getMmTelProvisioningKey(subId, tech);
3701 // Default is no capabilities are provisioned.
3702 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3703 }
3704
3705 /**
3706 * Sets the MmTel capability provisioning bitfield (defined by
3707 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3708 * technology specified.
3709 *
3710 * Note: This is a synchronous command and should not be called on UI thread.
3711 */
3712 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3713 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3714 String key = getMmTelProvisioningKey(subId, tech);
3715 editor.putInt(key, newField);
3716 editor.commit();
3717 }
3718
3719 private static String getMmTelProvisioningKey(int subId, int tech) {
3720 // resulting key is provision_ims_mmtel_{subId}_{tech}
3721 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3722 }
3723
3724 /**
3725 * Query CarrierConfig to see if the specified capability requires provisioning for the
3726 * carrier associated with the subscription id.
3727 */
3728 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3729 int capability) {
3730 CarrierConfigManager configManager = new CarrierConfigManager(context);
3731 PersistableBundle c = configManager.getConfigForSubId(subId);
3732 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003733 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003734 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3735 false);
3736 boolean requireVoiceVtProvisioning = c.getBoolean(
3737 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3738
3739 // First check to make sure that the capability requires provisioning.
3740 switch (capability) {
3741 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3742 // intentional fallthrough
3743 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3744 if (requireVoiceVtProvisioning) {
3745 // Voice and Video requires provisioning
3746 return true;
3747 }
3748 break;
3749 }
3750 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3751 if (requireUtProvisioning) {
3752 // UT requires provisioning
3753 return true;
3754 }
3755 break;
3756 }
3757 }
3758 return false;
3759 }
3760
allenwtsu99c623b2020-01-03 18:24:23 +08003761 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
3762 int capability) {
3763 CarrierConfigManager configManager = new CarrierConfigManager(context);
3764 PersistableBundle c = configManager.getConfigForSubId(subId);
3765
3766 boolean requireRcsProvisioning = c.getBoolean(
3767 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
3768
3769 // First check to make sure that the capability requires provisioning.
3770 switch (capability) {
3771 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3772 // intentional fallthrough
3773 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
3774 if (requireRcsProvisioning) {
3775 // OPTION or PRESENCE requires provisioning
3776 return true;
3777 }
3778 break;
3779 }
3780 }
3781 return false;
3782 }
3783
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003784 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003785 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003786 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3787 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3788 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003789 enforceReadPrivilegedPermission("getImsProvisioningInt");
3790 final long identity = Binder.clearCallingIdentity();
3791 try {
3792 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003793 int slotId = getSlotIndex(subId);
3794 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3795 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3796 + subId + "' for key:" + key);
3797 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3798 }
3799 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003800 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003801 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3802 + subId + "' for key:" + key);
3803 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003804 } finally {
3805 Binder.restoreCallingIdentity(identity);
3806 }
3807 }
3808
3809 @Override
3810 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003811 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3812 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3813 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003814 enforceReadPrivilegedPermission("getImsProvisioningString");
3815 final long identity = Binder.clearCallingIdentity();
3816 try {
3817 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003818 int slotId = getSlotIndex(subId);
3819 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3820 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3821 + subId + "' for key:" + key);
3822 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3823 }
3824 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003825 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003826 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3827 + subId + "' for key:" + key);
3828 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003829 } finally {
3830 Binder.restoreCallingIdentity(identity);
3831 }
3832 }
3833
3834 @Override
3835 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003836 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3837 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3838 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3840 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003841 final long identity = Binder.clearCallingIdentity();
3842 try {
3843 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003844 int slotId = getSlotIndex(subId);
3845 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3846 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3847 + subId + "' for key:" + key);
3848 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3849 }
3850 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003851 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003852 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3853 + "' for key:" + key);
3854 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003855 } finally {
3856 Binder.restoreCallingIdentity(identity);
3857 }
3858 }
3859
3860 @Override
3861 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003862 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3863 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3864 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3866 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003867 final long identity = Binder.clearCallingIdentity();
3868 try {
3869 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003870 int slotId = getSlotIndex(subId);
3871 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3872 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3873 + subId + "' for key:" + key);
3874 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3875 }
3876 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003877 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003878 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3879 + "' for key:" + key);
3880 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003881 } finally {
3882 Binder.restoreCallingIdentity(identity);
3883 }
3884 }
3885
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003886 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003887 int slotId = SubscriptionManager.getSlotIndex(subId);
3888 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003889 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3890 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003891 }
3892 return slotId;
3893 }
3894
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003895 private int getSlotIndex(int subId) {
3896 int slotId = SubscriptionManager.getSlotIndex(subId);
3897 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3898 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3899 }
3900 return slotId;
3901 }
3902
Wink Saville36469e72014-06-11 15:17:00 -07003903 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003904 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003905 */
3906 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003907 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3908 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003909 final int targetSdk = getTargetSdk(callingPackage);
3910 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003911 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003912 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003913 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003914 mApp, subId, callingPackage, callingFeatureId,
3915 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003916 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3917 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003918
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003919 final long identity = Binder.clearCallingIdentity();
3920 try {
3921 final Phone phone = getPhone(subId);
3922 if (phone != null) {
3923 return phone.getServiceState().getDataNetworkType();
3924 } else {
3925 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3926 }
3927 } finally {
3928 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003929 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003930 }
3931
3932 /**
3933 * Returns the data network type
3934 */
3935 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003936 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
3937 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
3938 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003939 }
3940
3941 /**
3942 * Returns the data network type for a subId
3943 */
3944 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003945 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
3946 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003947 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003948 mApp, subId, callingPackage, callingFeatureId,
3949 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003950 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3951 }
3952
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003953 final long identity = Binder.clearCallingIdentity();
3954 try {
3955 final Phone phone = getPhone(subId);
3956 if (phone != null) {
3957 return phone.getServiceState().getDataNetworkType();
3958 } else {
3959 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3960 }
3961 } finally {
3962 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003963 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003964 }
3965
3966 /**
Wink Saville36469e72014-06-11 15:17:00 -07003967 * Returns the Voice network type for a subId
3968 */
3969 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003970 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
3971 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003972 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003973 mApp, subId, callingPackage, callingFeatureId,
3974 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003975 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3976 }
3977
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003978 final long identity = Binder.clearCallingIdentity();
3979 try {
3980 final Phone phone = getPhone(subId);
3981 if (phone != null) {
3982 return phone.getServiceState().getVoiceNetworkType();
3983 } else {
3984 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3985 }
3986 } finally {
3987 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003988 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003989 }
3990
3991 /**
3992 * @return true if a ICC card is present
3993 */
3994 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003995 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003996 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3997 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003998 }
3999
4000 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004001 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004002 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004003 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004004 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004005 final long identity = Binder.clearCallingIdentity();
4006 try {
4007 final Phone phone = PhoneFactory.getPhone(slotIndex);
4008 if (phone != null) {
4009 return phone.getIccCard().hasIccCard();
4010 } else {
4011 return false;
4012 }
4013 } finally {
4014 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004015 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004016 }
4017
4018 /**
4019 * Return if the current radio is LTE on CDMA. This
4020 * is a tri-state return value as for a period of time
4021 * the mode may be unknown.
4022 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004023 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004024 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004025 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004026 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004027 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004028 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4029 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4030 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004031 }
4032
Sanket Padawe356d7632015-06-22 14:03:32 -07004033 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004034 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4035 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004036 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004037 mApp, subId, callingPackage, callingFeatureId,
4038 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004039 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4040 }
4041
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004042 final long identity = Binder.clearCallingIdentity();
4043 try {
4044 final Phone phone = getPhone(subId);
4045 if (phone == null) {
4046 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4047 } else {
4048 return phone.getLteOnCdmaMode();
4049 }
4050 } finally {
4051 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004052 }
Wink Saville36469e72014-06-11 15:17:00 -07004053 }
4054
Wink Saville36469e72014-06-11 15:17:00 -07004055 /**
4056 * {@hide}
4057 * Returns Default subId, 0 in the case of single standby.
4058 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004059 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004060 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004061 }
4062
Shishir Agrawala9f32182016-04-12 12:00:16 -07004063 private int getSlotForDefaultSubscription() {
4064 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4065 }
4066
Wink Savilleb564aae2014-10-23 10:18:09 -07004067 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004068 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004069 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004070
Pengquan Menge92a50d2018-09-21 15:54:48 -07004071 private boolean isActiveSubscription(int subId) {
4072 return mSubscriptionController.isActiveSubId(subId);
4073 }
4074
Ihab Awadf2177b72013-11-25 13:33:23 -08004075 /**
4076 * @see android.telephony.TelephonyManager.WifiCallingChoices
4077 */
4078 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004079 final long identity = Binder.clearCallingIdentity();
4080 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004081 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004082 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4083 getWhenToMakeWifiCallsDefaultPreference());
4084 } finally {
4085 Binder.restoreCallingIdentity(identity);
4086 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004087 }
4088
4089 /**
4090 * @see android.telephony.TelephonyManager.WifiCallingChoices
4091 */
4092 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004093 final long identity = Binder.clearCallingIdentity();
4094 try {
4095 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004096 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004097 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4098 } finally {
4099 Binder.restoreCallingIdentity(identity);
4100 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004101 }
4102
Sailesh Nepald1e68152013-12-12 19:08:02 -08004103 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004104 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004105 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004106 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004107
Jordan Liu4c733742019-02-28 12:03:40 -08004108 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4109 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4110 if (phoneId == -1) {
4111 throw new IllegalArgumentException("Given slot index: " + slotIndex
4112 + " does not correspond to an active phone");
4113 }
4114 return PhoneFactory.getPhone(phoneId);
4115 }
4116
Shishir Agrawal566b7612013-10-28 14:41:00 -07004117 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004118 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4119 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004120 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4121 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004122 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004123 if (DBG) {
4124 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4125 }
4126 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4127 p2);
4128 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004129
Jordan Liu4c733742019-02-28 12:03:40 -08004130
4131 @Override
4132 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4133 int slotIndex, String callingPackage, String aid, int p2) {
4134 enforceModifyPermission();
4135 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4136 if (DBG) {
4137 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4138 }
4139 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4140 callingPackage, aid, p2);
4141 }
4142
4143 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4144 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004145 final long identity = Binder.clearCallingIdentity();
4146 try {
4147 if (TextUtils.equals(ISDR_AID, aid)) {
4148 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004149 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4150 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004151 if (bestComponent == null
4152 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4153 loge("The calling package is not allowed to access ISD-R.");
4154 throw new SecurityException(
4155 "The calling package is not allowed to access ISD-R.");
4156 }
Derek Tan740e1672017-06-27 14:56:27 -07004157 }
Derek Tan740e1672017-06-27 14:56:27 -07004158
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004159 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004160 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4161 null /* workSource */);
4162 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004163 return response;
4164 } finally {
4165 Binder.restoreCallingIdentity(identity);
4166 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004167 }
4168
4169 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004170 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004171 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4172 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004173 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4174 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4175 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004176
Jordan Liu4c733742019-02-28 12:03:40 -08004177 @Override
4178 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4179 enforceModifyPermission();
4180 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4181 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4182 channel);
4183 }
4184
4185 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004186 final long identity = Binder.clearCallingIdentity();
4187 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004188 if (channel < 0) {
4189 return false;
4190 }
Jordan Liu4c733742019-02-28 12:03:40 -08004191 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4192 null /* workSource */);
4193 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004194 return success;
4195 } finally {
4196 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004197 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004198 }
4199
4200 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004201 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004202 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004203 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4204 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004205 if (DBG) {
4206 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4207 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4208 + p3 + " data=" + data);
4209 }
4210 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4211 command, p1, p2, p3, data);
4212 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004213
Jordan Liu4c733742019-02-28 12:03:40 -08004214 @Override
4215 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4216 int command, int p1, int p2, int p3, String data) {
4217 enforceModifyPermission();
4218 if (DBG) {
4219 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4220 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4221 + p3 + " data=" + data);
4222 }
4223 return iccTransmitApduLogicalChannelWithPermission(
4224 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4225 data);
4226 }
4227
4228 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4229 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004230 final long identity = Binder.clearCallingIdentity();
4231 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004232 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004233 return "";
4234 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004235
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004236 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004237 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4238 null /* workSource */);
4239 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004240
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004241 // Append the returned status code to the end of the response payload.
4242 String s = Integer.toHexString(
4243 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4244 if (response.payload != null) {
4245 s = IccUtils.bytesToHexString(response.payload) + s;
4246 }
4247 return s;
4248 } finally {
4249 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004250 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004251 }
Jake Hambye994d462014-02-03 13:10:13 -08004252
Evan Charltonc66da362014-05-16 14:06:40 -07004253 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004254 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4255 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004256 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4257 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004258 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004259 if (DBG) {
4260 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4261 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4262 }
4263 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4264 cla, command, p1, p2, p3, data);
4265 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004266
Jordan Liu4c733742019-02-28 12:03:40 -08004267 @Override
4268 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4269 int command, int p1, int p2, int p3, String data) {
4270 enforceModifyPermission();
4271 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4272 if (DBG) {
4273 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4274 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4275 + " data=" + data);
4276 }
4277
4278 return iccTransmitApduBasicChannelWithPermission(
4279 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4280 p2, p3, data);
4281 }
4282
4283 // open APDU basic channel assuming the caller has sufficient permissions
4284 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4285 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004286 final long identity = Binder.clearCallingIdentity();
4287 try {
4288 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4289 && TextUtils.equals(ISDR_AID, data)) {
4290 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004291 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4292 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004293 if (bestComponent == null
4294 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4295 loge("The calling package is not allowed to select ISD-R.");
4296 throw new SecurityException(
4297 "The calling package is not allowed to select ISD-R.");
4298 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004299 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004300
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004301 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004302 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4303 null /* workSource */);
4304 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004305
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004306 // Append the returned status code to the end of the response payload.
4307 String s = Integer.toHexString(
4308 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4309 if (response.payload != null) {
4310 s = IccUtils.bytesToHexString(response.payload) + s;
4311 }
4312 return s;
4313 } finally {
4314 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004315 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004316 }
4317
4318 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004319 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004320 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4322 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004323
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004324 final long identity = Binder.clearCallingIdentity();
4325 try {
4326 if (DBG) {
4327 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4328 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4329 }
4330
4331 IccIoResult response =
4332 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4333 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4334 subId);
4335
4336 if (DBG) {
4337 log("Exchange SIM_IO [R]" + response);
4338 }
4339
4340 byte[] result = null;
4341 int length = 2;
4342 if (response.payload != null) {
4343 length = 2 + response.payload.length;
4344 result = new byte[length];
4345 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4346 } else {
4347 result = new byte[length];
4348 }
4349
4350 result[length - 1] = (byte) response.sw2;
4351 result[length - 2] = (byte) response.sw1;
4352 return result;
4353 } finally {
4354 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004355 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004356 }
4357
Nathan Haroldb3014052017-01-25 15:57:32 -08004358 /**
4359 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4360 * on a particular subscription
4361 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004362 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4363 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004364 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004365 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004366 return null;
4367 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004368
4369 final long identity = Binder.clearCallingIdentity();
4370 try {
4371 if (appType != TelephonyManager.APPTYPE_USIM
4372 && appType != TelephonyManager.APPTYPE_SIM) {
4373 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4374 return null;
4375 }
4376 Object response = sendRequest(
4377 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4378 if (response instanceof String[]) {
4379 return (String[]) response;
4380 }
yincheng zhaod698b842019-09-06 17:06:54 -07004381 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004382 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004383 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004384 } finally {
4385 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004386 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004387 }
4388
yincheng zhaod698b842019-09-06 17:06:54 -07004389 /**
4390 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4391 * subscription.
4392 *
4393 * @param subId the id of the subscription.
4394 * @param appType the uicc app type, must be USIM or SIM.
4395 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4396 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004397 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004398 * @return number of fplmns that is successfully written to the SIM.
4399 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004400 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4401 String callingFeatureId) {
4402 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4403 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004404 if (DBG) logv("no permissions for setForbiddenplmns");
4405 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4406 }
4407 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4408 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4409 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4410 }
4411 if (fplmns == null) {
4412 throw new IllegalArgumentException("Fplmn List provided is null");
4413 }
4414 for (String fplmn : fplmns) {
4415 if (!CellIdentity.isValidPlmn(fplmn)) {
4416 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4417 }
4418 }
4419 final long identity = Binder.clearCallingIdentity();
4420 try {
4421 Object response = sendRequest(
4422 CMD_SET_FORBIDDEN_PLMNS,
4423 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4424 subId);
4425 return (int) response;
4426 } finally {
4427 Binder.restoreCallingIdentity(identity);
4428 }
4429 }
4430
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004431 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004432 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004433 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4434 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004435
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004436 final long identity = Binder.clearCallingIdentity();
4437 try {
4438 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4439 if (response.payload == null) {
4440 return "";
4441 }
Evan Charltonc66da362014-05-16 14:06:40 -07004442
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004443 // Append the returned status code to the end of the response payload.
4444 String s = Integer.toHexString(
4445 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4446 s = IccUtils.bytesToHexString(response.payload) + s;
4447 return s;
4448 } finally {
4449 Binder.restoreCallingIdentity(identity);
4450 }
Evan Charltonc66da362014-05-16 14:06:40 -07004451 }
4452
Jake Hambye994d462014-02-03 13:10:13 -08004453 /**
4454 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4455 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4456 *
4457 * @param itemID the ID of the item to read
4458 * @return the NV item as a String, or null on error.
4459 */
4460 @Override
4461 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004462 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004463 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4464 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004465
4466 final long identity = Binder.clearCallingIdentity();
4467 try {
4468 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004469 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004470 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4471 return value;
4472 } finally {
4473 Binder.restoreCallingIdentity(identity);
4474 }
Jake Hambye994d462014-02-03 13:10:13 -08004475 }
4476
4477 /**
4478 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4479 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4480 *
4481 * @param itemID the ID of the item to read
4482 * @param itemValue the value to write, as a String
4483 * @return true on success; false on any failure
4484 */
4485 @Override
4486 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004487 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004488 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4489 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004490
4491 final long identity = Binder.clearCallingIdentity();
4492 try {
4493 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4494 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004495 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004496 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4497 return success;
4498 } finally {
4499 Binder.restoreCallingIdentity(identity);
4500 }
Jake Hambye994d462014-02-03 13:10:13 -08004501 }
4502
4503 /**
4504 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4505 * Used for device configuration by some CDMA operators.
4506 *
4507 * @param preferredRoamingList byte array containing the new PRL
4508 * @return true on success; false on any failure
4509 */
4510 @Override
4511 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004512 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4513 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004514
4515 final long identity = Binder.clearCallingIdentity();
4516 try {
4517 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4518 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4519 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4520 return success;
4521 } finally {
4522 Binder.restoreCallingIdentity(identity);
4523 }
Jake Hambye994d462014-02-03 13:10:13 -08004524 }
4525
4526 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004527 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004528 * Used for device configuration by some CDMA operators.
4529 *
chen xu6dac5ab2018-10-26 17:39:23 -07004530 * @param slotIndex - device slot.
4531 *
Jake Hambye994d462014-02-03 13:10:13 -08004532 * @return true on success; false on any failure
4533 */
4534 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004535 public boolean resetModemConfig(int slotIndex) {
4536 Phone phone = PhoneFactory.getPhone(slotIndex);
4537 if (phone != null) {
4538 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4539 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004540
chen xu6dac5ab2018-10-26 17:39:23 -07004541 final long identity = Binder.clearCallingIdentity();
4542 try {
4543 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4544 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4545 return success;
4546 } finally {
4547 Binder.restoreCallingIdentity(identity);
4548 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004549 }
chen xu6dac5ab2018-10-26 17:39:23 -07004550 return false;
4551 }
4552
4553 /**
4554 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4555 *
4556 * @param slotIndex - device slot.
4557 *
4558 * @return true on success; false on any failure
4559 */
4560 @Override
4561 public boolean rebootModem(int slotIndex) {
4562 Phone phone = PhoneFactory.getPhone(slotIndex);
4563 if (phone != null) {
4564 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4565 mApp, phone.getSubId(), "rebootModem");
4566
4567 final long identity = Binder.clearCallingIdentity();
4568 try {
4569 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4570 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4571 return success;
4572 } finally {
4573 Binder.restoreCallingIdentity(identity);
4574 }
4575 }
4576 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004577 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004578
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004579 public String[] getPcscfAddress(String apnType, String callingPackage,
4580 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004581 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004582 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4583 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004584 return new String[0];
4585 }
4586
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004587 final long identity = Binder.clearCallingIdentity();
4588 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004589 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004590 } finally {
4591 Binder.restoreCallingIdentity(identity);
4592 }
Wink Saville36469e72014-06-11 15:17:00 -07004593 }
4594
Brad Ebinger51f743a2017-01-23 13:50:20 -08004595 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004596 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4597 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004598 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004599 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004600 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004601
4602 final long identity = Binder.clearCallingIdentity();
4603 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004604 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004605 // may happen if the device does not support IMS.
4606 return;
4607 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004608 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004609 } finally {
4610 Binder.restoreCallingIdentity(identity);
4611 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004612 }
4613
4614 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004615 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4616 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004617 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004618 public void disableIms(int slotId) {
4619 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004620
4621 final long identity = Binder.clearCallingIdentity();
4622 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004623 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004624 // may happen if the device does not support IMS.
4625 return;
4626 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004627 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004628 } finally {
4629 Binder.restoreCallingIdentity(identity);
4630 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004631 }
4632
4633 /**
4634 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4635 * feature or {@link null} if the service is not available. If the feature is available, the
4636 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4637 */
4638 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004639 IImsServiceFeatureCallback callback) {
4640 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004641
4642 final long identity = Binder.clearCallingIdentity();
4643 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004644 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004645 // may happen if the device does not support IMS.
4646 return null;
4647 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004648 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004649 } finally {
4650 Binder.restoreCallingIdentity(identity);
4651 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004652 }
4653
4654 /**
4655 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4656 * feature during emergency calling or {@link null} if the service is not available. If the
4657 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4658 * listener for feature updates.
4659 */
4660 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4661 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004662
4663 final long identity = Binder.clearCallingIdentity();
4664 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004665 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004666 // may happen if the device does not support IMS.
4667 return null;
4668 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004669 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004670 } finally {
4671 Binder.restoreCallingIdentity(identity);
4672 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004673 }
4674
Brad Ebinger5f64b052017-12-14 14:26:15 -08004675 /**
4676 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004677 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004678 */
4679 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4680 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004681
4682 final long identity = Binder.clearCallingIdentity();
4683 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004684 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004685 // may happen if the device does not support IMS.
4686 return null;
4687 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004688 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004689 } finally {
4690 Binder.restoreCallingIdentity(identity);
4691 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004692 }
4693
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004694 /**
4695 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004696 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004697 */
4698 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4699 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004700
4701 final long identity = Binder.clearCallingIdentity();
4702 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004703 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004704 // may happen if the device does not support IMS.
4705 return null;
4706 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004707 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004708 } finally {
4709 Binder.restoreCallingIdentity(identity);
4710 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004711 }
4712
Brad Ebinger884c07b2018-02-15 16:17:40 -08004713 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004714 * Sets the ImsService Package Name that Telephony will bind to.
4715 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08004716 * @param slotIndex the slot ID that the ImsService should bind for.
4717 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004718 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004719 * @param featureTypes An integer array of feature types associated with a packageName.
4720 * @param packageName The name of the package that the current configuration will be replaced
4721 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004722 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004723 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004724 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4725 int[] featureTypes, String packageName) {
4726 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4727 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004728 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4729 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08004730 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004731
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004732 final long identity = Binder.clearCallingIdentity();
4733 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004734 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004735 // may happen if the device does not support IMS.
4736 return false;
4737 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004738 Map<Integer, String> featureConfig = new HashMap<>();
4739 for (int featureType : featureTypes) {
4740 featureConfig.put(featureType, packageName);
4741 }
4742 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4743 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004744 } finally {
4745 Binder.restoreCallingIdentity(identity);
4746 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004747 }
4748
4749 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08004750 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004751 *
4752 * @param slotId The slot that the ImsService is associated with.
4753 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4754 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004755 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004756 * @return the package name of the ImsService configuration.
4757 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004758 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4759 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004760 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08004761 TelephonyPermissions
4762 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4763 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4764 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004766 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 "";
4771 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004772 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004773 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4774 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004775 } finally {
4776 Binder.restoreCallingIdentity(identity);
4777 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004778 }
4779
Brad Ebinger77b832e2019-10-17 17:03:22 -07004780 /**
4781 * Get the MmTelFeature state associated with the requested subscription id.
4782 * @param subId The subscription that the MmTelFeature is associated with.
4783 * @param callback A callback with an integer containing the
4784 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4785 */
4786 @Override
4787 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4788 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4789 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4790 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4791 "IMS not available on device.");
4792 }
4793 final long token = Binder.clearCallingIdentity();
4794 try {
4795 int slotId = getSlotIndex(subId);
4796 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4797 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4798 + subId + "'");
4799 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4800 }
4801 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4802 try {
4803 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4804 } catch (RemoteException e) {
4805 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4806 + "Ignore");
4807 }
4808 });
4809 } finally {
4810 Binder.restoreCallingIdentity(token);
4811 }
4812 }
4813
Wink Saville36469e72014-06-11 15:17:00 -07004814 public void setImsRegistrationState(boolean registered) {
4815 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004816
4817 final long identity = Binder.clearCallingIdentity();
4818 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004819 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004820 } finally {
4821 Binder.restoreCallingIdentity(identity);
4822 }
Wink Saville36469e72014-06-11 15:17:00 -07004823 }
4824
4825 /**
Stuart Scott54788802015-03-30 13:18:01 -07004826 * Set the network selection mode to automatic.
4827 *
4828 */
4829 @Override
4830 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004831 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4832 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004833
Pengquan Menge92a50d2018-09-21 15:54:48 -07004834 if (!isActiveSubscription(subId)) {
4835 return;
4836 }
4837
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004838 final long identity = Binder.clearCallingIdentity();
4839 try {
4840 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4841 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4842 } finally {
4843 Binder.restoreCallingIdentity(identity);
4844 }
Stuart Scott54788802015-03-30 13:18:01 -07004845 }
4846
Pengquan Mengea84e042018-09-20 14:57:26 -07004847 /**
4848 * Ask the radio to connect to the input network and change selection mode to manual.
4849 *
4850 * @param subId the id of the subscription.
4851 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4852 * the operator to attach to.
4853 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4854 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4855 * normal network selection next time.
4856 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004857 */
4858 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004859 public boolean setNetworkSelectionModeManual(
4860 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004861 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4862 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004863
4864 if (!isActiveSubscription(subId)) {
4865 return false;
4866 }
4867
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004868 final long identity = Binder.clearCallingIdentity();
4869 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004870 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004871 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004872 if (DBG) {
4873 log("setNetworkSelectionModeManual: subId: " + subId
4874 + " operator: " + operatorInfo);
4875 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004876 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4877 } finally {
4878 Binder.restoreCallingIdentity(identity);
4879 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004880 }
4881
4882 /**
4883 * Scans for available networks.
4884 */
4885 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004886 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4887 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4889 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004890 LocationAccessPolicy.LocationPermissionResult locationResult =
4891 LocationAccessPolicy.checkLocationPermission(mApp,
4892 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4893 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004894 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004895 .setCallingPid(Binder.getCallingPid())
4896 .setCallingUid(Binder.getCallingUid())
4897 .setMethod("getCellNetworkScanResults")
4898 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4899 .build());
4900 switch (locationResult) {
4901 case DENIED_HARD:
4902 throw new SecurityException("Not allowed to access scan results -- location");
4903 case DENIED_SOFT:
4904 return null;
4905 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004906
Pengquan Menga1bb6272018-09-06 09:59:22 -07004907 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004908 try {
4909 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004910 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004911 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004912 } finally {
4913 Binder.restoreCallingIdentity(identity);
4914 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004915 }
4916
4917 /**
yinxub1bed742017-04-17 11:45:04 -07004918 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004919 *
yinxub1bed742017-04-17 11:45:04 -07004920 * @param subId id of the subscription
4921 * @param request contains the radio access networks with bands/channels to scan
4922 * @param messenger callback messenger for scan results or errors
4923 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004924 * @return the id of the requested scan which can be used to stop the scan.
4925 */
4926 @Override
4927 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004928 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004929 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4930 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004931 LocationAccessPolicy.LocationPermissionResult locationResult =
4932 LocationAccessPolicy.checkLocationPermission(mApp,
4933 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4934 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004935 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004936 .setCallingPid(Binder.getCallingPid())
4937 .setCallingUid(Binder.getCallingUid())
4938 .setMethod("requestNetworkScan")
4939 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4940 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004941 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004942 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004943 if (e != null) {
4944 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4945 throw e;
4946 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004947 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004948 return TelephonyScanManager.INVALID_SCAN_ID;
4949 }
4950 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004951 }
Hall Liu912dfd32019-04-25 14:02:26 -07004952 int callingUid = Binder.getCallingUid();
4953 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004954 final long identity = Binder.clearCallingIdentity();
4955 try {
4956 return mNetworkScanRequestTracker.startNetworkScan(
4957 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004958 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004959 } finally {
4960 Binder.restoreCallingIdentity(identity);
4961 }
yinxu504e1392017-04-12 16:03:22 -07004962 }
4963
Hall Liub2ac8ef2019-02-28 15:56:23 -08004964 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004965 NetworkScanRequest request, int subId) {
4966 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4967 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4968 boolean hasNetworkScanPermission =
4969 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4970 == PERMISSION_GRANTED;
4971
4972 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4973 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4974 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004975 }
4976
4977 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4978 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004979 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4980 return new SecurityException("Specific channels must not be"
4981 + " scanned without location access.");
4982 }
4983 }
4984 }
4985
Hall Liub2ac8ef2019-02-28 15:56:23 -08004986 return null;
4987 }
4988
yinxu504e1392017-04-12 16:03:22 -07004989 /**
4990 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004991 *
4992 * @param subId id of the subscription
4993 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004994 */
4995 @Override
4996 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004997 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4998 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004999
Hall Liu912dfd32019-04-25 14:02:26 -07005000 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005001 final long identity = Binder.clearCallingIdentity();
5002 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005003 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004 } finally {
5005 Binder.restoreCallingIdentity(identity);
5006 }
yinxu504e1392017-04-12 16:03:22 -07005007 }
5008
5009 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005010 * Get the calculated preferred network type.
5011 * Used for debugging incorrect network type.
5012 *
5013 * @return the preferred network type, defined in RILConstants.java.
5014 */
5015 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005016 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005017 final Phone defaultPhone = getDefaultPhone();
5018 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005019 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005020 return RILConstants.PREFERRED_NETWORK_MODE;
5021 }
5022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005023 final long identity = Binder.clearCallingIdentity();
5024 try {
5025 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005026 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005027 } finally {
5028 Binder.restoreCallingIdentity(identity);
5029 }
Junda Liu84d15a22014-07-02 11:21:04 -07005030 }
5031
5032 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005033 * Get the preferred network type.
5034 * Used for device configuration by some CDMA operators.
5035 *
5036 * @return the preferred network type, defined in RILConstants.java.
5037 */
5038 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005039 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005040 TelephonyPermissions
5041 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5042 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005043
5044 final long identity = Binder.clearCallingIdentity();
5045 try {
5046 if (DBG) log("getPreferredNetworkType");
5047 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5048 int networkType = (result != null ? result[0] : -1);
5049 if (DBG) log("getPreferredNetworkType: " + networkType);
5050 return networkType;
5051 } finally {
5052 Binder.restoreCallingIdentity(identity);
5053 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005054 }
5055
5056 /**
5057 * Set the preferred network type.
5058 * Used for device configuration by some CDMA operators.
5059 *
5060 * @param networkType the preferred network type, defined in RILConstants.java.
5061 * @return true on success; false on any failure.
5062 */
5063 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005064 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005065 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5066 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005067
5068 final long identity = Binder.clearCallingIdentity();
5069 try {
5070 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
5071 Boolean success = (Boolean) sendRequest(
5072 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5073 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5074 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005075 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005076 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5077 }
5078 return success;
5079 } finally {
5080 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005081 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005082 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005083
5084 /**
Miaoa84611c2019-03-15 09:21:10 +08005085 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005086 *
Miaoa84611c2019-03-15 09:21:10 +08005087 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005088 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005089 * @hide
5090 */
5091 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005092 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005093 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005094 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005095 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005096 try {
Miaoa84611c2019-03-15 09:21:10 +08005097 if (phone != null) {
5098 return phone.hasMatchedTetherApnSetting();
5099 } else {
5100 return false;
5101 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005102 } finally {
5103 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005104 }
Junda Liu475951f2014-11-07 16:45:03 -08005105 }
5106
5107 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005108 * Set mobile data enabled
5109 * Used by the user through settings etc to turn on/off mobile data
5110 *
5111 * @param enable {@code true} turn turn data on, else {@code false}
5112 */
5113 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005114 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005115 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5116 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005117
5118 final long identity = Binder.clearCallingIdentity();
5119 try {
5120 int phoneId = mSubscriptionController.getPhoneId(subId);
5121 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5122 Phone phone = PhoneFactory.getPhone(phoneId);
5123 if (phone != null) {
5124 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005125 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005126 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005127 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005128 }
5129 } finally {
5130 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005131 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005132 }
5133
5134 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005135 * Get the user enabled state of Mobile Data.
5136 *
5137 * TODO: remove and use isUserDataEnabled.
5138 * This can't be removed now because some vendor codes
5139 * calls through ITelephony directly while they should
5140 * use TelephonyManager.
5141 *
5142 * @return true on enabled
5143 */
5144 @Override
5145 public boolean getDataEnabled(int subId) {
5146 return isUserDataEnabled(subId);
5147 }
5148
5149 /**
5150 * Get whether mobile data is enabled per user setting.
5151 *
5152 * There are other factors deciding whether mobile data is actually enabled, but they are
5153 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005154 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005155 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005156 *
5157 * @return {@code true} if data is enabled else {@code false}
5158 */
5159 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005160 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005161 try {
5162 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5163 null);
5164 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005165 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5166 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005167 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005168
5169 final long identity = Binder.clearCallingIdentity();
5170 try {
5171 int phoneId = mSubscriptionController.getPhoneId(subId);
5172 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5173 Phone phone = PhoneFactory.getPhone(phoneId);
5174 if (phone != null) {
5175 boolean retVal = phone.isUserDataEnabled();
5176 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5177 return retVal;
5178 } else {
5179 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5180 return false;
5181 }
5182 } finally {
5183 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005184 }
5185 }
5186
5187 /**
5188 * Get whether mobile data is enabled.
5189 *
5190 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5191 * whether mobile data is actually enabled.
5192 *
5193 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5194 *
5195 * @return {@code true} if data is enabled else {@code false}
5196 */
5197 @Override
5198 public boolean isDataEnabled(int subId) {
5199 try {
5200 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5201 null);
5202 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005203 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5204 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005205 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005206
5207 final long identity = Binder.clearCallingIdentity();
5208 try {
5209 int phoneId = mSubscriptionController.getPhoneId(subId);
5210 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5211 Phone phone = PhoneFactory.getPhone(phoneId);
5212 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005213 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005214 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5215 return retVal;
5216 } else {
5217 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5218 return false;
5219 }
5220 } finally {
5221 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005222 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005223 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005224
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005225 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5226 Phone phone) {
5227 //load access rules from carrier configs, and check those as well: b/139133814
5228 SubscriptionController subController = SubscriptionController.getInstance();
5229 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5230 || subController == null) return privilegeFromSim;
5231
5232 int uid = Binder.getCallingUid();
5233 PackageManager pkgMgr = phone.getContext().getPackageManager();
5234 String[] packages = pkgMgr.getPackagesForUid(uid);
5235
5236 final long identity = Binder.clearCallingIdentity();
5237 try {
5238 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5239 SubscriptionManager subManager = (SubscriptionManager)
5240 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5241 for (String pkg : packages) {
5242 if (subManager.canManageSubscription(subInfo, pkg)) {
5243 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5244 }
5245 }
5246 return privilegeFromSim;
5247 } finally {
5248 Binder.restoreCallingIdentity(identity);
5249 }
5250 }
5251
5252 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5253 String pkgName) {
5254 //load access rules from carrier configs, and check those as well: b/139133814
5255 SubscriptionController subController = SubscriptionController.getInstance();
5256 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5257 || subController == null) return privilegeFromSim;
5258
5259 final long identity = Binder.clearCallingIdentity();
5260 try {
5261 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5262 SubscriptionManager subManager = (SubscriptionManager)
5263 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5264 return subManager.canManageSubscription(subInfo, pkgName)
5265 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5266 } finally {
5267 Binder.restoreCallingIdentity(identity);
5268 }
5269 }
5270
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005271 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005272 public int getCarrierPrivilegeStatus(int subId) {
5273 final Phone phone = getPhone(subId);
5274 if (phone == null) {
5275 loge("getCarrierPrivilegeStatus: Invalid subId");
5276 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5277 }
5278 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005279 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005280 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005281 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5282 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005283
5284 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5285 card.getCarrierPrivilegeStatusForCurrentTransaction(
5286 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005287 }
Junda Liu29340342014-07-10 15:23:27 -07005288
5289 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005290 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005291 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005292 final Phone phone = getPhone(subId);
5293 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005294 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005295 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5296 }
5297 UiccProfile profile =
5298 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5299 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005300 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005301 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5302 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005303 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005304 profile.getCarrierPrivilegeStatusForUid(
5305 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005306 }
5307
5308 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005309 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5310 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005311 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005312 }
5313
5314 int phoneId = SubscriptionManager.getPhoneId(subId);
5315 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005316 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005317 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005318 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5319 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005320 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5321 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5322 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005323 }
5324
5325 @Override
5326 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005327 if (TextUtils.isEmpty(pkgName))
5328 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005329 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5330 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5331 UiccCard card = UiccController.getInstance().getUiccCard(i);
5332 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005333 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005334 continue;
5335 }
5336
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005337 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5338 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5339 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005340 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5341 break;
5342 }
5343 }
5344
5345 return result;
Junda Liu29340342014-07-10 15:23:27 -07005346 }
Derek Tan89e89d42014-07-08 17:00:10 -07005347
5348 @Override
Junda Liue64de782015-04-16 17:19:16 -07005349 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5350 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5351 loge("phoneId " + phoneId + " is not valid.");
5352 return null;
5353 }
5354 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005355 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005356 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005357 return null ;
5358 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005359 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005360 }
5361
Amith Yamasani6e118872016-02-19 12:53:51 -08005362 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005363 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005364 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005365 List<String> privilegedPackages = new ArrayList<>();
5366 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005367 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5368 // has UICC in that slot.
5369 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005370 if (card.hasCarrierPrivilegeRules()) {
5371 if (packages == null) {
5372 // Only check packages in user 0 for now
5373 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005374 PackageManager.MATCH_DISABLED_COMPONENTS
5375 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005376 | PackageManager.GET_SIGNING_CERTIFICATES,
5377 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005378 }
5379 for (int p = packages.size() - 1; p >= 0; p--) {
5380 PackageInfo pkgInfo = packages.get(p);
5381 if (pkgInfo != null && pkgInfo.packageName != null
5382 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005383 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005384 privilegedPackages.add(pkgInfo.packageName);
5385 }
5386 }
5387 }
5388 }
5389 return privilegedPackages;
5390 }
5391
chen xuf7e9fe82019-05-09 19:31:02 -07005392 @Override
5393 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005394 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5395
5396 final long identity = Binder.clearCallingIdentity();
5397
chen xuf7e9fe82019-05-09 19:31:02 -07005398 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005399 try {
5400 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5401 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5402 }
5403 } finally {
5404 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005405 }
5406 return privilegedPackages;
5407 }
5408
Wink Savilleb564aae2014-10-23 10:18:09 -07005409 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005410 final Phone phone = getPhone(subId);
5411 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005412 if (card == null) {
5413 loge("getIccId: No UICC");
5414 return null;
5415 }
5416 String iccId = card.getIccId();
5417 if (TextUtils.isEmpty(iccId)) {
5418 loge("getIccId: ICC ID is null or empty.");
5419 return null;
5420 }
5421 return iccId;
5422 }
5423
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005424 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005425 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5426 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08005427 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005428 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005429
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005430 final long identity = Binder.clearCallingIdentity();
5431 try {
5432 final String iccId = getIccId(subId);
5433 final Phone phone = getPhone(subId);
5434 if (phone == null) {
5435 return false;
5436 }
5437 final String subscriberId = phone.getSubscriberId();
5438
5439 if (DBG_MERGE) {
5440 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5441 + subscriberId + " to " + number);
5442 }
5443
5444 if (TextUtils.isEmpty(iccId)) {
5445 return false;
5446 }
5447
5448 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5449
5450 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5451 if (alphaTag == null) {
5452 editor.remove(alphaTagPrefKey);
5453 } else {
5454 editor.putString(alphaTagPrefKey, alphaTag);
5455 }
5456
5457 // Record both the line number and IMSI for this ICCID, since we need to
5458 // track all merged IMSIs based on line number
5459 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5460 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5461 if (number == null) {
5462 editor.remove(numberPrefKey);
5463 editor.remove(subscriberPrefKey);
5464 } else {
5465 editor.putString(numberPrefKey, number);
5466 editor.putString(subscriberPrefKey, subscriberId);
5467 }
5468
5469 editor.commit();
5470 return true;
5471 } finally {
5472 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005473 }
Derek Tan7226c842014-07-02 17:42:23 -07005474 }
5475
5476 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005477 public String getLine1NumberForDisplay(int subId, String callingPackage,
5478 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005479 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005480 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005481 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005482 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005483 return null;
5484 }
Derek Tan97ebb422014-09-05 16:55:38 -07005485
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005486 final long identity = Binder.clearCallingIdentity();
5487 try {
5488 String iccId = getIccId(subId);
5489 if (iccId != null) {
5490 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5491 if (DBG_MERGE) {
5492 log("getLine1NumberForDisplay returning "
5493 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5494 }
5495 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005496 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005497 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5498 return null;
5499 } finally {
5500 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005501 }
Derek Tan7226c842014-07-02 17:42:23 -07005502 }
5503
5504 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005505 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5506 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005507 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005508 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005509 return null;
5510 }
Derek Tan97ebb422014-09-05 16:55:38 -07005511
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005512 final long identity = Binder.clearCallingIdentity();
5513 try {
5514 String iccId = getIccId(subId);
5515 if (iccId != null) {
5516 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5517 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5518 }
5519 return null;
5520 } finally {
5521 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005522 }
Derek Tan7226c842014-07-02 17:42:23 -07005523 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005524
5525 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005526 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5527 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005528 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5529 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005530 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005531 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005532 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005533 return null;
5534 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005535
Jordan Liub49b04b2019-05-06 14:45:15 -07005536 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5537 // the process, where TelephonyManager was instantiated.
5538 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005539 final long identity = Binder.clearCallingIdentity();
5540 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005541 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005542 final TelephonyManager tele = TelephonyManager.from(context);
5543 final SubscriptionManager sub = SubscriptionManager.from(context);
5544
5545 // Figure out what subscribers are currently active
5546 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005547
Jordan Liub49b04b2019-05-06 14:45:15 -07005548 // Only consider subs which match the current subId
5549 // This logic can be simplified. See b/131189269 for progress.
5550 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005551 activeSubscriberIds.add(tele.getSubscriberId(subId));
5552 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005553
5554 // First pass, find a number override for an active subscriber
5555 String mergeNumber = null;
5556 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5557 for (String key : prefs.keySet()) {
5558 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5559 final String subscriberId = (String) prefs.get(key);
5560 if (activeSubscriberIds.contains(subscriberId)) {
5561 final String iccId = key.substring(
5562 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5563 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5564 mergeNumber = (String) prefs.get(numberKey);
5565 if (DBG_MERGE) {
5566 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5567 + " for active subscriber " + subscriberId);
5568 }
5569 if (!TextUtils.isEmpty(mergeNumber)) {
5570 break;
5571 }
5572 }
5573 }
5574 }
5575
5576 // Shortcut when no active merged subscribers
5577 if (TextUtils.isEmpty(mergeNumber)) {
5578 return null;
5579 }
5580
5581 // Second pass, find all subscribers under that line override
5582 final ArraySet<String> result = new ArraySet<>();
5583 for (String key : prefs.keySet()) {
5584 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5585 final String number = (String) prefs.get(key);
5586 if (mergeNumber.equals(number)) {
5587 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5588 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5589 final String subscriberId = (String) prefs.get(subscriberKey);
5590 if (!TextUtils.isEmpty(subscriberId)) {
5591 result.add(subscriberId);
5592 }
5593 }
5594 }
5595 }
5596
5597 final String[] resultArray = result.toArray(new String[result.size()]);
5598 Arrays.sort(resultArray);
5599 if (DBG_MERGE) {
5600 Slog.d(LOG_TAG,
5601 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5602 }
5603 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005604 } finally {
5605 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005606 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005607 }
5608
5609 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005610 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5611 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5612
5613 final long identity = Binder.clearCallingIdentity();
5614 try {
5615 final TelephonyManager telephonyManager = mApp.getSystemService(
5616 TelephonyManager.class);
5617 String subscriberId = telephonyManager.getSubscriberId(subId);
5618 if (subscriberId == null) {
5619 if (DBG) {
5620 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5621 + subId);
5622 }
5623 return null;
5624 }
5625
5626 final SubscriptionInfo info = SubscriptionController.getInstance()
5627 .getSubscriptionInfo(subId);
5628 final ParcelUuid groupUuid = info.getGroupUuid();
5629 // If it doesn't belong to any group, return just subscriberId of itself.
5630 if (groupUuid == null) {
5631 return new String[]{subscriberId};
5632 }
5633
5634 // Get all subscriberIds from the group.
5635 final List<String> mergedSubscriberIds = new ArrayList<>();
5636 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005637 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5638 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07005639 for (SubscriptionInfo subInfo : groupInfos) {
5640 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5641 if (subscriberId != null) {
5642 mergedSubscriberIds.add(subscriberId);
5643 }
5644 }
5645
5646 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5647 } finally {
5648 Binder.restoreCallingIdentity(identity);
5649
5650 }
5651 }
5652
5653 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005654 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08005655 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005656 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005657
5658 final long identity = Binder.clearCallingIdentity();
5659 try {
5660 final Phone phone = getPhone(subId);
5661 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5662 } finally {
5663 Binder.restoreCallingIdentity(identity);
5664 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005665 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005666
5667 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005668 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005669 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5670 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08005671 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5672 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005673
5674 final long identity = Binder.clearCallingIdentity();
5675 try {
5676 final Phone phone = getPhone(subId);
5677 if (phone == null) {
5678 return false;
5679 }
5680 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5681 cdmaNonRoamingList);
5682 } finally {
5683 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005684 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005685 }
5686
5687 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005688 @Deprecated
5689 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5690 enforceModifyPermission();
5691
5692 int returnValue = 0;
5693 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005694 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005695 if(result.exception == null) {
5696 if (result.result != null) {
5697 byte[] responseData = (byte[])(result.result);
5698 if(responseData.length > oemResp.length) {
5699 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5700 responseData.length + "bytes. Buffer Size is " +
5701 oemResp.length + "bytes.");
5702 }
5703 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5704 returnValue = responseData.length;
5705 }
5706 } else {
5707 CommandException ex = (CommandException) result.exception;
5708 returnValue = ex.getCommandError().ordinal();
5709 if(returnValue > 0) returnValue *= -1;
5710 }
5711 } catch (RuntimeException e) {
5712 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5713 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5714 if(returnValue > 0) returnValue *= -1;
5715 }
5716
5717 return returnValue;
5718 }
5719
5720 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005721 public void setRadioCapability(RadioAccessFamily[] rafs) {
5722 try {
5723 ProxyController.getInstance().setRadioCapability(rafs);
5724 } catch (RuntimeException e) {
5725 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5726 }
5727 }
5728
5729 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005730 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005731 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005732 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005733 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005734 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005735 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005736 final long identity = Binder.clearCallingIdentity();
5737 try {
chen xub97461a2018-10-26 14:17:57 -07005738 TelephonyPermissions
5739 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5740 mApp, phone.getSubId(), "getRadioAccessFamily");
5741 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005742 } finally {
5743 Binder.restoreCallingIdentity(identity);
5744 }
chen xub97461a2018-10-26 14:17:57 -07005745 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005746 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005747
5748 @Override
5749 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005750 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005751 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005752
5753 final long identity = Binder.clearCallingIdentity();
5754 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005755 ImsManager.getInstance(defaultPhone.getContext(),
5756 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005757 } finally {
5758 Binder.restoreCallingIdentity(identity);
5759 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005760 }
5761
5762 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005763 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005764 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005765 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5766 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005767 return false;
5768 }
Svet Ganovb320e182015-04-16 12:30:10 -07005769
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005770 final long identity = Binder.clearCallingIdentity();
5771 try {
5772 // Check the user preference and the system-level IMS setting. Even if the user has
5773 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5774 // In the long run, we may instead need to check if there exists a connection service
5775 // which can support video calling.
5776 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005777 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005778 return imsManager.isVtEnabledByPlatform()
5779 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5780 && imsManager.isVtEnabledByUser();
5781 } finally {
5782 Binder.restoreCallingIdentity(identity);
5783 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005784 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005785
Andrew Leea1239f22015-03-02 17:44:07 -08005786 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005787 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5788 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005789 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005790 mApp, subId, callingPackage, callingFeatureId,
5791 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005792 return false;
5793 }
5794
5795 final long identity = Binder.clearCallingIdentity();
5796 try {
5797 CarrierConfigManager configManager =
5798 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005799 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005800 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5801 } finally {
5802 Binder.restoreCallingIdentity(identity);
5803 }
Andrew Leea1239f22015-03-02 17:44:07 -08005804 }
5805
5806 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005807 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005808 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005809 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005810 return false;
5811 }
5812
5813 final long identity = Binder.clearCallingIdentity();
5814 try {
5815 CarrierConfigManager configManager =
5816 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005817 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005818 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5819 } finally {
5820 Binder.restoreCallingIdentity(identity);
5821 }
Andrew Leea1239f22015-03-02 17:44:07 -08005822 }
5823
Andrew Lee9431b832015-03-09 18:46:45 -07005824 @Override
5825 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07005826 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005827 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005828 }
5829
5830 @Override
5831 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005832 final long identity = Binder.clearCallingIdentity();
5833 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005834 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005835 } finally {
5836 Binder.restoreCallingIdentity(identity);
5837 }
Andrew Lee9431b832015-03-09 18:46:45 -07005838 }
5839
Hall Liuf6668912018-10-31 17:05:23 -07005840 /**
5841 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5842 * support for the feature and device firmware support.
5843 *
5844 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5845 */
5846 @Override
5847 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005848 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005849 final Phone phone = getPhone(subscriptionId);
5850 if (phone == null) {
5851 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5852 return false;
5853 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005854 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005855 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005856 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5857 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005858 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005859 return isCarrierSupported && isDeviceSupported;
5860 } finally {
5861 Binder.restoreCallingIdentity(identity);
5862 }
Hall Liu98187582018-01-22 19:15:32 -08005863 }
5864
Hall Liuf6668912018-10-31 17:05:23 -07005865 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005866 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5867 * RTT setting, will return true if the device and carrier both support RTT.
5868 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005869 */
5870 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005871 final long identity = Binder.clearCallingIdentity();
5872 try {
Hall Liu81eb08c2019-10-29 16:50:20 -07005873 return isRttSupported(subscriptionId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005874 } finally {
5875 Binder.restoreCallingIdentity(identity);
5876 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005877 }
5878
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005879 @Deprecated
5880 @Override
5881 public String getDeviceId(String callingPackage) {
5882 return getDeviceIdWithFeature(callingPackage, null);
5883 }
5884
Sanket Padawe7310cc72015-01-14 09:53:20 -08005885 /**
5886 * Returns the unique device ID of phone, for example, the IMEI for
5887 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5888 *
5889 * <p>Requires Permission:
5890 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5891 */
5892 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005893 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005894 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005895 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005896 return null;
5897 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005898 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005899 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005900 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005901 return null;
5902 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005903
5904 final long identity = Binder.clearCallingIdentity();
5905 try {
5906 return phone.getDeviceId();
5907 } finally {
5908 Binder.restoreCallingIdentity(identity);
5909 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005910 }
5911
Ping Sunc67b7c22016-03-02 19:16:45 +08005912 /**
5913 * {@hide}
5914 * Returns the IMS Registration Status on a particular subid
5915 *
5916 * @param subId
5917 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005918 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005919 Phone phone = getPhone(subId);
5920 if (phone != null) {
5921 return phone.isImsRegistered();
5922 } else {
5923 return false;
5924 }
5925 }
5926
Santos Cordon7a1885b2015-02-03 11:15:19 -08005927 @Override
5928 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005929 final long identity = Binder.clearCallingIdentity();
5930 try {
5931 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5932 } finally {
5933 Binder.restoreCallingIdentity(identity);
5934 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005935 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005936
Tyler Gunnf70ed162019-04-03 15:28:53 -07005937 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07005938 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005939 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07005940 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005941 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07005942 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5943 }
5944 final long identity = Binder.clearCallingIdentity();
5945 try {
5946 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5947 } finally {
5948 Binder.restoreCallingIdentity(identity);
5949 }
5950 }
5951
5952 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005953 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5954 final long identity = Binder.clearCallingIdentity();
5955 try {
5956 Phone phone = getPhone(subscriptionId);
5957 if (phone == null) {
5958 return null;
5959 }
5960 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5961 } finally {
5962 Binder.restoreCallingIdentity(identity);
5963 }
5964 }
5965
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005966 /**
5967 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005968 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005969 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005970 final long identity = Binder.clearCallingIdentity();
5971 try {
5972 Phone phone = getPhone(subId);
5973 if (phone != null) {
5974 return phone.isWifiCallingEnabled();
5975 } else {
5976 return false;
5977 }
5978 } finally {
5979 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005980 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005981 }
5982
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005983 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005984 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005985 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005986 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005987 final long identity = Binder.clearCallingIdentity();
5988 try {
5989 Phone phone = getPhone(subId);
5990 if (phone != null) {
5991 return phone.isVideoEnabled();
5992 } else {
5993 return false;
5994 }
5995 } finally {
5996 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005997 }
5998 }
5999
6000 /**
6001 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6002 * defined in {@link ImsRegistrationImplBase}.
6003 */
6004 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006005 final long identity = Binder.clearCallingIdentity();
6006 try {
6007 Phone phone = getPhone(subId);
6008 if (phone != null) {
6009 return phone.getImsRegistrationTech();
6010 } else {
6011 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6012 }
6013 } finally {
6014 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006015 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006016 }
6017
Stuart Scott8eef64f2015-04-08 15:13:54 -07006018 @Override
6019 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006020 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006021 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6022 return;
6023 }
6024
Svet Ganovcc087f82015-05-12 20:35:54 -07006025 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006026
Svet Ganovcc087f82015-05-12 20:35:54 -07006027 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006028 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6029 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006030 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006031 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006032 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006033 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6034 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006035 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006036 // There has been issues when Sms raw table somehow stores orphan
6037 // fragments. They lead to garbled message when new fragments come
6038 // in and combined with those stale ones. In case this happens again,
6039 // user can reset all network settings which will clean up this table.
6040 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006041 // Clean up IMS settings as well here.
6042 int slotId = getSlotIndex(subId);
6043 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6044 ImsManager.getInstance(mApp, slotId).factoryReset();
6045 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006046
6047 // Erase modem config if erase modem on network setting is enabled.
6048 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6049 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6050 if (configValue != null && Boolean.parseBoolean(configValue)) {
6051 sendEraseModemConfig(getDefaultPhone());
6052 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006053 } finally {
6054 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006055 }
6056 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006057
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006058 private void cleanUpSmsRawTable(Context context) {
6059 ContentResolver resolver = context.getContentResolver();
6060 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6061 resolver.delete(uri, null, null);
6062 }
6063
Narayan Kamath1c496c22015-04-16 14:40:19 +01006064 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006065 public String getSimLocaleForSubscriber(int subId) {
6066 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6067 final Phone phone = getPhone(subId);
6068 if (phone == null) {
6069 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006070 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006071 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006072 final long identity = Binder.clearCallingIdentity();
6073 try {
chen xu5d3637b2019-01-21 23:31:38 -08006074 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006075 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08006076 if (info == null) {
6077 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6078 return null;
6079 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006080 // Try and fetch the locale from the carrier properties or from the SIM language
6081 // preferences (EF-PL and EF-LI)...
6082 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006083 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006084 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6085 if (localeFromDefaultSim != null) {
6086 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6087 if (DBG) log("Using locale from subId: " + subId + " locale: "
6088 + localeFromDefaultSim);
6089 return localeFromDefaultSim.toLanguageTag();
6090 } else {
6091 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006092 }
6093 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006094
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006095 // The SIM language preferences only store a language (e.g. fr = French), not an
6096 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6097 // the SIM and carrier preferences does not include a country we add the country
6098 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006099 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006100 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006101 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006102 return mccLocale.toLanguageTag();
6103 }
6104
6105 if (DBG) log("No locale found - returning null");
6106 return null;
6107 } finally {
6108 Binder.restoreCallingIdentity(identity);
6109 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006110 }
6111
6112 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006113 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6114 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006115 }
6116
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006117 /**
6118 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6119 */
6120 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006121 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6122 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006123 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006124
Chenjie Yu1ba97252018-01-11 18:16:20 -08006125 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006126 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006127
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006128 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006129 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6130 * representing the state of the modem.
6131 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006132 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6133 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006134 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006135 */
6136 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006137 public void requestModemActivityInfo(ResultReceiver result) {
6138 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006139 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006140
6141 final long identity = Binder.clearCallingIdentity();
6142 try {
6143 ModemActivityInfo ret = null;
6144 synchronized (mLastModemActivityInfo) {
6145 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6146 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006147 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006148 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006149 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xu13851032019-09-10 18:49:52 -07006150 int[] txTimeMs = info.getTransmitTimeMillis();
6151 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006152 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xu13851032019-09-10 18:49:52 -07006153 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006154 }
6155 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006156 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6157 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006158 mLastModemActivityInfo.setIdleTimeMillis(
6159 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xu13851032019-09-10 18:49:52 -07006160 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6161 mLastModemActivityInfo.setReceiveTimeMillis(
6162 info.getReceiveTimeMillis() + mLastModemActivityInfo
6163 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006164 }
Chen Xu13851032019-09-10 18:49:52 -07006165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006166 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6167 mLastModemActivityInfo.getSleepTimeMillis(),
6168 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xu13851032019-09-10 18:49:52 -07006169 mLastModemActivityInfo.getTransmitTimeMillis(),
6170 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006171 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006172 Bundle bundle = new Bundle();
6173 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6174 result.send(0, bundle);
6175 } finally {
6176 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006177 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006178 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006179
Siddharth Rayb8114062018-06-17 15:02:38 -07006180 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6181 // less than total activity duration.
6182 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6183 if (info == null) {
6184 return false;
6185 }
6186 int activityDurationMs =
6187 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6188 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006189 int[] txTimeMs = info.getTransmitTimeMillis();
6190 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6191 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006192 }
6193 return (info.isValid()
6194 && (info.getSleepTimeMillis() <= activityDurationMs)
6195 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006196 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006197 && (totalTxTimeMs <= activityDurationMs));
6198 }
6199
Jack Yu85bd38a2015-11-09 11:34:32 -08006200 /**
6201 * {@hide}
6202 * Returns the service state information on specified subscription.
6203 */
6204 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006205 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6206 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006207 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006208 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006209 return null;
6210 }
6211
Hall Liuf19c44f2018-11-27 14:38:17 -08006212 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6213 LocationAccessPolicy.checkLocationPermission(mApp,
6214 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6215 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006216 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006217 .setCallingPid(Binder.getCallingPid())
6218 .setCallingUid(Binder.getCallingUid())
6219 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006220 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006221 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6222 .build());
6223
6224 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6225 LocationAccessPolicy.checkLocationPermission(mApp,
6226 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6227 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006228 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006229 .setCallingPid(Binder.getCallingPid())
6230 .setCallingUid(Binder.getCallingUid())
6231 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006232 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006233 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6234 .build());
6235 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6236 boolean hasFinePermission =
6237 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6238 boolean hasCoarsePermission =
6239 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6240
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006241 final long identity = Binder.clearCallingIdentity();
6242 try {
6243 final Phone phone = getPhone(subId);
6244 if (phone == null) {
6245 return null;
6246 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006247
Hall Liuf19c44f2018-11-27 14:38:17 -08006248 ServiceState ss = phone.getServiceState();
6249
6250 // Scrub out the location info in ServiceState depending on what level of access
6251 // the caller has.
6252 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006253 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6254 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006255 } finally {
6256 Binder.restoreCallingIdentity(identity);
6257 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006258 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006259
6260 /**
6261 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6262 *
6263 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6264 * voicemail ringtone.
6265 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6266 * PhoneAccount.
6267 */
6268 @Override
6269 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006270 final long identity = Binder.clearCallingIdentity();
6271 try {
6272 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6273 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006274 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006275 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006276
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006277 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6278 } finally {
6279 Binder.restoreCallingIdentity(identity);
6280 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006281 }
6282
6283 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006284 * Sets the per-account voicemail ringtone.
6285 *
6286 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6287 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6288 *
6289 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6290 * voicemail ringtone.
6291 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6292 * PhoneAccount.
6293 */
6294 @Override
6295 public void setVoicemailRingtoneUri(String callingPackage,
6296 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006297 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006298 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006299 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6300 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006301 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6302 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6303 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006304 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006305
6306 final long identity = Binder.clearCallingIdentity();
6307 try {
6308 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6309 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006310 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006311 }
6312 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6313 } finally {
6314 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006315 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006316 }
6317
6318 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006319 * Returns whether vibration is set for voicemail notification in Phone settings.
6320 *
6321 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6322 * voicemail vibration setting.
6323 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6324 */
6325 @Override
6326 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006327 final long identity = Binder.clearCallingIdentity();
6328 try {
6329 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6330 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006331 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006333
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006334 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6335 } finally {
6336 Binder.restoreCallingIdentity(identity);
6337 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006338 }
6339
Youhan Wange64578a2016-05-02 15:32:42 -07006340 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006341 * Sets the per-account voicemail vibration.
6342 *
6343 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6344 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6345 *
6346 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6347 * voicemail vibration setting.
6348 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6349 * specific PhoneAccount.
6350 */
6351 @Override
6352 public void setVoicemailVibrationEnabled(String callingPackage,
6353 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006354 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006355 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006356 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6357 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006358 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6359 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6360 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006361 }
6362
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006363 final long identity = Binder.clearCallingIdentity();
6364 try {
6365 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6366 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006367 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006368 }
6369 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6370 } finally {
6371 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006372 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006373 }
6374
6375 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006376 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6377 *
6378 * @throws SecurityException if the caller does not have the required permission
6379 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006380 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006381 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006382 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006383 }
6384
6385 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006386 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6387 * permission.
6388 *
6389 * @throws SecurityException if the caller does not have the required permission
6390 */
6391 private void enforceSendSmsPermission() {
6392 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6393 }
6394
6395 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006396 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006397 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006398 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006399 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006400 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006401 final long identity = Binder.clearCallingIdentity();
6402 try {
6403 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006404 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405 if (componentName == null) {
6406 throw new SecurityException(
6407 "Caller not current active visual voicemail package[null]");
6408 }
6409 String vvmPackage = componentName.getPackageName();
6410 if (!callingPackage.equals(vvmPackage)) {
6411 throw new SecurityException("Caller not current active visual voicemail package["
6412 + vvmPackage + "]");
6413 }
6414 } finally {
6415 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006416 }
6417 }
6418
6419 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006420 * Return the application ID for the app type.
6421 *
6422 * @param subId the subscription ID that this request applies to.
6423 * @param appType the uicc app type.
6424 * @return Application ID for specificied app type, or null if no uicc.
6425 */
6426 @Override
6427 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006428 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006429 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006430
6431 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006432 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006433 if (phone == null) {
6434 return null;
6435 }
6436 String aid = null;
6437 try {
6438 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6439 .getApplicationByType(appType).getAid();
6440 } catch (Exception e) {
6441 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6442 }
6443 return aid;
6444 } finally {
6445 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006446 }
Youhan Wange64578a2016-05-02 15:32:42 -07006447 }
6448
Youhan Wang4001d252016-05-11 10:29:41 -07006449 /**
6450 * Return the Electronic Serial Number.
6451 *
6452 * @param subId the subscription ID that this request applies to.
6453 * @return ESN or null if error.
6454 */
6455 @Override
6456 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006457 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006458 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006459
6460 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006461 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006462 if (phone == null) {
6463 return null;
6464 }
6465 String esn = null;
6466 try {
6467 esn = phone.getEsn();
6468 } catch (Exception e) {
6469 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6470 }
6471 return esn;
6472 } finally {
6473 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006474 }
Youhan Wang4001d252016-05-11 10:29:41 -07006475 }
6476
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006477 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006478 * Return the Preferred Roaming List Version.
6479 *
6480 * @param subId the subscription ID that this request applies to.
6481 * @return PRLVersion or null if error.
6482 */
6483 @Override
6484 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006485 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006486 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006487
6488 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006489 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006490 if (phone == null) {
6491 return null;
6492 }
6493 String cdmaPrlVersion = null;
6494 try {
6495 cdmaPrlVersion = phone.getCdmaPrlVersion();
6496 } catch (Exception e) {
6497 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6498 }
6499 return cdmaPrlVersion;
6500 } finally {
6501 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006502 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006503 }
6504
6505 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006506 * Get snapshot of Telephony histograms
6507 * @return List of Telephony histograms
6508 * @hide
6509 */
6510 @Override
6511 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006512 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6513 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006514
6515 final long identity = Binder.clearCallingIdentity();
6516 try {
6517 return RIL.getTelephonyRILTimingHistograms();
6518 } finally {
6519 Binder.restoreCallingIdentity(identity);
6520 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006521 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006522
6523 /**
6524 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006525 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6526 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006527 * Require system privileges. In the future we may add this to carrier APIs.
6528 *
Michele Berionne482f8202018-11-27 18:57:59 -08006529 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006530 */
6531 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006532 @TelephonyManager.SetCarrierRestrictionResult
6533 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006534 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006535 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006536
Michele Berionne482f8202018-11-27 18:57:59 -08006537 if (carrierRestrictionRules == null) {
6538 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006539 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006540
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006541 final long identity = Binder.clearCallingIdentity();
6542 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006543 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006544 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006545 } finally {
6546 Binder.restoreCallingIdentity(identity);
6547 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006548 }
6549
6550 /**
6551 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006552 * Get the allowed carrier list and the excluded carrier list, including the priority between
6553 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006554 * Require system privileges. In the future we may add this to carrier APIs.
6555 *
Michele Berionne482f8202018-11-27 18:57:59 -08006556 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006557 */
6558 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006559 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006560 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006561 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006562
6563 final long identity = Binder.clearCallingIdentity();
6564 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006565 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6566 if (response instanceof CarrierRestrictionRules) {
6567 return (CarrierRestrictionRules) response;
6568 }
6569 // Response is an Exception of some kind,
6570 // which is signalled to the user as a NULL retval
6571 return null;
6572 } catch (Exception e) {
6573 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6574 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006575 } finally {
6576 Binder.restoreCallingIdentity(identity);
6577 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006578 }
6579
fionaxu59545b42016-05-25 15:53:37 -07006580 /**
6581 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6582 * @param subId the subscription ID that this action applies to.
6583 * @param enabled control enable or disable metered apns.
6584 * {@hide}
6585 */
6586 @Override
6587 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6588 enforceModifyPermission();
6589 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006590
6591 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006592 if (phone == null) {
6593 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6594 return;
6595 }
6596 try {
6597 phone.carrierActionSetMeteredApnsEnabled(enabled);
6598 } catch (Exception e) {
6599 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006600 } finally {
6601 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006602 }
6603 }
6604
6605 /**
6606 * Action set from carrier signalling broadcast receivers to enable/disable radio
6607 * @param subId the subscription ID that this action applies to.
6608 * @param enabled control enable or disable radio.
6609 * {@hide}
6610 */
6611 @Override
6612 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6613 enforceModifyPermission();
6614 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006615
6616 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006617 if (phone == null) {
6618 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6619 return;
6620 }
6621 try {
6622 phone.carrierActionSetRadioEnabled(enabled);
6623 } catch (Exception e) {
6624 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006625 } finally {
6626 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006627 }
6628 }
6629
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006630 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006631 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6632 * network status based on which carrier apps could apply actions accordingly,
6633 * enable/disable default url handler for example.
6634 *
6635 * @param subId the subscription ID that this action applies to.
6636 * @param report control start/stop reporting the default network status.
6637 * {@hide}
6638 */
6639 @Override
6640 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6641 enforceModifyPermission();
6642 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006643
6644 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006645 if (phone == null) {
6646 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6647 return;
6648 }
6649 try {
6650 phone.carrierActionReportDefaultNetworkStatus(report);
6651 } catch (Exception e) {
6652 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006653 } finally {
6654 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006655 }
6656 }
6657
6658 /**
fionaxud9622282017-07-17 17:51:30 -07006659 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6660 * @param subId the subscription ID that this action applies to.
6661 * {@hide}
6662 */
6663 @Override
6664 public void carrierActionResetAll(int subId) {
6665 enforceModifyPermission();
6666 final Phone phone = getPhone(subId);
6667 if (phone == null) {
6668 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6669 return;
6670 }
6671 try {
6672 phone.carrierActionResetAll();
6673 } catch (Exception e) {
6674 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6675 }
6676 }
6677
6678 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006679 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6680 * bug report is being generated.
6681 */
6682 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006683 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006684 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6685 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006686 writer.println("Permission Denial: can't dump Phone from pid="
6687 + Binder.getCallingPid()
6688 + ", uid=" + Binder.getCallingUid()
6689 + "without permission "
6690 + android.Manifest.permission.DUMP);
6691 return;
6692 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006693 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006694 }
Jack Yueb89b242016-06-22 13:27:47 -07006695
Brad Ebingerdac2f002018-04-03 15:17:52 -07006696 @Override
6697 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6698 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6699 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006700 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6701 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006702 }
6703
Jack Yueb89b242016-06-22 13:27:47 -07006704 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006705 * Get aggregated video call data usage since boot.
6706 *
6707 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6708 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006709 * {@hide}
6710 */
6711 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006712 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006713 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6714 null);
6715
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006716 final long identity = Binder.clearCallingIdentity();
6717 try {
6718 // NetworkStatsService keeps tracking the active network interface and identity. It
6719 // records the delta with the corresponding network identity.
6720 // We just return the total video call data usage snapshot since boot.
6721 Phone phone = getPhone(subId);
6722 if (phone != null) {
6723 return phone.getVtDataUsage(perUidStats);
6724 }
6725 return null;
6726 } finally {
6727 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006728 }
Jack Yueb89b242016-06-22 13:27:47 -07006729 }
Jack Yu75ab2952016-07-08 14:29:33 -07006730
6731 /**
6732 * Policy control of data connection. Usually used when data limit is passed.
6733 * @param enabled True if enabling the data, otherwise disabling.
6734 * @param subId Subscription index
6735 * {@hide}
6736 */
6737 @Override
6738 public void setPolicyDataEnabled(boolean enabled, int subId) {
6739 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006740
6741 final long identity = Binder.clearCallingIdentity();
6742 try {
6743 Phone phone = getPhone(subId);
6744 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006745 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006746 }
6747 } finally {
6748 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006749 }
6750 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006751
6752 /**
6753 * Get Client request stats
6754 * @return List of Client Request Stats
6755 * @hide
6756 */
6757 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006758 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6759 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006760 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006761 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006762 return null;
6763 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006764 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006766 final long identity = Binder.clearCallingIdentity();
6767 try {
6768 if (phone != null) {
6769 return phone.getClientRequestStats();
6770 }
6771
6772 return null;
6773 } finally {
6774 Binder.restoreCallingIdentity(identity);
6775 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006776 }
6777
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006778 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006779 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006780 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006781 }
Jack Yueb4124c2017-02-16 15:32:43 -08006782
6783 /**
Grace Chen70990072017-03-24 17:21:30 -07006784 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006785 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006786 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006787 * @param state State of SIM (power down, power up, pass through)
6788 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6789 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6790 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006791 *
6792 **/
6793 @Override
Grace Chen70990072017-03-24 17:21:30 -07006794 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006795 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006796 Phone phone = PhoneFactory.getPhone(slotIndex);
6797
vagdeviaf9a5b92018-08-15 16:01:53 -07006798 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6799
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006800 final long identity = Binder.clearCallingIdentity();
6801 try {
6802 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006803 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006804 }
6805 } finally {
6806 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006807 }
6808 }
Shuo Qiandd210312017-04-12 22:11:33 +00006809
Tyler Gunn65d45c22017-06-05 11:22:26 -07006810 private boolean isUssdApiAllowed(int subId) {
6811 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006812 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006813 if (configManager == null) {
6814 return false;
6815 }
6816 PersistableBundle pb = configManager.getConfigForSubId(subId);
6817 if (pb == null) {
6818 return false;
6819 }
6820 return pb.getBoolean(
6821 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6822 }
6823
Shuo Qiandd210312017-04-12 22:11:33 +00006824 /**
6825 * Check if phone is in emergency callback mode
6826 * @return true if phone is in emergency callback mode
6827 * @param subId sub id
6828 */
goneil9c5f4872017-12-05 14:07:56 -08006829 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006830 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006831 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006832 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006833
6834 final long identity = Binder.clearCallingIdentity();
6835 try {
6836 if (phone != null) {
6837 return phone.isInEcm();
6838 } else {
6839 return false;
6840 }
6841 } finally {
6842 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006843 }
6844 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006845
6846 /**
6847 * Get the current signal strength information for the given subscription.
6848 * Because this information is not updated when the device is in a low power state
6849 * it should not be relied-upon to be current.
6850 * @param subId Subscription index
6851 * @return the most recent cached signal strength info from the modem
6852 */
6853 @Override
6854 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006855 final long identity = Binder.clearCallingIdentity();
6856 try {
6857 Phone p = getPhone(subId);
6858 if (p == null) {
6859 return null;
6860 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006861
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006862 return p.getSignalStrength();
6863 } finally {
6864 Binder.restoreCallingIdentity(identity);
6865 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006866 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006867
Pengquan Meng77b7f132018-08-22 14:49:57 -07006868 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006869 * Get the current modem radio state for the given slot.
6870 * @param slotIndex slot index.
6871 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006872 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00006873 * @return the current radio power state from the modem
6874 */
6875 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006876 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00006877 Phone phone = PhoneFactory.getPhone(slotIndex);
6878 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006879 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
6880 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00006881 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6882 }
6883
6884 final long identity = Binder.clearCallingIdentity();
6885 try {
6886 return phone.getRadioPowerState();
6887 } finally {
6888 Binder.restoreCallingIdentity(identity);
6889 }
6890 }
6891 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6892 }
6893
6894 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006895 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6896 *
6897 * <p>Requires one of the following permissions:
6898 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6899 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6900 * privileges.
6901 *
6902 * @param subId subscription id
6903 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6904 * {@code false}.
6905 */
6906 @Override
6907 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006908 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6909 null /* message */);
6910
Pengquan Menga1bb6272018-09-06 09:59:22 -07006911 boolean isEnabled = false;
6912 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006913 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006914 Phone phone = getPhone(subId);
6915 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006916 } catch (Exception e) {
6917 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6918 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006919 } finally {
6920 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006921 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006922 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006923 }
6924
6925
6926 /**
6927 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6928 *
6929 * <p> Requires permission:
6930 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6931 * privileges.
6932 *
6933 * @param subId subscription id
6934 * @param isEnabled {@code true} means enable, {@code false} means disable.
6935 */
6936 @Override
6937 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006938 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6939 mApp, subId, "setDataRoamingEnabled");
6940
Pengquan Menga1bb6272018-09-06 09:59:22 -07006941 final long identity = Binder.clearCallingIdentity();
6942 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006943 Phone phone = getPhone(subId);
6944 if (phone != null) {
6945 phone.setDataRoamingEnabled(isEnabled);
6946 }
6947 } finally {
6948 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006949 }
6950 }
6951
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006952 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006953 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08006954 TelephonyPermissions
6955 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07006956 mApp, subId, "isManualNetworkSelectionAllowed");
6957
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006958 boolean isAllowed = true;
6959 final long identity = Binder.clearCallingIdentity();
6960 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006961 Phone phone = getPhone(subId);
6962 if (phone != null) {
6963 isAllowed = phone.isCspPlmnEnabled();
6964 }
6965 } finally {
6966 Binder.restoreCallingIdentity(identity);
6967 }
6968 return isAllowed;
6969 }
6970
6971 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006972 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006973 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006974 try {
6975 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006976 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006977 } catch (SecurityException e) {
6978 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6979 // has carrier privileges on an active UICC
6980 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6981 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006982 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006983 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006984 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006985
6986 final long identity = Binder.clearCallingIdentity();
6987 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006988 UiccController uiccController = UiccController.getInstance();
6989 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006990 if (hasReadPermission) {
6991 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006992 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006993
6994 // Remove private info if the caller doesn't have access
6995 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6996 for (UiccCardInfo cardInfo : cardInfos) {
6997 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6998 // is available
6999 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7000 if (card == null || card.getUiccProfile() == null) {
7001 // assume no access if the card or profile is unavailable
7002 filteredInfos.add(cardInfo.getUnprivileged());
7003 continue;
7004 }
7005 UiccProfile profile = card.getUiccProfile();
7006 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7007 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7008 filteredInfos.add(cardInfo);
7009 } else {
7010 filteredInfos.add(cardInfo.getUnprivileged());
7011 }
7012 }
7013 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007014 } finally {
7015 Binder.restoreCallingIdentity(identity);
7016 }
7017 }
7018
7019 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007020 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007021 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007023 final long identity = Binder.clearCallingIdentity();
7024 try {
7025 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7026 if (slots == null) {
7027 Rlog.i(LOG_TAG, "slots is null.");
7028 return null;
7029 }
7030
7031 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7032 for (int i = 0; i < slots.length; i++) {
7033 UiccSlot slot = slots[i];
7034 if (slot == null) {
7035 continue;
7036 }
7037
Jordan Liu7be7e652019-05-06 18:55:02 +00007038 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007039 UiccCard card = slot.getUiccCard();
7040 if (card != null) {
7041 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007042 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007043 cardId = slot.getEid();
7044 if (TextUtils.isEmpty(cardId)) {
7045 cardId = slot.getIccId();
7046 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007047 }
7048
Jordan Liu857451f2019-05-09 16:35:35 -07007049 if (cardId != null) {
7050 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7051 // if cardId is an EID, it's all digits so this is fine
7052 cardId = IccUtils.stripTrailingFs(cardId);
7053 }
7054
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007055 int cardState = 0;
7056 switch (slot.getCardState()) {
7057 case CARDSTATE_ABSENT:
7058 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7059 break;
7060 case CARDSTATE_PRESENT:
7061 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7062 break;
7063 case CARDSTATE_ERROR:
7064 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7065 break;
7066 case CARDSTATE_RESTRICTED:
7067 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7068 break;
7069 default:
7070 break;
7071
7072 }
7073
7074 infos[i] = new UiccSlotInfo(
7075 slot.isActive(),
7076 slot.isEuicc(),
7077 cardId,
7078 cardState,
7079 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007080 slot.isExtendedApduSupported(),
7081 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007082 }
7083 return infos;
7084 } finally {
7085 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007086 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007087 }
7088
7089 @Override
7090 public boolean switchSlots(int[] physicalSlots) {
7091 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007092
7093 final long identity = Binder.clearCallingIdentity();
7094 try {
7095 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7096 } finally {
7097 Binder.restoreCallingIdentity(identity);
7098 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007099 }
Jack Yu4c988042018-02-27 15:30:01 -08007100
7101 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007102 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007103 final long identity = Binder.clearCallingIdentity();
7104 try {
7105 return UiccController.getInstance().getCardIdForDefaultEuicc();
7106 } finally {
7107 Binder.restoreCallingIdentity(identity);
7108 }
7109 }
7110
7111 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007112 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7113 enforceModifyPermission();
7114 final Phone phone = getPhone(subId);
7115 if (phone == null) {
7116 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7117 return;
7118 }
7119
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007120 final long identity = Binder.clearCallingIdentity();
7121 try {
7122 phone.setRadioIndicationUpdateMode(filters, mode);
7123 } finally {
7124 Binder.restoreCallingIdentity(identity);
7125 }
Jack Yu4c988042018-02-27 15:30:01 -08007126 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007127
7128 /**
goneil47ffb6e2018-04-06 15:40:58 -07007129 * A test API to reload the UICC profile.
7130 *
7131 * <p>Requires that the calling app has permission
7132 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7133 * @hide
7134 */
7135 @Override
7136 public void refreshUiccProfile(int subId) {
7137 enforceModifyPermission();
7138
7139 final long identity = Binder.clearCallingIdentity();
7140 try {
7141 Phone phone = getPhone(subId);
7142 if (phone == null) {
7143 return;
7144 }
7145 UiccCard uiccCard = phone.getUiccCard();
7146 if (uiccCard == null) {
7147 return;
7148 }
7149 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7150 if (uiccProfile == null) {
7151 return;
7152 }
7153 uiccProfile.refresh();
7154 } finally {
7155 Binder.restoreCallingIdentity(identity);
7156 }
7157 }
7158
7159 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007160 * Returns false if the mobile data is disabled by default, otherwise return true.
7161 */
7162 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007163 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007164 }
7165
7166 /**
7167 * Returns true if the data roaming is enabled by default, i.e the system property
7168 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7169 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7170 */
7171 private boolean getDefaultDataRoamingEnabled(int subId) {
7172 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007173 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007174 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007175 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7176 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7177 return isDataRoamingEnabled;
7178 }
7179
7180 /**
7181 * Returns the default network type for the given {@code subId}, if the default network type is
7182 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7183 */
7184 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007185 List<Integer> list = TelephonyProperties.default_network();
7186 int phoneId = mSubscriptionController.getPhoneId(subId);
7187 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7188 return list.get(phoneId);
7189 }
7190 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007191 }
fionaxua13278b2018-03-21 00:08:13 -07007192
7193 @Override
7194 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007195 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007196 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007197
7198 final long identity = Binder.clearCallingIdentity();
7199 try {
7200 final Phone phone = getPhone(subId);
7201 if (phone == null) {
7202 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7203 return;
7204 }
chen xueaba88a2019-03-15 13:15:10 -07007205 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7206 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007207 } finally {
7208 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007209 }
fionaxua13278b2018-03-21 00:08:13 -07007210 }
7211
7212 @Override
7213 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007214 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007215
7216 final long identity = Binder.clearCallingIdentity();
7217 try {
7218 final Phone phone = getPhone(subId);
7219 if (phone == null) {
7220 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7221 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7222 }
7223 return phone.getCarrierIdListVersion();
7224 } finally {
7225 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007226 }
fionaxua13278b2018-03-21 00:08:13 -07007227 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007228
7229 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007230 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7231 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007232 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007233 mApp, subId, callingPackage, callingFeatureId,
7234 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007235 return -1;
7236 }
7237
7238 final long identity = Binder.clearCallingIdentity();
7239 try {
7240 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7241 } finally {
7242 Binder.restoreCallingIdentity(identity);
7243 }
7244 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007245
7246 @Override
7247 public int getCdmaRoamingMode(int subId) {
7248 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7249 mApp, subId, "getCdmaRoamingMode");
7250
7251 final long identity = Binder.clearCallingIdentity();
7252 try {
7253 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7254 } finally {
7255 Binder.restoreCallingIdentity(identity);
7256 }
7257 }
7258
7259 @Override
7260 public boolean setCdmaRoamingMode(int subId, int mode) {
7261 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7262 mApp, subId, "setCdmaRoamingMode");
7263
7264 final long identity = Binder.clearCallingIdentity();
7265 try {
7266 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7267 } finally {
7268 Binder.restoreCallingIdentity(identity);
7269 }
7270 }
7271
7272 @Override
7273 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7274 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7275 mApp, subId, "setCdmaSubscriptionMode");
7276
7277 final long identity = Binder.clearCallingIdentity();
7278 try {
7279 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7280 } finally {
7281 Binder.restoreCallingIdentity(identity);
7282 }
7283 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007284
sqianc5eccab2018-10-19 18:46:41 -07007285 @Override
sqian8c685422019-02-22 15:55:18 -08007286 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007287 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007288 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007289 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7290 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007291 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7292 }
7293 final long identity = Binder.clearCallingIdentity();
7294 try {
sqian854d44b2018-12-12 16:48:18 -08007295 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7296 for (Phone phone: PhoneFactory.getPhones()) {
7297 if (phone.getEmergencyNumberTracker() != null
7298 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7299 emergencyNumberListInternal.put(
7300 phone.getSubId(),
7301 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7302 }
sqian11b7a0e2018-12-05 18:48:28 -08007303 }
sqian854d44b2018-12-12 16:48:18 -08007304 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007305 } finally {
7306 Binder.restoreCallingIdentity(identity);
7307 }
sqianc5eccab2018-10-19 18:46:41 -07007308 }
7309
7310 @Override
sqian8c685422019-02-22 15:55:18 -08007311 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007312 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007313 if (!exactMatch) {
7314 TelephonyPermissions
7315 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007316 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007317 }
7318 final long identity = Binder.clearCallingIdentity();
7319 try {
sqian854d44b2018-12-12 16:48:18 -08007320 for (Phone phone: PhoneFactory.getPhones()) {
7321 if (phone.getEmergencyNumberTracker() != null
7322 && phone.getEmergencyNumberTracker() != null) {
7323 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7324 number, exactMatch)) {
7325 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007326 }
7327 }
sqian11b7a0e2018-12-05 18:48:28 -08007328 }
7329 return false;
7330 } finally {
7331 Binder.restoreCallingIdentity(identity);
7332 }
7333 }
7334
sqianf4ca7ed2019-01-15 18:32:07 -08007335 /**
7336 * Update emergency number list for test mode.
7337 */
7338 @Override
7339 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7340 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7341 "updateEmergencyNumberListTestMode");
7342
7343 final long identity = Binder.clearCallingIdentity();
7344 try {
7345 for (Phone phone: PhoneFactory.getPhones()) {
7346 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7347 if (tracker != null) {
7348 tracker.executeEmergencyNumberTestModeCommand(action, num);
7349 }
7350 }
7351 } finally {
7352 Binder.restoreCallingIdentity(identity);
7353 }
7354 }
7355
7356 /**
7357 * Get the full emergency number list for test mode.
7358 */
7359 @Override
7360 public List<String> getEmergencyNumberListTestMode() {
7361 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7362 "getEmergencyNumberListTestMode");
7363
7364 final long identity = Binder.clearCallingIdentity();
7365 try {
7366 Set<String> emergencyNumbers = new HashSet<>();
7367 for (Phone phone: PhoneFactory.getPhones()) {
7368 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7369 if (tracker != null) {
7370 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7371 emergencyNumbers.add(num.getNumber());
7372 }
7373 }
7374 }
7375 return new ArrayList<>(emergencyNumbers);
7376 } finally {
7377 Binder.restoreCallingIdentity(identity);
7378 }
7379 }
7380
chen xud6b45bd2018-10-30 22:27:10 -07007381 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007382 public int getEmergencyNumberDbVersion(int subId) {
7383 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7384
7385 final long identity = Binder.clearCallingIdentity();
7386 try {
7387 final Phone phone = getPhone(subId);
7388 if (phone == null) {
7389 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7390 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7391 }
7392 return phone.getEmergencyNumberDbVersion();
7393 } finally {
7394 Binder.restoreCallingIdentity(identity);
7395 }
7396 }
7397
7398 @Override
7399 public void notifyOtaEmergencyNumberDbInstalled() {
7400 enforceModifyPermission();
7401
7402 final long identity = Binder.clearCallingIdentity();
7403 try {
7404 for (Phone phone: PhoneFactory.getPhones()) {
7405 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7406 if (tracker != null) {
7407 tracker.updateOtaEmergencyNumberDatabase();
7408 }
7409 }
7410 } finally {
7411 Binder.restoreCallingIdentity(identity);
7412 }
7413 }
7414
7415 @Override
7416 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7417 enforceActiveEmergencySessionPermission();
7418
7419 final long identity = Binder.clearCallingIdentity();
7420 try {
7421 for (Phone phone: PhoneFactory.getPhones()) {
7422 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7423 if (tracker != null) {
7424 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7425 }
7426 }
7427 } finally {
7428 Binder.restoreCallingIdentity(identity);
7429 }
7430 }
7431
7432 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007433 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7434 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7435 Phone phone = getPhone(subId);
7436 if (phone == null) {
7437 return null;
7438 }
7439 final long identity = Binder.clearCallingIdentity();
7440 try {
7441 UiccProfile profile = UiccController.getInstance()
7442 .getUiccProfileForPhone(phone.getPhoneId());
7443 if (profile != null) {
7444 return profile.getCertsFromCarrierPrivilegeAccessRules();
7445 }
7446 } finally {
7447 Binder.restoreCallingIdentity(identity);
7448 }
7449 return null;
7450 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007451
7452 /**
7453 * Enable or disable a modem stack.
7454 */
7455 @Override
7456 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7457 enforceModifyPermission();
7458
7459 final long identity = Binder.clearCallingIdentity();
7460 try {
7461 Phone phone = PhoneFactory.getPhone(slotIndex);
7462 if (phone == null) {
7463 return false;
7464 } else {
7465 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7466 }
7467 } finally {
7468 Binder.restoreCallingIdentity(identity);
7469 }
7470 }
Michelecea4cf22018-12-21 15:00:11 -08007471
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007472 /**
7473 * Whether a modem stack is enabled or not.
7474 */
7475 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007476 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7477 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007478 Phone phone = PhoneFactory.getPhone(slotIndex);
7479 if (phone == null) return false;
7480
7481 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007482 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7483 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007484 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7485 }
7486
7487 final long identity = Binder.clearCallingIdentity();
7488 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007489 try {
7490 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7491 } catch (NoSuchElementException ex) {
7492 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7493 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007494 } finally {
7495 Binder.restoreCallingIdentity(identity);
7496 }
7497 }
7498
Michelecea4cf22018-12-21 15:00:11 -08007499 @Override
Michele0ea7d782019-03-19 14:58:42 -07007500 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007501 enforceModifyPermission();
7502
7503 final long identity = Binder.clearCallingIdentity();
7504 try {
7505 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007506 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007507 .commit();
7508 } finally {
7509 Binder.restoreCallingIdentity(identity);
7510 }
7511 }
7512
7513 @Override
Michele0ea7d782019-03-19 14:58:42 -07007514 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007515 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007516 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007517 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7518 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007519 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007520 }
Michelecea4cf22018-12-21 15:00:11 -08007521
7522 final long identity = Binder.clearCallingIdentity();
7523 try {
Michele0ea7d782019-03-19 14:58:42 -07007524 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007525 } finally {
7526 Binder.restoreCallingIdentity(identity);
7527 }
7528 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007529
Michele0ea7d782019-03-19 14:58:42 -07007530 @TelephonyManager.IsMultiSimSupportedResult
7531 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007532 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7533 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7534 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007535 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7536 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007537 }
7538 // Check if the hardware supports multisim functionality. If usage of multisim is not
7539 // supported by the modem, indicate that it is restricted.
7540 PhoneCapability staticCapability =
7541 mPhoneConfigurationManager.getStaticPhoneCapability();
7542 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007543 loge("isMultiSimSupportedInternal: no static configuration available");
7544 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007545 }
7546 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007547 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7548 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007549 }
7550 // Check if support of multiple SIMs is restricted by carrier
7551 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007552 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007553 }
7554
Michele0ea7d782019-03-19 14:58:42 -07007555 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007556 }
7557
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007558 /**
7559 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007560 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7561 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7562 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007563 * @param numOfSims number of active sims we want to switch to
7564 */
7565 @Override
7566 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007567 if (numOfSims == 1) {
7568 enforceModifyPermission();
7569 } else {
7570 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7571 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7572 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007573 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007574
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007575 try {
Michele30b57b22019-03-01 12:01:14 -08007576 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007577 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007578 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7579 return;
7580 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007581 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7582 } finally {
7583 Binder.restoreCallingIdentity(identity);
7584 }
7585 }
7586
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007587 @Override
7588 public boolean isApplicationOnUicc(int subId, int appType) {
7589 enforceReadPrivilegedPermission("isApplicationOnUicc");
7590 Phone phone = getPhone(subId);
7591 if (phone == null) {
7592 return false;
7593 }
7594 final long identity = Binder.clearCallingIdentity();
7595 try {
7596 UiccCard uiccCard = phone.getUiccCard();
7597 if (uiccCard == null) {
7598 return false;
7599 }
7600 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7601 if (uiccProfile == null) {
7602 return false;
7603 }
7604 if (TelephonyManager.APPTYPE_SIM <= appType
7605 && appType <= TelephonyManager.APPTYPE_ISIM) {
7606 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7607 }
7608 return false;
7609 } finally {
7610 Binder.restoreCallingIdentity(identity);
7611 }
7612 }
7613
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007614 /**
chen xub4baa772019-04-03 10:23:41 -07007615 * Get whether making changes to modem configurations will trigger reboot.
7616 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007617 */
7618 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007619 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7620 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007621 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007622 mApp, subId, callingPackage, callingFeatureId,
7623 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007624 return false;
7625 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007626 final long identity = Binder.clearCallingIdentity();
7627 try {
7628 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7629 } finally {
7630 Binder.restoreCallingIdentity(identity);
7631 }
7632 }
7633
Nathan Harold29f5f052019-02-15 13:41:57 -08007634 private void updateModemStateMetrics() {
7635 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7636 // TODO: check the state for each modem if the api is ready.
7637 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7638 }
7639
Pengquan Meng3889a572019-01-23 11:16:29 -08007640 @Override
7641 public int[] getSlotsMapping() {
7642 enforceReadPrivilegedPermission("getSlotsMapping");
7643
7644 final long identity = Binder.clearCallingIdentity();
7645 try {
7646 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7647 // All logical slots should have a mapping to a physical slot.
7648 int[] logicalSlotsMapping = new int[phoneCount];
7649 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7650 for (int i = 0; i < slotInfos.length; i++) {
7651 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7652 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7653 }
7654 }
7655 return logicalSlotsMapping;
7656 } finally {
7657 Binder.restoreCallingIdentity(identity);
7658 }
7659 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007660
7661 /**
7662 * Get the IRadio HAL Version
7663 */
7664 @Override
7665 public int getRadioHalVersion() {
7666 Phone phone = getDefaultPhone();
7667 if (phone == null) return -1;
7668 HalVersion hv = phone.getHalVersion();
7669 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7670 return hv.major * 100 + hv.minor;
7671 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007672
7673 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007674 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7675 * corresponding network requests on a subId.
7676 *
7677 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007678 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007679 * 2) APN is un-metered for this subscription, or
7680 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7681 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7682 *
7683 * @return whether data is allowed for a apn type.
7684 *
7685 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007686 */
7687 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007688 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07007689 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7690 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007691
7692 // Now that all security checks passes, perform the operation as ourselves.
7693 final long identity = Binder.clearCallingIdentity();
7694 try {
7695 Phone phone = getPhone(subId);
7696 if (phone == null) return false;
7697
Jack Yu41407ee2019-05-13 16:54:09 -07007698 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007699 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7700 } finally {
7701 Binder.restoreCallingIdentity(identity);
7702 }
7703 }
7704
7705 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007706 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007707 enforceReadPrivilegedPermission("isApnMetered");
7708
7709 // Now that all security checks passes, perform the operation as ourselves.
7710 final long identity = Binder.clearCallingIdentity();
7711 try {
7712 Phone phone = getPhone(subId);
7713 if (phone == null) return true; // By default return true.
7714
Jack Yu41407ee2019-05-13 16:54:09 -07007715 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007716 } finally {
7717 Binder.restoreCallingIdentity(identity);
7718 }
7719 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007720
7721 @Override
changbetty363e8ac2019-12-06 18:16:37 +08007722 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
7723 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
7724 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
7725 if (iccRecords == null) {
7726 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
7727 return false;
7728 }
7729 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
7730 }
7731
7732 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07007733 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7734 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7735 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7736 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7737 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7738 }
7739 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7740 Intent intent = new Intent();
7741 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7742 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7743 // Bring up choose default SMS subscription dialog right now
7744 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7745 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7746 mApp.startActivity(intent);
7747 }
chen xud5ca2d52019-05-28 15:20:57 -07007748
7749 @Override
7750 public String getMmsUAProfUrl(int subId) {
7751 //TODO investigate if this API should require proper permission check in R b/133791609
7752 final long identity = Binder.clearCallingIdentity();
7753 try {
7754 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7755 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7756 } finally {
7757 Binder.restoreCallingIdentity(identity);
7758 }
7759 }
7760
7761 @Override
7762 public String getMmsUserAgent(int subId) {
7763 //TODO investigate if this API should require proper permission check in R b/133791609
7764 final long identity = Binder.clearCallingIdentity();
7765 try {
7766 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7767 .getString(com.android.internal.R.string.config_mms_user_agent);
7768 } finally {
7769 Binder.restoreCallingIdentity(identity);
7770 }
7771 }
Jack Yub07d4972019-05-28 16:12:25 -07007772
7773 @Override
7774 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7775 enforceModifyPermission();
7776
7777 // Now that all security checks passes, perform the operation as ourselves.
7778 final long identity = Binder.clearCallingIdentity();
7779 try {
7780 Phone phone = getPhone(subId);
7781 if (phone == null) return false;
7782
7783 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7784 } finally {
7785 Binder.restoreCallingIdentity(identity);
7786 }
7787 }
7788
7789 @Override
7790 public boolean isDataAllowedInVoiceCall(int subId) {
7791 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7792
7793 // Now that all security checks passes, perform the operation as ourselves.
7794 final long identity = Binder.clearCallingIdentity();
7795 try {
7796 Phone phone = getPhone(subId);
7797 if (phone == null) return false;
7798
7799 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7800 } finally {
7801 Binder.restoreCallingIdentity(identity);
7802 }
7803 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007804
7805 /**
7806 * Updates whether conference event pacakge handling is enabled.
7807 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7808 * otherwise.
7809 */
7810 @Override
7811 public void setCepEnabled(boolean isCepEnabled) {
7812 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7813
7814 final long identity = Binder.clearCallingIdentity();
7815 try {
7816 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7817 for (Phone phone : PhoneFactory.getPhones()) {
7818 Phone defaultPhone = phone.getImsPhone();
7819 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7820 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7821 ImsPhoneCallTracker imsPhoneCallTracker =
7822 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7823 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7824 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7825 + imsPhone.getMsisdn());
7826 }
7827 }
7828 } finally {
7829 Binder.restoreCallingIdentity(identity);
7830 }
7831 }
allenwtsu46dcc572020-01-08 18:24:03 +08007832
7833 /**
7834 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
7835 *
7836 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
7837 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
7838 * before being read.
7839 */
7840 @Override
7841 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
7842 isCompressed) {
7843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7844 mApp, subId, "notifyRcsAutoConfigurationReceived");
7845 try {
7846 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
7847 if (configBinder == null) {
7848 Rlog.e(LOG_TAG, "null result for getImsConfig");
7849 } else {
7850 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
7851 }
7852 } catch (RemoteException e) {
7853 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
7854 }
7855 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007856}