blob: 4ff6e9df6452572c601490230f20f04db11c526c [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
changbetty363e8ac2019-12-06 18:16:37 +080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070038import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.net.Uri;
40import android.os.AsyncResult;
41import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080042import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.os.Bundle;
44import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070045import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.Looper;
47import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070048import android.os.Messenger;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080051import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070052import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070055import android.os.ShellCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070060import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080061import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070062import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090063import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080064import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080065import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070066import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070067import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080071import android.telephony.CellIdentityCdma;
72import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070074import android.telephony.CellInfoGsm;
75import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070076import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070077import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070078import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080079import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070080import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070082import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080083import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080084import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.RadioAccessSpecifier;
Meng Wang17815702020-01-08 18:00:39 -080087import com.android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080089import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080090import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080091import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070092import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080095import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000096import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070097import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebinger774ba362019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsMmTelFeature;
108import android.telephony.ims.aidl.IImsRcsFeature;
109import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700110import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800113import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800114import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800115import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800119import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800120import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800121
Andrew Lee312e8172014-10-23 17:01:36 -0700122import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800123import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700124import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700125import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700126import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800127import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700128import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700129import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800131import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700132import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800133import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800135import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700136import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700137import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700138import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700140import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800141import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700142import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700143import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700144import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700145import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700146import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700147import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700148import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700149import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800150import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800151import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700152import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800153import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700154import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800155import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700156import com.android.internal.telephony.imsphone.ImsPhone;
157import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800158import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900159import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700160import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800161import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700162import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800163import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700164import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800165import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700166import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800167import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000168import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800169import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700170import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800171import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700172import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700173import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800174import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700175import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700176import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800177
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700178import java.io.FileDescriptor;
179import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700180import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800181import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800182import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800183import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800184import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100185import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800186import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700187import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700189
190/**
191 * Implementation of the ITelephony interface.
192 */
Santos Cordon117fee72014-05-16 17:56:12 -0700193public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194 private static final String LOG_TAG = "PhoneInterfaceManager";
195 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
196 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800197 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198
199 // Message codes used with mMainThreadHandler
200 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700201 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
202 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700203 private static final int CMD_OPEN_CHANNEL = 9;
204 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
205 private static final int CMD_CLOSE_CHANNEL = 11;
206 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800207 private static final int CMD_NV_READ_ITEM = 13;
208 private static final int EVENT_NV_READ_ITEM_DONE = 14;
209 private static final int CMD_NV_WRITE_ITEM = 15;
210 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
211 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
212 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700213 private static final int CMD_RESET_MODEM_CONFIG = 19;
214 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800215 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
216 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
217 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
218 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800219 private static final int CMD_SEND_ENVELOPE = 25;
220 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000221 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
222 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700223 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
224 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
225 private static final int CMD_EXCHANGE_SIM_IO = 31;
226 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800227 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
228 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700229 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
230 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700231 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
232 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700233 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
234 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
235 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
236 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700237 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
238 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
239 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
240 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700241 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800242 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
243 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000244 private static final int CMD_SWITCH_SLOTS = 50;
245 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700246 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
247 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
248 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
249 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
250 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
251 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
252 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
253 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700254 private static final int CMD_GET_ALL_CELL_INFO = 60;
255 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
256 private static final int CMD_GET_CELL_LOCATION = 62;
257 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700258 private static final int CMD_MODEM_REBOOT = 64;
259 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700260 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
261 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800262 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
263 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700264 private static final int CMD_GET_MODEM_STATUS = 70;
265 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700266 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
267 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700268 private static final int CMD_ERASE_MODEM_CONFIG = 74;
269 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700270
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800271 // Parameters of select command.
272 private static final int SELECT_COMMAND = 0xA4;
273 private static final int SELECT_P1 = 0x04;
274 private static final int SELECT_P2 = 0;
275 private static final int SELECT_P3 = 0x10;
276
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700277 /** The singleton instance. */
278 private static PhoneInterfaceManager sInstance;
279
Wink Saville3ab207e2014-11-20 13:07:20 -0800280 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800281 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800282 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700283 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800284 private AppOpsManager mAppOps;
285 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800286 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800287 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700288 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700289
Derek Tan97ebb422014-09-05 16:55:38 -0700290 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
291 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800292 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800293 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700294
Michelecea4cf22018-12-21 15:00:11 -0800295 // String to store multi SIM allowed
296 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
297
Derek Tan740e1672017-06-27 14:56:27 -0700298 // The AID of ISD-R.
299 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
300
yinxub1bed742017-04-17 11:45:04 -0700301 private NetworkScanRequestTracker mNetworkScanRequestTracker;
302
David Kelly5e06a7f2018-03-12 14:10:59 +0000303 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
304 private static final int MANUFACTURER_CODE_LENGTH = 8;
305
Derek Tan89e89d42014-07-08 17:00:10 -0700306 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700307 * Experiment flag to enable erase modem config on reset network, default value is false
308 */
309 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
310 "reset_network_erase_modem_config_enabled";
311
312 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700313 * A request object to use for transmitting data to an ICC.
314 */
315 private static final class IccAPDUArgument {
316 public int channel, cla, command, p1, p2, p3;
317 public String data;
318
319 public IccAPDUArgument(int channel, int cla, int command,
320 int p1, int p2, int p3, String data) {
321 this.channel = channel;
322 this.cla = cla;
323 this.command = command;
324 this.p1 = p1;
325 this.p2 = p2;
326 this.p3 = p3;
327 this.data = data;
328 }
329 }
330
331 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700332 * A request object to use for transmitting data to an ICC.
333 */
334 private static final class ManualNetworkSelectionArgument {
335 public OperatorInfo operatorInfo;
336 public boolean persistSelection;
337
338 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
339 this.operatorInfo = operatorInfo;
340 this.persistSelection = persistSelection;
341 }
342 }
343
344 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700345 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
346 * request after sending. The main thread will notify the request when it is complete.
347 */
348 private static final class MainThreadRequest {
349 /** The argument to use for the request */
350 public Object argument;
351 /** The result of the request that is run on the main thread */
352 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800353 // The subscriber id that this request applies to. Defaults to
354 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
355 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356
Nathan Harold92bed182018-10-12 18:16:49 -0700357 // In cases where subId is unavailable, the caller needs to specify the phone.
358 public Phone phone;
359
vagdeviaf9a5b92018-08-15 16:01:53 -0700360 public WorkSource workSource;
361
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362 public MainThreadRequest(Object argument) {
363 this.argument = argument;
364 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800365
Nathan Harold92bed182018-10-12 18:16:49 -0700366 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
367 this.argument = argument;
368 if (phone != null) {
369 this.phone = phone;
370 }
371 this.workSource = workSource;
372 }
373
vagdeviaf9a5b92018-08-15 16:01:53 -0700374 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800375 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800376 if (subId != null) {
377 this.subId = subId;
378 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700379 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800380 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 }
382
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800383 private static final class IncomingThirdPartyCallArgs {
384 public final ComponentName component;
385 public final String callId;
386 public final String callerDisplayName;
387
388 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
389 String callerDisplayName) {
390 this.component = component;
391 this.callId = callId;
392 this.callerDisplayName = callerDisplayName;
393 }
394 }
395
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700396 /**
397 * A handler that processes messages on the main thread in the phone process. Since many
398 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
399 * inbound binder threads to the main thread in the phone process. The Binder thread
400 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
401 * on, which will be notified when the operation completes and will contain the result of the
402 * request.
403 *
404 * <p>If a MainThreadRequest object is provided in the msg.obj field,
405 * note that request.result must be set to something non-null for the calling thread to
406 * unblock.
407 */
408 private final class MainThreadHandler extends Handler {
409 @Override
410 public void handleMessage(Message msg) {
411 MainThreadRequest request;
412 Message onCompleted;
413 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800414 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700415 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800416 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417
418 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700419 case CMD_HANDLE_USSD_REQUEST: {
420 request = (MainThreadRequest) msg.obj;
421 final Phone phone = getPhoneFromRequest(request);
422 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
423 String ussdRequest = ussdObject.first;
424 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700425
Pengquan Menga1bb6272018-09-06 09:59:22 -0700426 if (!isUssdApiAllowed(request.subId)) {
427 // Carrier does not support use of this API, return failure.
428 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
429 UssdResponse response = new UssdResponse(ussdRequest, null);
430 Bundle returnData = new Bundle();
431 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
432 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700433
Pengquan Menga1bb6272018-09-06 09:59:22 -0700434 request.result = true;
435 notifyRequester(request);
436 return;
437 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700438
Pengquan Menga1bb6272018-09-06 09:59:22 -0700439 try {
440 request.result = phone != null
441 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
442 } catch (CallStateException cse) {
443 request.result = false;
444 }
445 // Wake up the requesting thread
446 notifyRequester(request);
447 break;
pkanwar32d516d2016-10-14 19:37:38 -0700448 }
449
Yorke Lee716f67e2015-06-17 15:39:16 -0700450 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700451 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700452 final Phone phone = getPhoneFromRequest(request);
453 request.result = phone != null ?
454 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
455 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700456 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700457 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700458 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700459 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700460
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700461 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700462 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700463 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800464 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700465 if (uiccCard == null) {
466 loge("iccTransmitApduLogicalChannel: No UICC");
467 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700468 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700469 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700470 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
471 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700472 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700473 iccArgument.channel, iccArgument.cla, iccArgument.command,
474 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700475 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700476 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700477 break;
478
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700479 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700480 ar = (AsyncResult) msg.obj;
481 request = (MainThreadRequest) ar.userObj;
482 if (ar.exception == null && ar.result != null) {
483 request.result = ar.result;
484 } else {
485 request.result = new IccIoResult(0x6F, 0, (byte[])null);
486 if (ar.result == null) {
487 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800488 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700489 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800490 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700491 } else {
492 loge("iccTransmitApduLogicalChannel: Unknown exception");
493 }
494 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700495 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700496 break;
497
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
499 request = (MainThreadRequest) msg.obj;
500 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800501 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700502 if (uiccCard == null) {
503 loge("iccTransmitApduBasicChannel: No UICC");
504 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700505 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700506 } else {
507 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
508 request);
509 uiccCard.iccTransmitApduBasicChannel(
510 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
511 iccArgument.p3, iccArgument.data, onCompleted);
512 }
513 break;
514
515 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
516 ar = (AsyncResult) msg.obj;
517 request = (MainThreadRequest) ar.userObj;
518 if (ar.exception == null && ar.result != null) {
519 request.result = ar.result;
520 } else {
521 request.result = new IccIoResult(0x6F, 0, (byte[])null);
522 if (ar.result == null) {
523 loge("iccTransmitApduBasicChannel: Empty response");
524 } else if (ar.exception instanceof CommandException) {
525 loge("iccTransmitApduBasicChannel: CommandException: " +
526 ar.exception);
527 } else {
528 loge("iccTransmitApduBasicChannel: Unknown exception");
529 }
530 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700531 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700532 break;
533
534 case CMD_EXCHANGE_SIM_IO:
535 request = (MainThreadRequest) msg.obj;
536 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800537 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700538 if (uiccCard == null) {
539 loge("iccExchangeSimIO: No UICC");
540 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700541 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700542 } else {
543 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
544 request);
545 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
546 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
547 iccArgument.data, onCompleted);
548 }
549 break;
550
551 case EVENT_EXCHANGE_SIM_IO_DONE:
552 ar = (AsyncResult) msg.obj;
553 request = (MainThreadRequest) ar.userObj;
554 if (ar.exception == null && ar.result != null) {
555 request.result = ar.result;
556 } else {
557 request.result = new IccIoResult(0x6f, 0, (byte[])null);
558 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700559 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700560 break;
561
Derek Tan4d5e5c12014-02-04 11:54:58 -0800562 case CMD_SEND_ENVELOPE:
563 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800564 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700565 if (uiccCard == null) {
566 loge("sendEnvelopeWithStatus: No UICC");
567 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700568 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700569 } else {
570 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
571 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
572 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800573 break;
574
575 case EVENT_SEND_ENVELOPE_DONE:
576 ar = (AsyncResult) msg.obj;
577 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700578 if (ar.exception == null && ar.result != null) {
579 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800580 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700581 request.result = new IccIoResult(0x6F, 0, (byte[])null);
582 if (ar.result == null) {
583 loge("sendEnvelopeWithStatus: Empty response");
584 } else if (ar.exception instanceof CommandException) {
585 loge("sendEnvelopeWithStatus: CommandException: " +
586 ar.exception);
587 } else {
588 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
589 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800590 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700591 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800592 break;
593
Shishir Agrawal566b7612013-10-28 14:41:00 -0700594 case CMD_OPEN_CHANNEL:
595 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800596 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800597 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700598 if (uiccCard == null) {
599 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800600 request.result = new IccOpenLogicalChannelResponse(-1,
601 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700602 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700603 } else {
604 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800605 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
606 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700607 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 break;
609
610 case EVENT_OPEN_CHANNEL_DONE:
611 ar = (AsyncResult) msg.obj;
612 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700613 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700615 int[] result = (int[]) ar.result;
616 int channelId = result[0];
617 byte[] selectResponse = null;
618 if (result.length > 1) {
619 selectResponse = new byte[result.length - 1];
620 for (int i = 1; i < result.length; ++i) {
621 selectResponse[i - 1] = (byte) result[i];
622 }
623 }
624 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700625 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 if (ar.result == null) {
628 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700629 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 if (ar.exception != null) {
631 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
632 }
633
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700634 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700635 if (ar.exception instanceof CommandException) {
636 CommandException.Error error =
637 ((CommandException) (ar.exception)).getCommandError();
638 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700639 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700640 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700641 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700642 }
643 }
644 openChannelResp = new IccOpenLogicalChannelResponse(
645 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700647 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700648 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 break;
650
651 case CMD_CLOSE_CHANNEL:
652 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800653 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700654 if (uiccCard == null) {
655 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900656 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700657 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700658 } else {
659 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
660 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
661 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 break;
663
664 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800665 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
666 break;
667
668 case CMD_NV_READ_ITEM:
669 request = (MainThreadRequest) msg.obj;
670 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800671 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
672 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800673 break;
674
675 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 ar = (AsyncResult) msg.obj;
677 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800678 if (ar.exception == null && ar.result != null) {
679 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800681 request.result = "";
682 if (ar.result == null) {
683 loge("nvReadItem: Empty response");
684 } else if (ar.exception instanceof CommandException) {
685 loge("nvReadItem: CommandException: " +
686 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800688 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 }
690 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700691 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 break;
693
Jake Hambye994d462014-02-03 13:10:13 -0800694 case CMD_NV_WRITE_ITEM:
695 request = (MainThreadRequest) msg.obj;
696 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
697 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800698 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700699 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800700 break;
701
702 case EVENT_NV_WRITE_ITEM_DONE:
703 handleNullReturnEvent(msg, "nvWriteItem");
704 break;
705
706 case CMD_NV_WRITE_CDMA_PRL:
707 request = (MainThreadRequest) msg.obj;
708 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800709 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800710 break;
711
712 case EVENT_NV_WRITE_CDMA_PRL_DONE:
713 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
714 break;
715
chen xu6dac5ab2018-10-26 17:39:23 -0700716 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800717 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700718 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800719 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800720 break;
721
chen xu6dac5ab2018-10-26 17:39:23 -0700722 case EVENT_RESET_MODEM_CONFIG_DONE:
723 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800724 break;
725
Jake Hamby7c27be32014-03-03 13:25:59 -0800726 case CMD_GET_PREFERRED_NETWORK_TYPE:
727 request = (MainThreadRequest) msg.obj;
728 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700729 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800730 break;
731
732 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
733 ar = (AsyncResult) msg.obj;
734 request = (MainThreadRequest) ar.userObj;
735 if (ar.exception == null && ar.result != null) {
736 request.result = ar.result; // Integer
737 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800738 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800739 if (ar.result == null) {
740 loge("getPreferredNetworkType: Empty response");
741 } else if (ar.exception instanceof CommandException) {
742 loge("getPreferredNetworkType: CommandException: " +
743 ar.exception);
744 } else {
745 loge("getPreferredNetworkType: Unknown exception");
746 }
747 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700748 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800749 break;
750
751 case CMD_SET_PREFERRED_NETWORK_TYPE:
752 request = (MainThreadRequest) msg.obj;
753 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
754 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700755 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800756 break;
757
758 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
759 handleNullReturnEvent(msg, "setPreferredNetworkType");
760 break;
761
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000762 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
763 request = (MainThreadRequest)msg.obj;
764 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800765 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000766 break;
767
768 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
769 ar = (AsyncResult)msg.obj;
770 request = (MainThreadRequest)ar.userObj;
771 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700772 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000773 break;
774
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800775 case CMD_SET_VOICEMAIL_NUMBER:
776 request = (MainThreadRequest) msg.obj;
777 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
778 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800779 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
780 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800781 break;
782
783 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
784 handleNullReturnEvent(msg, "setVoicemailNumber");
785 break;
786
Stuart Scott54788802015-03-30 13:18:01 -0700787 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
788 request = (MainThreadRequest) msg.obj;
789 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
790 request);
791 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
792 break;
793
794 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
795 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
796 break;
797
Shishir Agrawal302c8692015-06-19 13:49:39 -0700798 case CMD_PERFORM_NETWORK_SCAN:
799 request = (MainThreadRequest) msg.obj;
800 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
801 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
802 break;
803
804 case EVENT_PERFORM_NETWORK_SCAN_DONE:
805 ar = (AsyncResult) msg.obj;
806 request = (MainThreadRequest) ar.userObj;
807 CellNetworkScanResult cellScanResult;
808 if (ar.exception == null && ar.result != null) {
809 cellScanResult = new CellNetworkScanResult(
810 CellNetworkScanResult.STATUS_SUCCESS,
811 (List<OperatorInfo>) ar.result);
812 } else {
813 if (ar.result == null) {
814 loge("getCellNetworkScanResults: Empty response");
815 }
816 if (ar.exception != null) {
817 loge("getCellNetworkScanResults: Exception: " + ar.exception);
818 }
819 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
820 if (ar.exception instanceof CommandException) {
821 CommandException.Error error =
822 ((CommandException) (ar.exception)).getCommandError();
823 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
824 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
825 } else if (error == CommandException.Error.GENERIC_FAILURE) {
826 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
827 }
828 }
829 cellScanResult = new CellNetworkScanResult(errorCode, null);
830 }
831 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700832 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700833 break;
834
835 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
836 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700837 ManualNetworkSelectionArgument selArg =
838 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700839 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
840 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700841 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
842 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700843 break;
844
845 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700846 ar = (AsyncResult) msg.obj;
847 request = (MainThreadRequest) ar.userObj;
848 if (ar.exception == null) {
849 request.result = true;
850 } else {
851 request.result = false;
852 loge("setNetworkSelectionModeManual " + ar.exception);
853 }
854 notifyRequester(request);
855 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700856 break;
857
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700858 case CMD_GET_MODEM_ACTIVITY_INFO:
859 request = (MainThreadRequest) msg.obj;
860 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700861 if (defaultPhone != null) {
862 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
863 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700864 break;
865
866 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
867 ar = (AsyncResult) msg.obj;
868 request = (MainThreadRequest) ar.userObj;
869 if (ar.exception == null && ar.result != null) {
870 request.result = ar.result;
871 } else {
872 if (ar.result == null) {
873 loge("queryModemActivityInfo: Empty response");
874 } else if (ar.exception instanceof CommandException) {
875 loge("queryModemActivityInfo: CommandException: " +
876 ar.exception);
877 } else {
878 loge("queryModemActivityInfo: Unknown exception");
879 }
880 }
Amit Mahajand4766222016-01-28 15:28:28 -0800881 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
882 if (request.result == null) {
Chen Xu13851032019-09-10 18:49:52 -0700883 request.result = new ModemActivityInfo(0, 0, 0, null, 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800884 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700885 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700886 break;
887
Meng Wang1a7c35a2016-05-05 20:56:15 -0700888 case CMD_SET_ALLOWED_CARRIERS:
889 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800890 CarrierRestrictionRules argument =
891 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700892 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800893 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700894 break;
895
896 case EVENT_SET_ALLOWED_CARRIERS_DONE:
897 ar = (AsyncResult) msg.obj;
898 request = (MainThreadRequest) ar.userObj;
899 if (ar.exception == null && ar.result != null) {
900 request.result = ar.result;
901 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800902 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
903 if (ar.exception instanceof CommandException) {
904 loge("setAllowedCarriers: CommandException: " + ar.exception);
905 CommandException.Error error =
906 ((CommandException) (ar.exception)).getCommandError();
907 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
908 request.result =
909 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
910 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700911 } else {
912 loge("setAllowedCarriers: Unknown exception");
913 }
914 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700915 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700916 break;
917
918 case CMD_GET_ALLOWED_CARRIERS:
919 request = (MainThreadRequest) msg.obj;
920 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800921 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700922 break;
923
924 case EVENT_GET_ALLOWED_CARRIERS_DONE:
925 ar = (AsyncResult) msg.obj;
926 request = (MainThreadRequest) ar.userObj;
927 if (ar.exception == null && ar.result != null) {
928 request.result = ar.result;
929 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800930 request.result = new IllegalStateException(
931 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700932 if (ar.result == null) {
933 loge("getAllowedCarriers: Empty response");
934 } else if (ar.exception instanceof CommandException) {
935 loge("getAllowedCarriers: CommandException: " +
936 ar.exception);
937 } else {
938 loge("getAllowedCarriers: Unknown exception");
939 }
940 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700941 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700942 break;
943
Nathan Haroldb3014052017-01-25 15:57:32 -0800944 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
945 ar = (AsyncResult) msg.obj;
946 request = (MainThreadRequest) ar.userObj;
947 if (ar.exception == null && ar.result != null) {
948 request.result = ar.result;
949 } else {
950 request.result = new IllegalArgumentException(
951 "Failed to retrieve Forbidden Plmns");
952 if (ar.result == null) {
953 loge("getForbiddenPlmns: Empty response");
954 } else {
955 loge("getForbiddenPlmns: Unknown exception");
956 }
957 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700958 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800959 break;
960
961 case CMD_GET_FORBIDDEN_PLMNS:
962 request = (MainThreadRequest) msg.obj;
963 uiccCard = getUiccCardFromRequest(request);
964 if (uiccCard == null) {
965 loge("getForbiddenPlmns() UiccCard is null");
966 request.result = new IllegalArgumentException(
967 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700968 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800969 break;
970 }
971 Integer appType = (Integer) request.argument;
972 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
973 if (uiccApp == null) {
974 loge("getForbiddenPlmns() no app with specified type -- "
975 + appType);
976 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700977 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800978 break;
979 } else {
980 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
981 + " specified type -- " + appType);
982 }
983 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
984 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
985 onCompleted);
986 break;
987
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000988 case CMD_SWITCH_SLOTS:
989 request = (MainThreadRequest) msg.obj;
990 int[] physicalSlots = (int[]) request.argument;
991 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
992 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
993 break;
994
995 case EVENT_SWITCH_SLOTS_DONE:
996 ar = (AsyncResult) msg.obj;
997 request = (MainThreadRequest) ar.userObj;
998 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700999 notifyRequester(request);
1000 break;
1001 case CMD_GET_NETWORK_SELECTION_MODE:
1002 request = (MainThreadRequest) msg.obj;
1003 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1004 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1005 break;
1006
1007 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1008 ar = (AsyncResult) msg.obj;
1009 request = (MainThreadRequest) ar.userObj;
1010 if (ar.exception != null) {
1011 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1012 } else {
1013 int mode = ((int[]) ar.result)[0];
1014 if (mode == 0) {
1015 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1016 } else {
1017 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1018 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001019 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001020 notifyRequester(request);
1021 break;
1022 case CMD_GET_CDMA_ROAMING_MODE:
1023 request = (MainThreadRequest) msg.obj;
1024 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1025 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1026 break;
1027 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1028 ar = (AsyncResult) msg.obj;
1029 request = (MainThreadRequest) ar.userObj;
1030 if (ar.exception != null) {
1031 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1032 } else {
1033 request.result = ((int[]) ar.result)[0];
1034 }
1035 notifyRequester(request);
1036 break;
1037 case CMD_SET_CDMA_ROAMING_MODE:
1038 request = (MainThreadRequest) msg.obj;
1039 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1040 int mode = (int) request.argument;
1041 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1042 break;
1043 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1044 ar = (AsyncResult) msg.obj;
1045 request = (MainThreadRequest) ar.userObj;
1046 request.result = ar.exception == null;
1047 notifyRequester(request);
1048 break;
1049 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1050 request = (MainThreadRequest) msg.obj;
1051 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1052 int subscriptionMode = (int) request.argument;
1053 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1054 break;
1055 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1056 ar = (AsyncResult) msg.obj;
1057 request = (MainThreadRequest) ar.userObj;
1058 request.result = ar.exception == null;
1059 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001060 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001061 case CMD_GET_ALL_CELL_INFO:
1062 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001063 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001064 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001065 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001066 case EVENT_GET_ALL_CELL_INFO_DONE:
1067 ar = (AsyncResult) msg.obj;
1068 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001069 // If a timeout occurs, the response will be null
1070 request.result = (ar.exception == null && ar.result != null)
1071 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001072 synchronized (request) {
1073 request.notifyAll();
1074 }
1075 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001076 case CMD_REQUEST_CELL_INFO_UPDATE:
1077 request = (MainThreadRequest) msg.obj;
1078 request.phone.requestCellInfoUpdate(request.workSource,
1079 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1080 break;
1081 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1082 ar = (AsyncResult) msg.obj;
1083 request = (MainThreadRequest) ar.userObj;
1084 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1085 try {
1086 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001087 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001088 cb.onError(
1089 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1090 ar.exception.getClass().getName(),
1091 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001092 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001093 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001094 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001095 } else {
1096 // use the result as returned
1097 cb.onCellInfo((List<CellInfo>) ar.result);
1098 }
1099 } catch (RemoteException re) {
1100 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1101 }
1102 break;
1103 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001104 request = (MainThreadRequest) msg.obj;
1105 WorkSource ws = (WorkSource) request.argument;
1106 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001107 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001108 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001109 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001110 ar = (AsyncResult) msg.obj;
1111 request = (MainThreadRequest) ar.userObj;
1112 if (ar.exception == null) {
1113 request.result = ar.result;
1114 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001115 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001116 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001117 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001118 }
1119
1120 synchronized (request) {
1121 request.notifyAll();
1122 }
1123 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001124 case CMD_MODEM_REBOOT:
1125 request = (MainThreadRequest) msg.obj;
1126 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001127 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001128 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001129 case EVENT_CMD_MODEM_REBOOT_DONE:
1130 handleNullReturnEvent(msg, "rebootModem");
1131 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001132 case CMD_REQUEST_ENABLE_MODEM:
1133 request = (MainThreadRequest) msg.obj;
1134 boolean enable = (boolean) request.argument;
1135 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001136 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001137 PhoneConfigurationManager.getInstance()
1138 .enablePhone(request.phone, enable, onCompleted);
1139 break;
1140 case EVENT_ENABLE_MODEM_DONE:
1141 ar = (AsyncResult) msg.obj;
1142 request = (MainThreadRequest) ar.userObj;
1143 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001144 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001145 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001146 if ((boolean) request.result) {
1147 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1148 updateModemStateMetrics();
1149 } else {
1150 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1151 + ar.exception);
1152 }
1153 notifyRequester(request);
1154 break;
1155 case CMD_GET_MODEM_STATUS:
1156 request = (MainThreadRequest) msg.obj;
1157 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1158 PhoneConfigurationManager.getInstance()
1159 .getPhoneStatusFromModem(request.phone, onCompleted);
1160 break;
1161 case EVENT_GET_MODEM_STATUS_DONE:
1162 ar = (AsyncResult) msg.obj;
1163 request = (MainThreadRequest) ar.userObj;
1164 int id = request.phone.getPhoneId();
1165 if (ar.exception == null && ar.result != null) {
1166 request.result = ar.result;
1167 //update the cache as modem status has changed
1168 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1169 (boolean) request.result);
1170 } else {
1171 // Return true if modem status cannot be retrieved. For most cases,
1172 // modem status is on. And for older version modems, GET_MODEM_STATUS
1173 // and disable modem are not supported. Modem is always on.
1174 // TODO: this should be fixed in R to support a third
1175 // status UNKNOWN b/131631629
1176 request.result = true;
1177 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1178 + ar.exception);
1179 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001180 notifyRequester(request);
1181 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001182 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1183 ar = (AsyncResult) msg.obj;
1184 request = (MainThreadRequest) ar.userObj;
1185 if (ar.exception == null && ar.result != null) {
1186 request.result = ar.result;
1187 } else {
1188 request.result = -1;
1189 loge("Failed to set Forbidden Plmns");
1190 if (ar.result == null) {
1191 loge("setForbidenPlmns: Empty response");
1192 } else if (ar.exception != null) {
1193 loge("setForbiddenPlmns: Exception: " + ar.exception);
1194 request.result = -1;
1195 } else {
1196 loge("setForbiddenPlmns: Unknown exception");
1197 }
1198 }
1199 notifyRequester(request);
1200 break;
1201 case CMD_SET_FORBIDDEN_PLMNS:
1202 request = (MainThreadRequest) msg.obj;
1203 uiccCard = getUiccCardFromRequest(request);
1204 if (uiccCard == null) {
1205 loge("setForbiddenPlmns: UiccCard is null");
1206 request.result = -1;
1207 notifyRequester(request);
1208 break;
1209 }
1210 Pair<Integer, List<String>> setFplmnsArgs =
1211 (Pair<Integer, List<String>>) request.argument;
1212 appType = setFplmnsArgs.first;
1213 List<String> fplmns = setFplmnsArgs.second;
1214 uiccApp = uiccCard.getApplicationByType(appType);
1215 if (uiccApp == null) {
1216 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1217 request.result = -1;
1218 loge("Failed to get UICC App");
1219 notifyRequester(request);
1220 } else {
1221 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1222 ((SIMRecords) uiccApp.getIccRecords())
1223 .setForbiddenPlmns(onCompleted, fplmns);
1224 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001225 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001226 case CMD_ERASE_MODEM_CONFIG:
1227 request = (MainThreadRequest) msg.obj;
1228 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1229 defaultPhone.eraseModemConfig(onCompleted);
1230 break;
1231 case EVENT_ERASE_MODEM_CONFIG_DONE:
1232 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001233 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001234 default:
1235 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1236 break;
1237 }
1238 }
Jake Hambye994d462014-02-03 13:10:13 -08001239
Pengquan Menga1bb6272018-09-06 09:59:22 -07001240 private void notifyRequester(MainThreadRequest request) {
1241 synchronized (request) {
1242 request.notifyAll();
1243 }
1244 }
1245
Jake Hambye994d462014-02-03 13:10:13 -08001246 private void handleNullReturnEvent(Message msg, String command) {
1247 AsyncResult ar = (AsyncResult) msg.obj;
1248 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1249 if (ar.exception == null) {
1250 request.result = true;
1251 } else {
1252 request.result = false;
1253 if (ar.exception instanceof CommandException) {
1254 loge(command + ": CommandException: " + ar.exception);
1255 } else {
1256 loge(command + ": Unknown exception");
1257 }
1258 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001259 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001260 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001261 }
1262
1263 /**
1264 * Posts the specified command to be executed on the main thread,
1265 * waits for the request to complete, and returns the result.
1266 * @see #sendRequestAsync
1267 */
1268 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001269 return sendRequest(
1270 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001271 }
1272
1273 /**
1274 * Posts the specified command to be executed on the main thread,
1275 * waits for the request to complete, and returns the result.
1276 * @see #sendRequestAsync
1277 */
1278 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1279 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001280 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001281 }
1282
1283 /**
1284 * Posts the specified command to be executed on the main thread,
1285 * waits for the request to complete, and returns the result.
1286 * @see #sendRequestAsync
1287 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001288 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001289 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001290 }
1291
1292 /**
1293 * Posts the specified command to be executed on the main thread,
1294 * waits for the request to complete, and returns the result.
1295 * @see #sendRequestAsync
1296 */
Nathan Harold92bed182018-10-12 18:16:49 -07001297 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1298 return sendRequest(command, argument, subId, null, workSource);
1299 }
1300
1301 /**
1302 * Posts the specified command to be executed on the main thread,
1303 * waits for the request to complete, and returns the result.
1304 * @see #sendRequestAsync
1305 */
1306 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1307 return sendRequest(
1308 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1309 }
1310
1311 /**
1312 * Posts the specified command to be executed on the main thread,
1313 * waits for the request to complete, and returns the result.
1314 * @see #sendRequestAsync
1315 */
1316 private Object sendRequest(
1317 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001318 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1319 throw new RuntimeException("This method will deadlock if called from the main thread.");
1320 }
1321
Nathan Harold92bed182018-10-12 18:16:49 -07001322 MainThreadRequest request = null;
1323 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1324 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1325 } else if (phone != null) {
1326 request = new MainThreadRequest(argument, phone, workSource);
1327 } else {
1328 request = new MainThreadRequest(argument, subId, workSource);
1329 }
1330
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331 Message msg = mMainThreadHandler.obtainMessage(command, request);
1332 msg.sendToTarget();
1333
1334 // Wait for the request to complete
1335 synchronized (request) {
1336 while (request.result == null) {
1337 try {
1338 request.wait();
1339 } catch (InterruptedException e) {
1340 // Do nothing, go back and wait until the request is complete
1341 }
1342 }
1343 }
1344 return request.result;
1345 }
1346
1347 /**
1348 * Asynchronous ("fire and forget") version of sendRequest():
1349 * Posts the specified command to be executed on the main thread, and
1350 * returns immediately.
1351 * @see #sendRequest
1352 */
1353 private void sendRequestAsync(int command) {
1354 mMainThreadHandler.sendEmptyMessage(command);
1355 }
1356
1357 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001358 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001359 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001360 */
1361 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001362 sendRequestAsync(command, argument, null, null);
1363 }
1364
1365 /**
1366 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1367 * @see {@link #sendRequest(int,Object)}
1368 */
1369 private void sendRequestAsync(
1370 int command, Object argument, Phone phone, WorkSource workSource) {
1371 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001372 Message msg = mMainThreadHandler.obtainMessage(command, request);
1373 msg.sendToTarget();
1374 }
1375
1376 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377 * Initialize the singleton PhoneInterfaceManager instance.
1378 * This is only done once, at startup, from PhoneApp.onCreate().
1379 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001380 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001381 synchronized (PhoneInterfaceManager.class) {
1382 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001383 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001384 } else {
1385 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1386 }
1387 return sInstance;
1388 }
1389 }
1390
1391 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001392 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001393 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001394 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001395 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001396 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001397 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1398 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001399 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001400 mTelephonySharedPreferences =
1401 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001402 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001403 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001404
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001405 publish();
1406 }
1407
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001408 private Phone getDefaultPhone() {
1409 Phone thePhone = getPhone(getDefaultSubscription());
1410 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1411 }
1412
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001413 private void publish() {
1414 if (DBG) log("publish: " + this);
1415
1416 ServiceManager.addService("phone", this);
1417 }
1418
Stuart Scott584921c2015-01-15 17:10:34 -08001419 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001420 if (request.phone != null) {
1421 return request.phone;
1422 } else {
1423 return getPhoneFromSubId(request.subId);
1424 }
1425 }
1426
1427 private Phone getPhoneFromSubId(int subId) {
1428 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1429 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001430 }
1431
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001432 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1433 Phone phone = getPhoneFromRequest(request);
1434 return phone == null ? null :
1435 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1436 }
1437
Wink Saville36469e72014-06-11 15:17:00 -07001438 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001439 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001440 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001441 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001442
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001443 private void sendEraseModemConfig(Phone phone) {
1444 if (phone != null) {
1445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1446 mApp, phone.getSubId(), "eraseModemConfig");
1447 final long identity = Binder.clearCallingIdentity();
1448 try {
1449 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1450 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1451 } finally {
1452 Binder.restoreCallingIdentity(identity);
1453 }
1454 }
1455 }
1456
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001457 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001458 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001459 }
1460
Wink Savilleb564aae2014-10-23 10:18:09 -07001461 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001462 if (DBG) log("dial: " + number);
1463 // No permission check needed here: This is just a wrapper around the
1464 // ACTION_DIAL intent, which is available to any app since it puts up
1465 // the UI before it does anything.
1466
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001467 final long identity = Binder.clearCallingIdentity();
1468 try {
1469 String url = createTelUrl(number);
1470 if (url == null) {
1471 return;
1472 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001473
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001474 // PENDING: should we just silently fail if phone is offhook or ringing?
1475 PhoneConstants.State state = mCM.getState(subId);
1476 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1477 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1478 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1479 mApp.startActivity(intent);
1480 }
1481 } finally {
1482 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001483 }
1484 }
1485
1486 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001487 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001488 }
1489
Wink Savilleb564aae2014-10-23 10:18:09 -07001490 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001491 if (DBG) log("call: " + number);
1492
1493 // This is just a wrapper around the ACTION_CALL intent, but we still
1494 // need to do a permission check since we're calling startActivity()
1495 // from the context of the phone app.
1496 enforceCallPermission();
1497
Jordan Liu1617b712019-07-10 15:06:26 -07001498 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001499 != AppOpsManager.MODE_ALLOWED) {
1500 return;
1501 }
1502
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001503 final long identity = Binder.clearCallingIdentity();
1504 try {
1505 String url = createTelUrl(number);
1506 if (url == null) {
1507 return;
1508 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001509
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001510 boolean isValid = false;
1511 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1512 if (slist != null) {
1513 for (SubscriptionInfo subInfoRecord : slist) {
1514 if (subInfoRecord.getSubscriptionId() == subId) {
1515 isValid = true;
1516 break;
1517 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001518 }
Wink Saville08874612014-08-31 19:19:58 -07001519 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001520 if (!isValid) {
1521 return;
1522 }
Wink Saville08874612014-08-31 19:19:58 -07001523
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001524 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1525 intent.putExtra(SUBSCRIPTION_KEY, subId);
1526 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1527 mApp.startActivity(intent);
1528 } finally {
1529 Binder.restoreCallingIdentity(identity);
1530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001531 }
1532
Wink Savilleb564aae2014-10-23 10:18:09 -07001533 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001534 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001535 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1536 }
1537
Wink Savilleb564aae2014-10-23 10:18:09 -07001538 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001539 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001540 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1541 }
1542
Wink Savilleb564aae2014-10-23 10:18:09 -07001543 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001544 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001545
1546 final long identity = Binder.clearCallingIdentity();
1547 try {
1548 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1549 checkSimPin.start();
1550 return checkSimPin.unlockSim(null, pin);
1551 } finally {
1552 Binder.restoreCallingIdentity(identity);
1553 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 }
1555
Wink Savilleb564aae2014-10-23 10:18:09 -07001556 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001557 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001558
1559 final long identity = Binder.clearCallingIdentity();
1560 try {
1561 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1562 checkSimPuk.start();
1563 return checkSimPuk.unlockSim(puk, pin);
1564 } finally {
1565 Binder.restoreCallingIdentity(identity);
1566 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567 }
1568
1569 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001570 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001571 * a synchronous one.
1572 */
1573 private static class UnlockSim extends Thread {
1574
1575 private final IccCard mSimCard;
1576
1577 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001578 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1579 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001580
1581 // For replies from SimCard interface
1582 private Handler mHandler;
1583
1584 // For async handler to identify request type
1585 private static final int SUPPLY_PIN_COMPLETE = 100;
1586
1587 public UnlockSim(IccCard simCard) {
1588 mSimCard = simCard;
1589 }
1590
1591 @Override
1592 public void run() {
1593 Looper.prepare();
1594 synchronized (UnlockSim.this) {
1595 mHandler = new Handler() {
1596 @Override
1597 public void handleMessage(Message msg) {
1598 AsyncResult ar = (AsyncResult) msg.obj;
1599 switch (msg.what) {
1600 case SUPPLY_PIN_COMPLETE:
1601 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1602 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001603 mRetryCount = msg.arg1;
1604 if (ar.exception != null) {
1605 if (ar.exception instanceof CommandException &&
1606 ((CommandException)(ar.exception)).getCommandError()
1607 == CommandException.Error.PASSWORD_INCORRECT) {
1608 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1609 } else {
1610 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1611 }
1612 } else {
1613 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1614 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001615 mDone = true;
1616 UnlockSim.this.notifyAll();
1617 }
1618 break;
1619 }
1620 }
1621 };
1622 UnlockSim.this.notifyAll();
1623 }
1624 Looper.loop();
1625 }
1626
1627 /*
1628 * Use PIN or PUK to unlock SIM card
1629 *
1630 * If PUK is null, unlock SIM card with PIN
1631 *
1632 * If PUK is not null, unlock SIM card with PUK and set PIN code
1633 */
Wink Saville9de0f752013-10-22 19:04:03 -07001634 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001635
1636 while (mHandler == null) {
1637 try {
1638 wait();
1639 } catch (InterruptedException e) {
1640 Thread.currentThread().interrupt();
1641 }
1642 }
1643 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1644
1645 if (puk == null) {
1646 mSimCard.supplyPin(pin, callback);
1647 } else {
1648 mSimCard.supplyPuk(puk, pin, callback);
1649 }
1650
1651 while (!mDone) {
1652 try {
1653 Log.d(LOG_TAG, "wait for done");
1654 wait();
1655 } catch (InterruptedException e) {
1656 // Restore the interrupted status
1657 Thread.currentThread().interrupt();
1658 }
1659 }
1660 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001661 int[] resultArray = new int[2];
1662 resultArray[0] = mResult;
1663 resultArray[1] = mRetryCount;
1664 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001665 }
1666 }
1667
1668 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001669 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001670
1671 }
1672
Wink Savilleb564aae2014-10-23 10:18:09 -07001673 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001674 // No permission check needed here: this call is harmless, and it's
1675 // needed for the ServiceState.requestStateUpdate() call (which is
1676 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001677 final long identity = Binder.clearCallingIdentity();
1678 try {
1679 final Phone phone = getPhone(subId);
1680 if (phone != null) {
1681 phone.updateServiceLocation();
1682 }
1683 } finally {
1684 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001685 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001686 }
1687
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001688 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001689 @Override
1690 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001691 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001692 }
1693
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001694 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001695 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1696 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1697 callingFeatureId);
1698 }
1699
1700 @Deprecated
1701 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001702 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001703 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
1704 }
1705
1706 @Override
1707 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1708 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001709 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001710 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001711 return false;
1712 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001713
1714 final long identity = Binder.clearCallingIdentity();
1715 try {
1716 return isRadioOnForSubscriber(subId);
1717 } finally {
1718 Binder.restoreCallingIdentity(identity);
1719 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001720 }
1721
1722 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001723 final long identity = Binder.clearCallingIdentity();
1724 try {
1725 final Phone phone = getPhone(subId);
1726 if (phone != null) {
1727 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1728 } else {
1729 return false;
1730 }
1731 } finally {
1732 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001733 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 }
1735
1736 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001737 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001738 }
Wink Saville36469e72014-06-11 15:17:00 -07001739
Wink Savilleb564aae2014-10-23 10:18:09 -07001740 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001742
1743 final long identity = Binder.clearCallingIdentity();
1744 try {
1745 final Phone phone = getPhone(subId);
1746 if (phone != null) {
1747 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1748 }
1749 } finally {
1750 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001751 }
Wink Saville36469e72014-06-11 15:17:00 -07001752 }
1753
1754 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001755 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001756 }
1757
Wink Savilleb564aae2014-10-23 10:18:09 -07001758 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001759 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001760
1761 final long identity = Binder.clearCallingIdentity();
1762 try {
1763 final Phone phone = getPhone(subId);
1764 if (phone == null) {
1765 return false;
1766 }
1767 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1768 toggleRadioOnOffForSubscriber(subId);
1769 }
1770 return true;
1771 } finally {
1772 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001773 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 }
Wink Saville36469e72014-06-11 15:17:00 -07001775
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001776 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08001777 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001778 /*
1779 * If any of the Radios are available, it will need to be
1780 * shutdown. So return true if any Radio is available.
1781 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001782 final long identity = Binder.clearCallingIdentity();
1783 try {
1784 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1785 Phone phone = PhoneFactory.getPhone(i);
1786 if (phone != null && phone.isRadioAvailable()) return true;
1787 }
1788 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1789 return false;
1790 } finally {
1791 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001792 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001793 }
1794
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001795 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001796 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001797 enforceModifyPermission();
1798
1799 final long identity = Binder.clearCallingIdentity();
1800 try {
1801 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1802 logv("Shutting down Phone " + i);
1803 shutdownRadioUsingPhoneId(i);
1804 }
1805 } finally {
1806 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001807 }
1808 }
1809
1810 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001811 Phone phone = PhoneFactory.getPhone(phoneId);
1812 if (phone != null && phone.isRadioAvailable()) {
1813 phone.shutdownRadio();
1814 }
1815 }
1816
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001817 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001818 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001819
1820 final long identity = Binder.clearCallingIdentity();
1821 try {
1822 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1823 if (defaultPhone != null) {
1824 defaultPhone.setRadioPower(turnOn);
1825 return true;
1826 } else {
1827 loge("There's no default phone.");
1828 return false;
1829 }
1830 } finally {
1831 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001832 }
Wink Saville36469e72014-06-11 15:17:00 -07001833 }
1834
Wink Savilleb564aae2014-10-23 10:18:09 -07001835 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001836 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001837
1838 final long identity = Binder.clearCallingIdentity();
1839 try {
1840 final Phone phone = getPhone(subId);
1841 if (phone != null) {
1842 phone.setRadioPower(turnOn);
1843 return true;
1844 } else {
1845 return false;
1846 }
1847 } finally {
1848 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001849 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001850 }
1851
Wink Saville36469e72014-06-11 15:17:00 -07001852 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001853 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001854 public boolean enableDataConnectivity() {
1855 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001856
1857 final long identity = Binder.clearCallingIdentity();
1858 try {
1859 int subId = mSubscriptionController.getDefaultDataSubId();
1860 final Phone phone = getPhone(subId);
1861 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001862 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001863 return true;
1864 } else {
1865 return false;
1866 }
1867 } finally {
1868 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001869 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001870 }
1871
Wink Saville36469e72014-06-11 15:17:00 -07001872 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001873 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001874 public boolean disableDataConnectivity() {
1875 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001876
1877 final long identity = Binder.clearCallingIdentity();
1878 try {
1879 int subId = mSubscriptionController.getDefaultDataSubId();
1880 final Phone phone = getPhone(subId);
1881 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001882 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001883 return true;
1884 } else {
1885 return false;
1886 }
1887 } finally {
1888 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001889 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 }
1891
Sanket Padawe356d7632015-06-22 14:03:32 -07001892 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001893 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001894 final long identity = Binder.clearCallingIdentity();
1895 try {
1896 final Phone phone = getPhone(subId);
1897 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001898 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001899 } else {
1900 return false;
1901 }
1902 } finally {
1903 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001904 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001905 }
1906
1907 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001908 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001909 }
1910
pkanwarae03a6b2016-11-06 20:37:09 -08001911 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001912 enforceCallPermission();
1913
1914 final long identity = Binder.clearCallingIdentity();
1915 try {
1916 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1917 return;
1918 }
1919 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1920 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1921 } finally {
1922 Binder.restoreCallingIdentity(identity);
1923 }
pkanwar32d516d2016-10-14 19:37:38 -07001924 };
1925
Wink Savilleb564aae2014-10-23 10:18:09 -07001926 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001927 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001928
1929 final long identity = Binder.clearCallingIdentity();
1930 try {
1931 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1932 return false;
1933 }
1934 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1935 } finally {
1936 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001937 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 }
1939
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001940 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001941 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001942 }
1943
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001944 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001945 final long identity = Binder.clearCallingIdentity();
1946 try {
1947 Phone phone = PhoneFactory.getPhone(slotIndex);
1948 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1949 PhoneConstantConversions.convertCallState(phone.getState());
1950 } finally {
1951 Binder.restoreCallingIdentity(identity);
1952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953 }
1954
Sanket Padawe356d7632015-06-22 14:03:32 -07001955 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001956 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001957 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1958 }
1959
1960 @Override
1961 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001962 final long identity = Binder.clearCallingIdentity();
1963 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001964 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001965 if (phone != null) {
1966 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1967 } else {
1968 return PhoneConstantConversions.convertDataState(
1969 PhoneConstants.DataState.DISCONNECTED);
1970 }
1971 } finally {
1972 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001973 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001974 }
1975
Sanket Padawe356d7632015-06-22 14:03:32 -07001976 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001977 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001978 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1979 }
1980
1981 @Override
1982 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001983 final long identity = Binder.clearCallingIdentity();
1984 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001985 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001986 if (phone != null) {
1987 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1988 } else {
1989 return TelephonyManager.DATA_ACTIVITY_NONE;
1990 }
1991 } finally {
1992 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001993 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001994 }
1995
1996 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08001997 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001998 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001999 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002000
2001 LocationAccessPolicy.LocationPermissionResult locationResult =
2002 LocationAccessPolicy.checkLocationPermission(mApp,
2003 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2004 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002005 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002006 .setCallingPid(Binder.getCallingPid())
2007 .setCallingUid(Binder.getCallingUid())
2008 .setMethod("getCellLocation")
2009 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2010 .build());
2011 switch (locationResult) {
2012 case DENIED_HARD:
2013 throw new SecurityException("Not allowed to access cell location");
2014 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002015 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2016 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 }
2018
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002019 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002020 final long identity = Binder.clearCallingIdentity();
2021 try {
2022 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002023 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002024 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002025 } finally {
2026 Binder.restoreCallingIdentity(identity);
2027 }
Svetoslav64fad262015-04-14 14:35:21 -07002028 }
2029
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002030 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002031 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2032 String callingFeatureId) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002033 if (!TextUtils.isEmpty(callingPackage)) {
2034 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002035 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2036 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002037 return "";
2038 }
2039 }
2040
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002041 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2042 // registered cell info, so return a NULL country instead.
2043 final long identity = Binder.clearCallingIdentity();
2044 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002045 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2046 // Get default phone in this case.
2047 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2048 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002049 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002050 // Todo: fix this when we can get the actual cellular network info when the device
2051 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002052 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002053 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2054 null)) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002055 return "";
2056 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002057 Phone phone = PhoneFactory.getPhone(phoneId);
2058 if (phone != null) {
2059 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002060 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002061 if (sst != null) {
2062 LocaleTracker lt = sst.getLocaleTracker();
2063 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002064 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2065 return lt.getCurrentCountry();
2066 } else if (emergencyNumberTracker != null) {
2067 return emergencyNumberTracker.getEmergencyCountryIso();
2068 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002069 }
2070 }
2071 }
2072 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002073 } finally {
2074 Binder.restoreCallingIdentity(identity);
2075 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002076 }
2077
2078 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002079 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002080 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002081 }
2082
Sanket Padawe356d7632015-06-22 14:03:32 -07002083 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002084 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085 mApp.enforceCallingOrSelfPermission(
2086 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002087
2088 final long identity = Binder.clearCallingIdentity();
2089 try {
2090 final Phone phone = getPhone(subId);
2091 if (phone != null) {
2092 phone.enableLocationUpdates();
2093 }
2094 } finally {
2095 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002096 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002097 }
2098
2099 @Override
2100 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002101 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002102 }
2103
Sanket Padawe356d7632015-06-22 14:03:32 -07002104 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002105 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002106 mApp.enforceCallingOrSelfPermission(
2107 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002108
2109 final long identity = Binder.clearCallingIdentity();
2110 try {
2111 final Phone phone = getPhone(subId);
2112 if (phone != null) {
2113 phone.disableLocationUpdates();
2114 }
2115 } finally {
2116 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002117 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002118 }
2119
Nathan Harold31d7ff32018-10-15 20:20:30 -07002120 /**
2121 * Returns the target SDK version number for a given package name.
2122 *
Nathan Haroldec184742019-07-10 17:04:16 -07002123 * This call MUST be invoked before clearing the calling UID.
2124 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002125 * @return target SDK if the package is found or INT_MAX.
2126 */
2127 private int getTargetSdk(String packageName) {
2128 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002129 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002130 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002131 if (ai != null) return ai.targetSdkVersion;
2132 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002133 loge("Failed to get package info for pkg="
2134 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002135 }
2136 return Integer.MAX_VALUE;
2137 }
2138
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002139 @Override
2140 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002141 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2142 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002143 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002144 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2145 throw new SecurityException(
2146 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2147 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002148
Jordan Liu1617b712019-07-10 15:06:26 -07002149 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2151 return null;
2152 }
Svetoslav64fad262015-04-14 14:35:21 -07002153
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002154 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002156 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002157 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002158
Nathan Haroldf180aac2018-06-01 18:43:55 -07002159 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2160 for (CellInfo ci : info) {
2161 if (ci instanceof CellInfoGsm) {
2162 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2163 } else if (ci instanceof CellInfoWcdma) {
2164 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2165 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002167 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 }
2169
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002170 private List<CellInfo> getCachedCellInfo() {
2171 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2172 for (Phone phone : PhoneFactory.getPhones()) {
2173 List<CellInfo> info = phone.getAllCellInfo();
2174 if (info != null) cellInfos.addAll(info);
2175 }
2176 return cellInfos;
2177 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002178
2179 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002180 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002181 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002182 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002183
2184 LocationAccessPolicy.LocationPermissionResult locationResult =
2185 LocationAccessPolicy.checkLocationPermission(mApp,
2186 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2187 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002188 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002189 .setCallingPid(Binder.getCallingPid())
2190 .setCallingUid(Binder.getCallingUid())
2191 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002192 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002193 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2194 .build());
2195 switch (locationResult) {
2196 case DENIED_HARD:
2197 throw new SecurityException("Not allowed to access cell info");
2198 case DENIED_SOFT:
2199 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002200 }
2201
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002202 final int targetSdk = getTargetSdk(callingPackage);
2203 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2204 return getCachedCellInfo();
2205 }
2206
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002207 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002208 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002209 final long identity = Binder.clearCallingIdentity();
2210 try {
2211 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2212 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002213 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002214 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002215 if (info != null) cellInfos.addAll(info);
2216 }
2217 return cellInfos;
2218 } finally {
2219 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220 }
2221 }
2222
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002223 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002224 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2225 String callingFeatureId) {
2226 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2227 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002228 }
2229
2230 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002231 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2232 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002233 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002234 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002235 }
2236
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002237 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2238 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002239 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002240 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002241
2242 LocationAccessPolicy.LocationPermissionResult locationResult =
2243 LocationAccessPolicy.checkLocationPermission(mApp,
2244 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2245 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002246 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002247 .setCallingPid(Binder.getCallingPid())
2248 .setCallingUid(Binder.getCallingUid())
2249 .setMethod("requestCellInfoUpdate")
2250 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2251 .build());
2252 switch (locationResult) {
2253 case DENIED_HARD:
2254 throw new SecurityException("Not allowed to access cell info");
2255 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002256 try {
2257 cb.onCellInfo(new ArrayList<CellInfo>());
2258 } catch (RemoteException re) {
2259 // Drop without consequences
2260 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002261 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002262 }
2263
Nathan Harolda939a962019-05-09 10:13:47 -07002264
2265 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002266 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2267
2268 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2269 }
2270
2271 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002272 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002273 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002274 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002275
2276 final long identity = Binder.clearCallingIdentity();
2277 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002278 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002279 } finally {
2280 Binder.restoreCallingIdentity(identity);
2281 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 }
2283
Shishir Agrawala9f32182016-04-12 12:00:16 -07002284 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002285 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002286 Phone phone = PhoneFactory.getPhone(slotIndex);
2287 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002288 return null;
2289 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002290 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002291 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002292 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002293 return null;
2294 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002295
2296 final long identity = Binder.clearCallingIdentity();
2297 try {
2298 return phone.getImei();
2299 } finally {
2300 Binder.restoreCallingIdentity(identity);
2301 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002302 }
2303
2304 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002305 public String getTypeAllocationCodeForSlot(int slotIndex) {
2306 Phone phone = PhoneFactory.getPhone(slotIndex);
2307 String tac = null;
2308 if (phone != null) {
2309 String imei = phone.getImei();
2310 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2311 }
2312 return tac;
2313 }
2314
2315 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002316 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002317 Phone phone = PhoneFactory.getPhone(slotIndex);
2318 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002319 return null;
2320 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002321
Jeff Davidson913390f2018-02-23 17:11:49 -08002322 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002323 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002324 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002325 return null;
2326 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002327
2328 final long identity = Binder.clearCallingIdentity();
2329 try {
2330 return phone.getMeid();
2331 } finally {
2332 Binder.restoreCallingIdentity(identity);
2333 }
Jack Yu2af8d712017-03-15 17:14:14 -07002334 }
2335
2336 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002337 public String getManufacturerCodeForSlot(int slotIndex) {
2338 Phone phone = PhoneFactory.getPhone(slotIndex);
2339 String manufacturerCode = null;
2340 if (phone != null) {
2341 String meid = phone.getMeid();
2342 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2343 }
2344 return manufacturerCode;
2345 }
2346
2347 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002348 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2349 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002350 Phone phone = PhoneFactory.getPhone(slotIndex);
2351 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002352 return null;
2353 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002354 int subId = phone.getSubId();
2355 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002356 mApp, subId, callingPackage, callingFeatureId,
2357 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002358 return null;
2359 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002360
2361 final long identity = Binder.clearCallingIdentity();
2362 try {
2363 return phone.getDeviceSvn();
2364 } finally {
2365 Binder.restoreCallingIdentity(identity);
2366 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002367 }
2368
fionaxu43304da2017-11-27 22:51:16 -08002369 @Override
2370 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002371 final long identity = Binder.clearCallingIdentity();
2372 try {
2373 final Phone phone = getPhone(subId);
2374 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2375 } finally {
2376 Binder.restoreCallingIdentity(identity);
2377 }
fionaxu43304da2017-11-27 22:51:16 -08002378 }
2379
2380 @Override
2381 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002382 final long identity = Binder.clearCallingIdentity();
2383 try {
2384 final Phone phone = getPhone(subId);
2385 return phone == null ? null : phone.getCarrierName();
2386 } finally {
2387 Binder.restoreCallingIdentity(identity);
2388 }
fionaxu43304da2017-11-27 22:51:16 -08002389 }
2390
calvinpanffe225e2018-11-01 19:43:06 +08002391 @Override
chen xu0026ca62019-03-06 15:28:50 -08002392 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002393 final long identity = Binder.clearCallingIdentity();
2394 try {
2395 final Phone phone = getPhone(subId);
2396 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002397 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002398 } finally {
2399 Binder.restoreCallingIdentity(identity);
2400 }
2401 }
2402
2403 @Override
chen xu0026ca62019-03-06 15:28:50 -08002404 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002405 final long identity = Binder.clearCallingIdentity();
2406 try {
2407 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002408 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002409 } finally {
2410 Binder.restoreCallingIdentity(identity);
2411 }
2412 }
2413
chen xu651eec72018-11-11 19:03:44 -08002414 @Override
chen xu864e11c2018-12-06 22:10:03 -08002415 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2416 if (!isSubscriptionMccMnc) {
2417 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2418 }
chen xu651eec72018-11-11 19:03:44 -08002419 final Phone phone = PhoneFactory.getPhone(slotIndex);
2420 if (phone == null) {
2421 return TelephonyManager.UNKNOWN_CARRIER_ID;
2422 }
2423 final long identity = Binder.clearCallingIdentity();
2424 try {
2425 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2426 } finally {
2427 Binder.restoreCallingIdentity(identity);
2428 }
2429 }
2430
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 //
2432 // Internal helper methods.
2433 //
2434
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002435 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2437 *
2438 * @throws SecurityException if the caller does not have the required permission
2439 */
2440 private void enforceModifyPermission() {
2441 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2442 }
2443
Shuo Qianf2b2df42019-11-13 17:43:31 -08002444 private void enforceActiveEmergencySessionPermission() {
2445 mApp.enforceCallingOrSelfPermission(
2446 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2447 }
2448
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 /**
2450 * Make sure the caller has the CALL_PHONE permission.
2451 *
2452 * @throws SecurityException if the caller does not have the required permission
2453 */
2454 private void enforceCallPermission() {
2455 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2456 }
2457
paulhu423b5f22019-08-23 19:17:33 +08002458 private void enforceSettingsPermission() {
2459 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002460 }
2461
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 private String createTelUrl(String number) {
2463 if (TextUtils.isEmpty(number)) {
2464 return null;
2465 }
2466
Jake Hambye994d462014-02-03 13:10:13 -08002467 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 }
2469
Ihab Awadf9e92732013-12-05 18:02:52 -08002470 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2472 }
2473
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002474 private static void logv(String msg) {
2475 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2476 }
2477
Ihab Awadf9e92732013-12-05 18:02:52 -08002478 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2480 }
2481
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002482 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002483 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002484 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002485 }
2486
Sanket Padawe356d7632015-06-22 14:03:32 -07002487 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002488 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002489 final long identity = Binder.clearCallingIdentity();
2490 try {
2491 final Phone phone = PhoneFactory.getPhone(slotIndex);
2492 if (phone == null) {
2493 return PhoneConstants.PHONE_TYPE_NONE;
2494 } else {
2495 return phone.getPhoneType();
2496 }
2497 } finally {
2498 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 }
2501
2502 /**
2503 * Returns the CDMA ERI icon index to display
2504 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002505 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002506 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2507 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2508 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002509 }
2510
Sanket Padawe356d7632015-06-22 14:03:32 -07002511 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002512 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2513 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002514 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002515 mApp, subId, callingPackage, callingFeatureId,
2516 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002517 return -1;
2518 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002519
2520 final long identity = Binder.clearCallingIdentity();
2521 try {
2522 final Phone phone = getPhone(subId);
2523 if (phone != null) {
2524 return phone.getCdmaEriIconIndex();
2525 } else {
2526 return -1;
2527 }
2528 } finally {
2529 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002531 }
2532
2533 /**
2534 * Returns the CDMA ERI icon mode,
2535 * 0 - ON
2536 * 1 - FLASHING
2537 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002538 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002539 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2540 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2541 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002542 }
2543
Sanket Padawe356d7632015-06-22 14:03:32 -07002544 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002545 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2546 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002547 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002548 mApp, subId, callingPackage, callingFeatureId,
2549 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002550 return -1;
2551 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002552
2553 final long identity = Binder.clearCallingIdentity();
2554 try {
2555 final Phone phone = getPhone(subId);
2556 if (phone != null) {
2557 return phone.getCdmaEriIconMode();
2558 } else {
2559 return -1;
2560 }
2561 } finally {
2562 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002564 }
2565
2566 /**
2567 * Returns the CDMA ERI text,
2568 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002569 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002570 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2571 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2572 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002573 }
2574
Sanket Padawe356d7632015-06-22 14:03:32 -07002575 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002576 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2577 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002578 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002579 mApp, subId, callingPackage, callingFeatureId,
2580 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002581 return null;
2582 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002583
2584 final long identity = Binder.clearCallingIdentity();
2585 try {
2586 final Phone phone = getPhone(subId);
2587 if (phone != null) {
2588 return phone.getCdmaEriText();
2589 } else {
2590 return null;
2591 }
2592 } finally {
2593 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002594 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002595 }
2596
2597 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002598 * Returns the CDMA MDN.
2599 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002600 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002601 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2603 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002604
2605 final long identity = Binder.clearCallingIdentity();
2606 try {
2607 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002608 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002609 return phone.getLine1Number();
2610 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002611 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612 return null;
2613 }
2614 } finally {
2615 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002616 }
2617 }
2618
2619 /**
2620 * Returns the CDMA MIN.
2621 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002622 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002623 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2625 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626
2627 final long identity = Binder.clearCallingIdentity();
2628 try {
2629 final Phone phone = getPhone(subId);
2630 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2631 return phone.getCdmaMin();
2632 } else {
2633 return null;
2634 }
2635 } finally {
2636 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002637 }
2638 }
2639
Hall Liud892bec2018-11-30 14:51:45 -08002640 @Override
2641 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2642 INumberVerificationCallback callback, String callingPackage) {
2643 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2644 != PERMISSION_GRANTED) {
2645 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2646 }
2647 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2648
2649 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2650 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2651 throw new SecurityException("Calling package must be configured in the device config");
2652 }
2653
2654 if (range == null) {
2655 throw new NullPointerException("Range must be non-null");
2656 }
2657
2658 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002659 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002660
2661 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2662 }
2663
Junda Liuca05d5d2014-08-14 22:36:34 -07002664 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002665 * Returns true if CDMA provisioning needs to run.
2666 */
2667 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668 final long identity = Binder.clearCallingIdentity();
2669 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002670 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002671 } finally {
2672 Binder.restoreCallingIdentity(identity);
2673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002674 }
2675
2676 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002677 * Sets the voice mail number of a given subId.
2678 */
2679 @Override
2680 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08002681 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2682 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683
2684 final long identity = Binder.clearCallingIdentity();
2685 try {
2686 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2687 new Pair<String, String>(alphaTag, number), new Integer(subId));
2688 return success;
2689 } finally {
2690 Binder.restoreCallingIdentity(identity);
2691 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002692 }
2693
Ta-wei Yen87c49842016-05-13 21:19:52 -07002694 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002695 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2696 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002697 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2698 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002699 if (!TextUtils.equals(callingPackage, systemDialer)) {
2700 throw new SecurityException("caller must be system dialer");
2701 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702
2703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2706 if (phoneAccountHandle == null) {
2707 return null;
2708 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002709 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002710 } finally {
2711 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002712 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002713 }
2714
2715 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002716 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2717 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002718 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002719 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002720 mApp, subId, callingPackage, callingFeatureId,
2721 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002722 return null;
2723 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002724
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002725 final long identity = Binder.clearCallingIdentity();
2726 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002727 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002728 } finally {
2729 Binder.restoreCallingIdentity(identity);
2730 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002731 }
2732
2733 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002734 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2735 VisualVoicemailSmsFilterSettings settings) {
2736 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737
2738 final long identity = Binder.clearCallingIdentity();
2739 try {
2740 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002741 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002742 } finally {
2743 Binder.restoreCallingIdentity(identity);
2744 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002745 }
2746
2747 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002748 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2749 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002750
2751 final long identity = Binder.clearCallingIdentity();
2752 try {
2753 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002754 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002755 } finally {
2756 Binder.restoreCallingIdentity(identity);
2757 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002758 }
2759
2760 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002761 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2762 String callingPackage, int subId) {
2763 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002764
2765 final long identity = Binder.clearCallingIdentity();
2766 try {
2767 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002768 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002769 } finally {
2770 Binder.restoreCallingIdentity(identity);
2771 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002772 }
2773
2774 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002775 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002776 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002777
2778 final long identity = Binder.clearCallingIdentity();
2779 try {
2780 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002781 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002782 } finally {
2783 Binder.restoreCallingIdentity(identity);
2784 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002785 }
2786
2787 @Override
2788 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2789 String number, int port, String text, PendingIntent sentIntent) {
2790 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002791 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002792 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002793 SmsController smsController = PhoneFactory.getSmsController();
2794 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2795 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002796 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002797
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002798 /**
fionaxu0152e512016-11-14 13:36:14 -08002799 * Sets the voice activation state of a given subId.
2800 */
2801 @Override
2802 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2804 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002805
2806 final long identity = Binder.clearCallingIdentity();
2807 try {
2808 final Phone phone = getPhone(subId);
2809 if (phone != null) {
2810 phone.setVoiceActivationState(activationState);
2811 } else {
2812 loge("setVoiceActivationState fails with invalid subId: " + subId);
2813 }
2814 } finally {
2815 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002816 }
2817 }
2818
2819 /**
2820 * Sets the data activation state of a given subId.
2821 */
2822 @Override
2823 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2825 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826
2827 final long identity = Binder.clearCallingIdentity();
2828 try {
2829 final Phone phone = getPhone(subId);
2830 if (phone != null) {
2831 phone.setDataActivationState(activationState);
2832 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002833 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002834 }
2835 } finally {
2836 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002837 }
2838 }
2839
2840 /**
2841 * Returns the voice activation state of a given subId.
2842 */
2843 @Override
2844 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002845 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002846
fionaxu0152e512016-11-14 13:36:14 -08002847 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002848 final long identity = Binder.clearCallingIdentity();
2849 try {
2850 if (phone != null) {
2851 return phone.getVoiceActivationState();
2852 } else {
2853 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2854 }
2855 } finally {
2856 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002857 }
2858 }
2859
2860 /**
2861 * Returns the data activation state of a given subId.
2862 */
2863 @Override
2864 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002865 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002866
fionaxu0152e512016-11-14 13:36:14 -08002867 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002868 final long identity = Binder.clearCallingIdentity();
2869 try {
2870 if (phone != null) {
2871 return phone.getDataActivationState();
2872 } else {
2873 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2874 }
2875 } finally {
2876 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002877 }
2878 }
2879
2880 /**
Wink Saville36469e72014-06-11 15:17:00 -07002881 * Returns the unread count of voicemails for a subId
2882 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002883 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002884 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2885 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002886 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002887 mApp, subId, callingPackage, callingFeatureId,
2888 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002889 return 0;
2890 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002891 final long identity = Binder.clearCallingIdentity();
2892 try {
2893 final Phone phone = getPhone(subId);
2894 if (phone != null) {
2895 return phone.getVoiceMessageCount();
2896 } else {
2897 return 0;
2898 }
2899 } finally {
2900 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002901 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002902 }
2903
2904 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002905 * returns true, if the device is in a state where both voice and data
2906 * are supported simultaneously. This can change based on location or network condition.
2907 */
2908 @Override
2909 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910 final long identity = Binder.clearCallingIdentity();
2911 try {
2912 final Phone phone = getPhone(subId);
2913 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2914 } finally {
2915 Binder.restoreCallingIdentity(identity);
2916 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002917 }
2918
2919 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002920 * Send the dialer code if called from the current default dialer or the caller has
2921 * carrier privilege.
2922 * @param inputCode The dialer code to send
2923 */
2924 @Override
2925 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002926 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002927 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002928 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2929 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002930 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08002931 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08002932 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002933 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002934
2935 final long identity = Binder.clearCallingIdentity();
2936 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002937 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938 } finally {
2939 Binder.restoreCallingIdentity(identity);
2940 }
fionaxu235cc5e2017-03-06 22:25:57 -08002941 }
2942
Pengquan Menga1bb6272018-09-06 09:59:22 -07002943 @Override
2944 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002945 if (!isActiveSubscription(subId)) {
2946 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2947 }
2948
Pengquan Menga1bb6272018-09-06 09:59:22 -07002949 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2950 }
2951
Brad Ebinger35c841c2018-10-01 10:40:55 -07002952 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002953 public boolean isInEmergencySmsMode() {
2954 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2955 final long identity = Binder.clearCallingIdentity();
2956 try {
2957 for (Phone phone : PhoneFactory.getPhones()) {
2958 if (phone.isInEmergencySmsMode()) {
2959 return true;
2960 }
2961 }
2962 } finally {
2963 Binder.restoreCallingIdentity(identity);
2964 }
2965 return false;
2966 }
2967
2968 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002969 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2970 throws RemoteException {
2971 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07002972 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2973 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2974 "IMS not available on device.");
2975 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002976 final long token = Binder.clearCallingIdentity();
2977 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002978 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002979 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002980 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002981 } catch (ImsException e) {
2982 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002983 } finally {
2984 Binder.restoreCallingIdentity(token);
2985 }
2986 }
2987
2988 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002989 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2990 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002991 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2992 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2993 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07002994 final long token = Binder.clearCallingIdentity();
2995 try {
2996 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2997 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2998 .removeRegistrationCallbackForSubscription(c, subId);
2999 } catch (ImsException e) {
3000 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3001 + "is inactive, ignoring unregister.");
3002 // If the subscription is no longer active, just return, since the callback
3003 // will already have been removed internally.
3004 } finally {
3005 Binder.restoreCallingIdentity(token);
3006 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003007 }
3008
Brad Ebinger774ba362019-10-22 17:36:18 -07003009 /**
3010 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3011 */
3012 @Override
3013 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3014 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3015 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3016 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3017 "IMS not available on device.");
3018 }
3019 final long token = Binder.clearCallingIdentity();
3020 try {
3021 Phone phone = getPhone(subId);
3022 if (phone == null) {
3023 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3024 + subId + "'");
3025 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3026 }
3027 phone.getImsRegistrationState(regState -> {
3028 try {
3029 consumer.accept((regState == null)
3030 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3031 } catch (RemoteException e) {
3032 // Ignore if the remote process is no longer available to call back.
3033 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3034 }
3035 });
3036 } finally {
3037 Binder.restoreCallingIdentity(token);
3038 }
3039 }
3040
3041 /**
3042 * Get the transport type for the IMS service registration state.
3043 */
3044 @Override
3045 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3046 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3047 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3048 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3049 "IMS not available on device.");
3050 }
3051 final long token = Binder.clearCallingIdentity();
3052 try {
3053 Phone phone = getPhone(subId);
3054 if (phone == null) {
3055 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3056 + subId + "'");
3057 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3058 }
3059 phone.getImsRegistrationTech(regTech -> {
3060 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3061 int regTechConverted = (regTech == null)
3062 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3063 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3064 regTechConverted);
3065 try {
3066 consumer.accept(regTechConverted);
3067 } catch (RemoteException e) {
3068 // Ignore if the remote process is no longer available to call back.
3069 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3070 }
3071 });
3072 } finally {
3073 Binder.restoreCallingIdentity(token);
3074 }
3075 }
3076
Brad Ebinger35c841c2018-10-01 10:40:55 -07003077 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003078 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3079 throws RemoteException {
3080 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003081 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3082 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3083 "IMS not available on device.");
3084 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003085 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3086 final long token = Binder.clearCallingIdentity();
3087 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003088 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003089 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003090 } catch (ImsException e) {
3091 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003092 } finally {
3093 Binder.restoreCallingIdentity(token);
3094 }
3095 }
3096
3097 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003098 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3099 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003100 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3101 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3102 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003103
3104 final long token = Binder.clearCallingIdentity();
3105 try {
3106 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3107 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003108 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003109 } catch (ImsException e) {
3110 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3111 + "is inactive, ignoring unregister.");
3112 // If the subscription is no longer active, just return, since the callback
3113 // will already have been removed internally.
3114 } finally {
3115 Binder.restoreCallingIdentity(token);
3116 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003117 }
3118
3119 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003120 public boolean isCapable(int subId, int capability, int regTech) {
3121 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003122 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3123 final long token = Binder.clearCallingIdentity();
3124 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003125 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003126 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003127 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003128 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3129 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003130 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003131 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3132 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003133 } finally {
3134 Binder.restoreCallingIdentity(token);
3135 }
3136 }
3137
3138 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003139 public boolean isAvailable(int subId, int capability, int regTech) {
3140 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003141 final long token = Binder.clearCallingIdentity();
3142 try {
3143 Phone phone = getPhone(subId);
3144 if (phone == null) return false;
3145 return phone.isImsCapabilityAvailable(capability, regTech);
3146 } finally {
3147 Binder.restoreCallingIdentity(token);
3148 }
3149 }
3150
Brad Ebinger77b832e2019-10-17 17:03:22 -07003151 /**
3152 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3153 * subscription.
3154 * @param subId The subscription to use to check the configuration.
3155 * @param callback The callback that will be used to send the result.
3156 * @param capability The MmTelFeature capability that will be used to send the result.
3157 * @param transportType The transport type of the MmTelFeature capability.
3158 */
3159 @Override
3160 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3161 int transportType) {
3162 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3163 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3164 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3165 "IMS not available on device.");
3166 }
3167 final long token = Binder.clearCallingIdentity();
3168 try {
3169 int slotId = getSlotIndex(subId);
3170 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3171 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3172 + subId + "'");
3173 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3174 }
3175 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3176 transportType, aBoolean -> {
3177 try {
3178 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3179 } catch (RemoteException e) {
3180 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3181 + "running. Ignore");
3182 }
3183 });
3184 } finally {
3185 Binder.restoreCallingIdentity(token);
3186 }
3187 }
3188
Brad Ebinger35c841c2018-10-01 10:40:55 -07003189 @Override
3190 public boolean isAdvancedCallingSettingEnabled(int subId) {
3191 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3192 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3193 final long token = Binder.clearCallingIdentity();
3194 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003195 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003196 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003197 } catch (ImsException e) {
3198 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003199 } finally {
3200 Binder.restoreCallingIdentity(token);
3201 }
3202 }
3203
3204 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003205 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003206 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003207 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003208 final long identity = Binder.clearCallingIdentity();
3209 try {
3210 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003211 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003212 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003213 } catch (ImsException e) {
3214 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003215 } finally {
3216 Binder.restoreCallingIdentity(identity);
3217 }
3218 }
3219
3220 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003221 public boolean isVtSettingEnabled(int subId) {
3222 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003223 final long identity = Binder.clearCallingIdentity();
3224 try {
3225 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003226 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3227 } catch (ImsException e) {
3228 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003229 } finally {
3230 Binder.restoreCallingIdentity(identity);
3231 }
3232 }
3233
3234 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003235 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003236 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003237 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003238 final long identity = Binder.clearCallingIdentity();
3239 try {
3240 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003241 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003242 } catch (ImsException e) {
3243 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003244 } finally {
3245 Binder.restoreCallingIdentity(identity);
3246 }
3247 }
3248
3249 @Override
3250 public boolean isVoWiFiSettingEnabled(int subId) {
3251 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3252 final long identity = Binder.clearCallingIdentity();
3253 try {
3254 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003255 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003256 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003257 } catch (ImsException e) {
3258 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003259 } finally {
3260 Binder.restoreCallingIdentity(identity);
3261 }
3262 }
3263
3264 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003265 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003267 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003268 final long identity = Binder.clearCallingIdentity();
3269 try {
3270 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003271 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003272 } catch (ImsException e) {
3273 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003274 } finally {
3275 Binder.restoreCallingIdentity(identity);
3276 }
3277 }
3278
3279 @Override
3280 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3281 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3282 final long identity = Binder.clearCallingIdentity();
3283 try {
3284 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003285 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003286 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003287 } catch (ImsException e) {
3288 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003289 } finally {
3290 Binder.restoreCallingIdentity(identity);
3291 }
3292 }
3293
3294 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003295 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003297 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003298 final long identity = Binder.clearCallingIdentity();
3299 try {
3300 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003301 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003302 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003303 } catch (ImsException e) {
3304 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003305 } finally {
3306 Binder.restoreCallingIdentity(identity);
3307 }
3308 }
3309
3310 @Override
3311 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3312 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3313 "setVoWiFiNonPersistent");
3314 final long identity = Binder.clearCallingIdentity();
3315 try {
3316 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003317 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003318 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003319 } catch (ImsException e) {
3320 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003321 } finally {
3322 Binder.restoreCallingIdentity(identity);
3323 }
3324 }
3325
3326 @Override
3327 public int getVoWiFiModeSetting(int subId) {
3328 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3329 final long identity = Binder.clearCallingIdentity();
3330 try {
3331 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003332 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003333 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003334 } catch (ImsException e) {
3335 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003336 } finally {
3337 Binder.restoreCallingIdentity(identity);
3338 }
3339 }
3340
3341 @Override
3342 public void setVoWiFiModeSetting(int subId, int mode) {
3343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3344 "setVoWiFiModeSetting");
3345 final long identity = Binder.clearCallingIdentity();
3346 try {
3347 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003348 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003349 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003350 } catch (ImsException e) {
3351 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003352 } finally {
3353 Binder.restoreCallingIdentity(identity);
3354 }
3355 }
3356
3357 @Override
3358 public int getVoWiFiRoamingModeSetting(int subId) {
3359 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3360 final long identity = Binder.clearCallingIdentity();
3361 try {
3362 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003363 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003364 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003365 } catch (ImsException e) {
3366 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003367 } finally {
3368 Binder.restoreCallingIdentity(identity);
3369 }
3370 }
3371
3372 @Override
3373 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3375 "setVoWiFiRoamingModeSetting");
3376 final long identity = Binder.clearCallingIdentity();
3377 try {
3378 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003379 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003380 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003381 } catch (ImsException e) {
3382 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003383 } finally {
3384 Binder.restoreCallingIdentity(identity);
3385 }
3386 }
3387
3388 @Override
3389 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3390 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3391 "setRttCapabilityEnabled");
3392 final long identity = Binder.clearCallingIdentity();
3393 try {
3394 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003395 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3396 } catch (ImsException e) {
3397 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003398 } finally {
3399 Binder.restoreCallingIdentity(identity);
3400 }
3401 }
3402
3403 @Override
3404 public boolean isTtyOverVolteEnabled(int subId) {
3405 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3406 final long identity = Binder.clearCallingIdentity();
3407 try {
3408 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003409 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003410 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003411 } catch (ImsException e) {
3412 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003413 } finally {
3414 Binder.restoreCallingIdentity(identity);
3415 }
3416 }
3417
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003418 @Override
3419 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3420 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3421 final long identity = Binder.clearCallingIdentity();
3422 try {
3423 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003424 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003425 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003426 } catch (ImsException e) {
3427 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003428 } finally {
3429 Binder.restoreCallingIdentity(identity);
3430 }
3431 }
3432
3433 @Override
3434 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3435 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3436 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003437 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3438 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3439 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003440 try {
3441 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003442 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003443 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003444 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003445 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3446 + "is inactive, ignoring unregister.");
3447 // If the subscription is no longer active, just return, since the callback will already
3448 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003449 } finally {
3450 Binder.restoreCallingIdentity(identity);
3451 }
3452 }
3453
allenwtsu99c623b2020-01-03 18:24:23 +08003454
3455 private void checkModifyPhoneStatePermission(int subId, String message) {
3456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3457 message);
3458 }
3459
3460 private boolean isImsProvisioningRequired(int subId, int capability,
3461 boolean isMmtelCapability) {
3462 Phone phone = getPhone(subId);
3463 if (phone == null) {
3464 loge("phone instance null for subid " + subId);
3465 return false;
3466 }
3467 if (isMmtelCapability) {
3468 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3469 return false;
3470 }
3471 } else {
3472 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3473 return false;
3474 }
3475 }
3476 return true;
3477 }
3478
3479 @Override
3480 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3481 boolean isProvisioned) {
3482 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3483
3484 final long identity = Binder.clearCallingIdentity();
3485 try {
3486 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3487 if (!isImsProvisioningRequired(subId, capability, false)) {
3488 return;
3489 }
3490
3491 // this capability requires provisioning, route to the correct API.
3492 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3493 switch (capability) {
3494 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3495 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3496 ims.setEabProvisioned(isProvisioned);
3497 break;
3498 default: {
3499 throw new IllegalArgumentException("Tried to set provisioning for "
3500 + "rcs capability '" + capability + "', which does not require "
3501 + "provisioning.");
3502 }
3503 }
3504 } finally {
3505 Binder.restoreCallingIdentity(identity);
3506 }
3507
3508 }
3509
3510
3511 @Override
3512 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3513 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3514 final long identity = Binder.clearCallingIdentity();
3515 try {
3516 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3517 if (!isImsProvisioningRequired(subId, capability, false)) {
3518 return true;
3519 }
3520
3521 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3522 switch (capability) {
3523 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3524 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3525 return ims.isEabProvisionedOnDevice();
3526
3527 default: {
3528 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3529 + "capability '" + capability + "', which does not require "
3530 + "provisioning.");
3531 }
3532 }
3533
3534 } finally {
3535 Binder.restoreCallingIdentity(identity);
3536 }
3537 }
3538
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003539 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003540 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3541 boolean isProvisioned) {
3542 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3543 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3544 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3545 }
allenwtsu99c623b2020-01-03 18:24:23 +08003546 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003547 final long identity = Binder.clearCallingIdentity();
3548 try {
3549 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003550 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003551 return;
3552 }
3553
3554 // this capability requires provisioning, route to the correct API.
3555 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3556 switch (capability) {
3557 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3558 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3559 ims.setVolteProvisioned(isProvisioned);
3560 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3561 ims.setWfcProvisioned(isProvisioned);
3562 }
3563 break;
3564 }
3565 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3566 // There is currently no difference in VT provisioning type.
3567 ims.setVtProvisioned(isProvisioned);
3568 break;
3569 }
3570 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3571 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3572 // change the capability of the feature instead if needed.
3573 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3574 == isProvisioned) {
3575 // No change in provisioning.
3576 return;
3577 }
3578 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3579 try {
3580 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003581 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003582 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3583 + ", Exception" + e.getMessage());
3584 }
3585 break;
3586 }
3587 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003588 throw new IllegalArgumentException("Tried to set provisioning for "
3589 + "MmTel capability '" + capability + "', which does not require "
3590 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003591 }
3592 }
3593
3594 } finally {
3595 Binder.restoreCallingIdentity(identity);
3596 }
3597 }
3598
3599 @Override
3600 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3601 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3602 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3603 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3604 }
3605 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3606 final long identity = Binder.clearCallingIdentity();
3607 try {
3608 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003609 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003610 return true;
3611 }
3612
3613 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3614 switch (capability) {
3615 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3616 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3617 return ims.isVolteProvisionedOnDevice();
3618 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3619 return ims.isWfcProvisionedOnDevice();
3620 }
3621 // This should never happen, since we are checking tech above to make sure it
3622 // is either LTE or IWLAN.
3623 throw new IllegalArgumentException("Invalid radio technology for voice "
3624 + "capability.");
3625 }
3626 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3627 // There is currently no difference in VT provisioning type.
3628 return ims.isVtProvisionedOnDevice();
3629 }
3630 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3631 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3632 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3633 }
3634 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003635 throw new IllegalArgumentException(
3636 "Tried to get provisioning for MmTel capability '" + capability
3637 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003638 }
3639 }
3640
3641 } finally {
3642 Binder.restoreCallingIdentity(identity);
3643 }
3644 }
3645
3646 @Override
3647 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3648 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3649 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3650 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3651 }
3652 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3653 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3654 return (provisionedBits & capability) > 0;
3655 }
3656
3657 @Override
3658 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3659 boolean isProvisioned) {
3660 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3661 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3662 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3663 }
3664 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3665 "setProvisioningStatusForCapability");
3666 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3667 // If the current provisioning status for capability already matches isProvisioned,
3668 // do nothing.
3669 if (((provisionedBits & capability) > 0) == isProvisioned) {
3670 return;
3671 }
3672 if (isProvisioned) {
3673 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3674 } else {
3675 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3676 }
3677 }
3678
3679 /**
3680 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3681 * technology. The bitfield should mirror the bitfield defined by
3682 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3683 */
3684 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3685 String key = getMmTelProvisioningKey(subId, tech);
3686 // Default is no capabilities are provisioned.
3687 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3688 }
3689
3690 /**
3691 * Sets the MmTel capability provisioning bitfield (defined by
3692 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3693 * technology specified.
3694 *
3695 * Note: This is a synchronous command and should not be called on UI thread.
3696 */
3697 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3698 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3699 String key = getMmTelProvisioningKey(subId, tech);
3700 editor.putInt(key, newField);
3701 editor.commit();
3702 }
3703
3704 private static String getMmTelProvisioningKey(int subId, int tech) {
3705 // resulting key is provision_ims_mmtel_{subId}_{tech}
3706 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3707 }
3708
3709 /**
3710 * Query CarrierConfig to see if the specified capability requires provisioning for the
3711 * carrier associated with the subscription id.
3712 */
3713 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3714 int capability) {
3715 CarrierConfigManager configManager = new CarrierConfigManager(context);
3716 PersistableBundle c = configManager.getConfigForSubId(subId);
3717 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003718 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003719 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3720 false);
3721 boolean requireVoiceVtProvisioning = c.getBoolean(
3722 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3723
3724 // First check to make sure that the capability requires provisioning.
3725 switch (capability) {
3726 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3727 // intentional fallthrough
3728 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3729 if (requireVoiceVtProvisioning) {
3730 // Voice and Video requires provisioning
3731 return true;
3732 }
3733 break;
3734 }
3735 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3736 if (requireUtProvisioning) {
3737 // UT requires provisioning
3738 return true;
3739 }
3740 break;
3741 }
3742 }
3743 return false;
3744 }
3745
allenwtsu99c623b2020-01-03 18:24:23 +08003746 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
3747 int capability) {
3748 CarrierConfigManager configManager = new CarrierConfigManager(context);
3749 PersistableBundle c = configManager.getConfigForSubId(subId);
3750
3751 boolean requireRcsProvisioning = c.getBoolean(
3752 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
3753
3754 // First check to make sure that the capability requires provisioning.
3755 switch (capability) {
3756 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3757 // intentional fallthrough
3758 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
3759 if (requireRcsProvisioning) {
3760 // OPTION or PRESENCE requires provisioning
3761 return true;
3762 }
3763 break;
3764 }
3765 }
3766 return false;
3767 }
3768
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003769 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003770 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003771 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3772 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3773 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003774 enforceReadPrivilegedPermission("getImsProvisioningInt");
3775 final long identity = Binder.clearCallingIdentity();
3776 try {
3777 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003778 int slotId = getSlotIndex(subId);
3779 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3780 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3781 + subId + "' for key:" + key);
3782 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3783 }
3784 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003785 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003786 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3787 + subId + "' for key:" + key);
3788 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003789 } finally {
3790 Binder.restoreCallingIdentity(identity);
3791 }
3792 }
3793
3794 @Override
3795 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003796 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3797 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3798 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003799 enforceReadPrivilegedPermission("getImsProvisioningString");
3800 final long identity = Binder.clearCallingIdentity();
3801 try {
3802 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003803 int slotId = getSlotIndex(subId);
3804 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3805 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3806 + subId + "' for key:" + key);
3807 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3808 }
3809 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003810 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003811 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3812 + subId + "' for key:" + key);
3813 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003814 } finally {
3815 Binder.restoreCallingIdentity(identity);
3816 }
3817 }
3818
3819 @Override
3820 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003821 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3822 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3823 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3825 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003826 final long identity = Binder.clearCallingIdentity();
3827 try {
3828 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003829 int slotId = getSlotIndex(subId);
3830 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3831 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3832 + subId + "' for key:" + key);
3833 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3834 }
3835 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003836 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003837 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3838 + "' for key:" + key);
3839 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003840 } finally {
3841 Binder.restoreCallingIdentity(identity);
3842 }
3843 }
3844
3845 @Override
3846 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003847 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3848 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3849 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003850 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3851 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003852 final long identity = Binder.clearCallingIdentity();
3853 try {
3854 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003855 int slotId = getSlotIndex(subId);
3856 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3857 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3858 + subId + "' for key:" + key);
3859 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3860 }
3861 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003862 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003863 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3864 + "' for key:" + key);
3865 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003866 } finally {
3867 Binder.restoreCallingIdentity(identity);
3868 }
3869 }
3870
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003871 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003872 int slotId = SubscriptionManager.getSlotIndex(subId);
3873 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003874 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3875 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003876 }
3877 return slotId;
3878 }
3879
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003880 private int getSlotIndex(int subId) {
3881 int slotId = SubscriptionManager.getSlotIndex(subId);
3882 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3883 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3884 }
3885 return slotId;
3886 }
3887
Wink Saville36469e72014-06-11 15:17:00 -07003888 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003889 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003890 */
3891 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003892 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3893 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003894 final int targetSdk = getTargetSdk(callingPackage);
3895 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003896 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003897 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003898 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003899 mApp, subId, callingPackage, callingFeatureId,
3900 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003901 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3902 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003903
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003904 final long identity = Binder.clearCallingIdentity();
3905 try {
3906 final Phone phone = getPhone(subId);
3907 if (phone != null) {
3908 return phone.getServiceState().getDataNetworkType();
3909 } else {
3910 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3911 }
3912 } finally {
3913 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003914 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003915 }
3916
3917 /**
3918 * Returns the data network type
3919 */
3920 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003921 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
3922 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
3923 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003924 }
3925
3926 /**
3927 * Returns the data network type for a subId
3928 */
3929 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003930 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
3931 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003932 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003933 mApp, subId, callingPackage, callingFeatureId,
3934 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003935 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3936 }
3937
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003938 final long identity = Binder.clearCallingIdentity();
3939 try {
3940 final Phone phone = getPhone(subId);
3941 if (phone != null) {
3942 return phone.getServiceState().getDataNetworkType();
3943 } else {
3944 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3945 }
3946 } finally {
3947 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003948 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003949 }
3950
3951 /**
Wink Saville36469e72014-06-11 15:17:00 -07003952 * Returns the Voice network type for a subId
3953 */
3954 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003955 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
3956 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003957 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003958 mApp, subId, callingPackage, callingFeatureId,
3959 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003960 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3961 }
3962
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003963 final long identity = Binder.clearCallingIdentity();
3964 try {
3965 final Phone phone = getPhone(subId);
3966 if (phone != null) {
3967 return phone.getServiceState().getVoiceNetworkType();
3968 } else {
3969 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3970 }
3971 } finally {
3972 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003973 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003974 }
3975
3976 /**
3977 * @return true if a ICC card is present
3978 */
3979 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003980 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003981 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3982 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003983 }
3984
3985 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003986 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003987 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003988 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003989 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003990 final long identity = Binder.clearCallingIdentity();
3991 try {
3992 final Phone phone = PhoneFactory.getPhone(slotIndex);
3993 if (phone != null) {
3994 return phone.getIccCard().hasIccCard();
3995 } else {
3996 return false;
3997 }
3998 } finally {
3999 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004000 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004001 }
4002
4003 /**
4004 * Return if the current radio is LTE on CDMA. This
4005 * is a tri-state return value as for a period of time
4006 * the mode may be unknown.
4007 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004008 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004009 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004010 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004011 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004012 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004013 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4014 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4015 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004016 }
4017
Sanket Padawe356d7632015-06-22 14:03:32 -07004018 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004019 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4020 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004021 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004022 mApp, subId, callingPackage, callingFeatureId,
4023 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004024 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4025 }
4026
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004027 final long identity = Binder.clearCallingIdentity();
4028 try {
4029 final Phone phone = getPhone(subId);
4030 if (phone == null) {
4031 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4032 } else {
4033 return phone.getLteOnCdmaMode();
4034 }
4035 } finally {
4036 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004037 }
Wink Saville36469e72014-06-11 15:17:00 -07004038 }
4039
Wink Saville36469e72014-06-11 15:17:00 -07004040 /**
4041 * {@hide}
4042 * Returns Default subId, 0 in the case of single standby.
4043 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004044 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004045 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004046 }
4047
Shishir Agrawala9f32182016-04-12 12:00:16 -07004048 private int getSlotForDefaultSubscription() {
4049 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4050 }
4051
Wink Savilleb564aae2014-10-23 10:18:09 -07004052 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004053 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004054 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004055
Pengquan Menge92a50d2018-09-21 15:54:48 -07004056 private boolean isActiveSubscription(int subId) {
4057 return mSubscriptionController.isActiveSubId(subId);
4058 }
4059
Ihab Awadf2177b72013-11-25 13:33:23 -08004060 /**
4061 * @see android.telephony.TelephonyManager.WifiCallingChoices
4062 */
4063 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004064 final long identity = Binder.clearCallingIdentity();
4065 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004066 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004067 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4068 getWhenToMakeWifiCallsDefaultPreference());
4069 } finally {
4070 Binder.restoreCallingIdentity(identity);
4071 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004072 }
4073
4074 /**
4075 * @see android.telephony.TelephonyManager.WifiCallingChoices
4076 */
4077 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004078 final long identity = Binder.clearCallingIdentity();
4079 try {
4080 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004081 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004082 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4083 } finally {
4084 Binder.restoreCallingIdentity(identity);
4085 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004086 }
4087
Sailesh Nepald1e68152013-12-12 19:08:02 -08004088 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004089 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004090 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004091 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004092
Jordan Liu4c733742019-02-28 12:03:40 -08004093 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4094 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4095 if (phoneId == -1) {
4096 throw new IllegalArgumentException("Given slot index: " + slotIndex
4097 + " does not correspond to an active phone");
4098 }
4099 return PhoneFactory.getPhone(phoneId);
4100 }
4101
Shishir Agrawal566b7612013-10-28 14:41:00 -07004102 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004103 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4104 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004105 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4106 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004107 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004108 if (DBG) {
4109 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4110 }
4111 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4112 p2);
4113 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004114
Jordan Liu4c733742019-02-28 12:03:40 -08004115
4116 @Override
4117 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4118 int slotIndex, String callingPackage, String aid, int p2) {
4119 enforceModifyPermission();
4120 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4121 if (DBG) {
4122 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4123 }
4124 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4125 callingPackage, aid, p2);
4126 }
4127
4128 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4129 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004130 final long identity = Binder.clearCallingIdentity();
4131 try {
4132 if (TextUtils.equals(ISDR_AID, aid)) {
4133 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004134 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4135 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004136 if (bestComponent == null
4137 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4138 loge("The calling package is not allowed to access ISD-R.");
4139 throw new SecurityException(
4140 "The calling package is not allowed to access ISD-R.");
4141 }
Derek Tan740e1672017-06-27 14:56:27 -07004142 }
Derek Tan740e1672017-06-27 14:56:27 -07004143
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004144 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004145 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4146 null /* workSource */);
4147 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004148 return response;
4149 } finally {
4150 Binder.restoreCallingIdentity(identity);
4151 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004152 }
4153
4154 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004155 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4157 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004158 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4159 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4160 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004161
Jordan Liu4c733742019-02-28 12:03:40 -08004162 @Override
4163 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4164 enforceModifyPermission();
4165 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4166 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4167 channel);
4168 }
4169
4170 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004171 final long identity = Binder.clearCallingIdentity();
4172 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004173 if (channel < 0) {
4174 return false;
4175 }
Jordan Liu4c733742019-02-28 12:03:40 -08004176 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4177 null /* workSource */);
4178 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004179 return success;
4180 } finally {
4181 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004182 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004183 }
4184
4185 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004186 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004187 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004188 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4189 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004190 if (DBG) {
4191 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4192 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4193 + p3 + " data=" + data);
4194 }
4195 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4196 command, p1, p2, p3, data);
4197 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004198
Jordan Liu4c733742019-02-28 12:03:40 -08004199 @Override
4200 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4201 int command, int p1, int p2, int p3, String data) {
4202 enforceModifyPermission();
4203 if (DBG) {
4204 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4205 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4206 + p3 + " data=" + data);
4207 }
4208 return iccTransmitApduLogicalChannelWithPermission(
4209 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4210 data);
4211 }
4212
4213 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4214 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004215 final long identity = Binder.clearCallingIdentity();
4216 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004217 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004218 return "";
4219 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004220
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004221 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004222 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4223 null /* workSource */);
4224 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004225
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004226 // Append the returned status code to the end of the response payload.
4227 String s = Integer.toHexString(
4228 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4229 if (response.payload != null) {
4230 s = IccUtils.bytesToHexString(response.payload) + s;
4231 }
4232 return s;
4233 } finally {
4234 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004235 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004236 }
Jake Hambye994d462014-02-03 13:10:13 -08004237
Evan Charltonc66da362014-05-16 14:06:40 -07004238 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004239 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4240 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004241 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4242 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004243 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004244 if (DBG) {
4245 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4246 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4247 }
4248 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4249 cla, command, p1, p2, p3, data);
4250 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004251
Jordan Liu4c733742019-02-28 12:03:40 -08004252 @Override
4253 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4254 int command, int p1, int p2, int p3, String data) {
4255 enforceModifyPermission();
4256 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4257 if (DBG) {
4258 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4259 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4260 + " data=" + data);
4261 }
4262
4263 return iccTransmitApduBasicChannelWithPermission(
4264 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4265 p2, p3, data);
4266 }
4267
4268 // open APDU basic channel assuming the caller has sufficient permissions
4269 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4270 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004271 final long identity = Binder.clearCallingIdentity();
4272 try {
4273 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4274 && TextUtils.equals(ISDR_AID, data)) {
4275 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004276 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4277 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004278 if (bestComponent == null
4279 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4280 loge("The calling package is not allowed to select ISD-R.");
4281 throw new SecurityException(
4282 "The calling package is not allowed to select ISD-R.");
4283 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004284 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004285
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004286 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004287 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4288 null /* workSource */);
4289 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004290
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004291 // Append the returned status code to the end of the response payload.
4292 String s = Integer.toHexString(
4293 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4294 if (response.payload != null) {
4295 s = IccUtils.bytesToHexString(response.payload) + s;
4296 }
4297 return s;
4298 } finally {
4299 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004300 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004301 }
4302
4303 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004304 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004305 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004306 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4307 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004308
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004309 final long identity = Binder.clearCallingIdentity();
4310 try {
4311 if (DBG) {
4312 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4313 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4314 }
4315
4316 IccIoResult response =
4317 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4318 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4319 subId);
4320
4321 if (DBG) {
4322 log("Exchange SIM_IO [R]" + response);
4323 }
4324
4325 byte[] result = null;
4326 int length = 2;
4327 if (response.payload != null) {
4328 length = 2 + response.payload.length;
4329 result = new byte[length];
4330 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4331 } else {
4332 result = new byte[length];
4333 }
4334
4335 result[length - 1] = (byte) response.sw2;
4336 result[length - 2] = (byte) response.sw1;
4337 return result;
4338 } finally {
4339 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004340 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004341 }
4342
Nathan Haroldb3014052017-01-25 15:57:32 -08004343 /**
4344 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4345 * on a particular subscription
4346 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004347 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4348 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004349 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004350 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004351 return null;
4352 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004353
4354 final long identity = Binder.clearCallingIdentity();
4355 try {
4356 if (appType != TelephonyManager.APPTYPE_USIM
4357 && appType != TelephonyManager.APPTYPE_SIM) {
4358 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4359 return null;
4360 }
4361 Object response = sendRequest(
4362 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4363 if (response instanceof String[]) {
4364 return (String[]) response;
4365 }
yincheng zhaod698b842019-09-06 17:06:54 -07004366 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004367 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004368 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004369 } finally {
4370 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004371 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004372 }
4373
yincheng zhaod698b842019-09-06 17:06:54 -07004374 /**
4375 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4376 * subscription.
4377 *
4378 * @param subId the id of the subscription.
4379 * @param appType the uicc app type, must be USIM or SIM.
4380 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4381 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004382 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004383 * @return number of fplmns that is successfully written to the SIM.
4384 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004385 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4386 String callingFeatureId) {
4387 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4388 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004389 if (DBG) logv("no permissions for setForbiddenplmns");
4390 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4391 }
4392 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4393 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4394 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4395 }
4396 if (fplmns == null) {
4397 throw new IllegalArgumentException("Fplmn List provided is null");
4398 }
4399 for (String fplmn : fplmns) {
4400 if (!CellIdentity.isValidPlmn(fplmn)) {
4401 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4402 }
4403 }
4404 final long identity = Binder.clearCallingIdentity();
4405 try {
4406 Object response = sendRequest(
4407 CMD_SET_FORBIDDEN_PLMNS,
4408 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4409 subId);
4410 return (int) response;
4411 } finally {
4412 Binder.restoreCallingIdentity(identity);
4413 }
4414 }
4415
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004416 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004417 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004418 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4419 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004420
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004421 final long identity = Binder.clearCallingIdentity();
4422 try {
4423 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4424 if (response.payload == null) {
4425 return "";
4426 }
Evan Charltonc66da362014-05-16 14:06:40 -07004427
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004428 // Append the returned status code to the end of the response payload.
4429 String s = Integer.toHexString(
4430 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4431 s = IccUtils.bytesToHexString(response.payload) + s;
4432 return s;
4433 } finally {
4434 Binder.restoreCallingIdentity(identity);
4435 }
Evan Charltonc66da362014-05-16 14:06:40 -07004436 }
4437
Jake Hambye994d462014-02-03 13:10:13 -08004438 /**
4439 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4440 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4441 *
4442 * @param itemID the ID of the item to read
4443 * @return the NV item as a String, or null on error.
4444 */
4445 @Override
4446 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004447 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004448 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4449 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004450
4451 final long identity = Binder.clearCallingIdentity();
4452 try {
4453 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004454 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004455 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4456 return value;
4457 } finally {
4458 Binder.restoreCallingIdentity(identity);
4459 }
Jake Hambye994d462014-02-03 13:10:13 -08004460 }
4461
4462 /**
4463 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4464 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4465 *
4466 * @param itemID the ID of the item to read
4467 * @param itemValue the value to write, as a String
4468 * @return true on success; false on any failure
4469 */
4470 @Override
4471 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004472 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004473 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4474 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004475
4476 final long identity = Binder.clearCallingIdentity();
4477 try {
4478 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4479 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004480 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004481 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4482 return success;
4483 } finally {
4484 Binder.restoreCallingIdentity(identity);
4485 }
Jake Hambye994d462014-02-03 13:10:13 -08004486 }
4487
4488 /**
4489 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4490 * Used for device configuration by some CDMA operators.
4491 *
4492 * @param preferredRoamingList byte array containing the new PRL
4493 * @return true on success; false on any failure
4494 */
4495 @Override
4496 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004497 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4498 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004499
4500 final long identity = Binder.clearCallingIdentity();
4501 try {
4502 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4503 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4504 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4505 return success;
4506 } finally {
4507 Binder.restoreCallingIdentity(identity);
4508 }
Jake Hambye994d462014-02-03 13:10:13 -08004509 }
4510
4511 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004512 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004513 * Used for device configuration by some CDMA operators.
4514 *
chen xu6dac5ab2018-10-26 17:39:23 -07004515 * @param slotIndex - device slot.
4516 *
Jake Hambye994d462014-02-03 13:10:13 -08004517 * @return true on success; false on any failure
4518 */
4519 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004520 public boolean resetModemConfig(int slotIndex) {
4521 Phone phone = PhoneFactory.getPhone(slotIndex);
4522 if (phone != null) {
4523 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4524 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004525
chen xu6dac5ab2018-10-26 17:39:23 -07004526 final long identity = Binder.clearCallingIdentity();
4527 try {
4528 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4529 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4530 return success;
4531 } finally {
4532 Binder.restoreCallingIdentity(identity);
4533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004534 }
chen xu6dac5ab2018-10-26 17:39:23 -07004535 return false;
4536 }
4537
4538 /**
4539 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4540 *
4541 * @param slotIndex - device slot.
4542 *
4543 * @return true on success; false on any failure
4544 */
4545 @Override
4546 public boolean rebootModem(int slotIndex) {
4547 Phone phone = PhoneFactory.getPhone(slotIndex);
4548 if (phone != null) {
4549 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4550 mApp, phone.getSubId(), "rebootModem");
4551
4552 final long identity = Binder.clearCallingIdentity();
4553 try {
4554 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4555 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4556 return success;
4557 } finally {
4558 Binder.restoreCallingIdentity(identity);
4559 }
4560 }
4561 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004562 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004563
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004564 public String[] getPcscfAddress(String apnType, String callingPackage,
4565 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004566 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004567 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4568 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004569 return new String[0];
4570 }
4571
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004572 final long identity = Binder.clearCallingIdentity();
4573 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004574 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004575 } finally {
4576 Binder.restoreCallingIdentity(identity);
4577 }
Wink Saville36469e72014-06-11 15:17:00 -07004578 }
4579
Brad Ebinger51f743a2017-01-23 13:50:20 -08004580 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004581 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4582 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004583 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004584 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004585 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004586
4587 final long identity = Binder.clearCallingIdentity();
4588 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004589 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004590 // may happen if the device does not support IMS.
4591 return;
4592 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004593 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004594 } finally {
4595 Binder.restoreCallingIdentity(identity);
4596 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004597 }
4598
4599 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004600 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4601 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004602 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004603 public void disableIms(int slotId) {
4604 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004605
4606 final long identity = Binder.clearCallingIdentity();
4607 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004608 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004609 // may happen if the device does not support IMS.
4610 return;
4611 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004612 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004613 } finally {
4614 Binder.restoreCallingIdentity(identity);
4615 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004616 }
4617
4618 /**
4619 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4620 * feature or {@link null} if the service is not available. If the feature is available, the
4621 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4622 */
4623 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004624 IImsServiceFeatureCallback callback) {
4625 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004626
4627 final long identity = Binder.clearCallingIdentity();
4628 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004629 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004630 // may happen if the device does not support IMS.
4631 return null;
4632 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004633 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004634 } finally {
4635 Binder.restoreCallingIdentity(identity);
4636 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004637 }
4638
4639 /**
4640 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4641 * feature during emergency calling or {@link null} if the service is not available. If the
4642 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4643 * listener for feature updates.
4644 */
4645 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4646 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004647
4648 final long identity = Binder.clearCallingIdentity();
4649 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004650 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004651 // may happen if the device does not support IMS.
4652 return null;
4653 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004654 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004655 } finally {
4656 Binder.restoreCallingIdentity(identity);
4657 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004658 }
4659
Brad Ebinger5f64b052017-12-14 14:26:15 -08004660 /**
4661 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004662 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004663 */
4664 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4665 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004666
4667 final long identity = Binder.clearCallingIdentity();
4668 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004669 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004670 // may happen if the device does not support IMS.
4671 return null;
4672 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004673 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004674 } finally {
4675 Binder.restoreCallingIdentity(identity);
4676 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004677 }
4678
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004679 /**
4680 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004681 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004682 */
4683 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4684 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004685
4686 final long identity = Binder.clearCallingIdentity();
4687 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004688 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004689 // may happen if the device does not support IMS.
4690 return null;
4691 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004692 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004693 } finally {
4694 Binder.restoreCallingIdentity(identity);
4695 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004696 }
4697
Brad Ebinger884c07b2018-02-15 16:17:40 -08004698 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004699 * Sets the ImsService Package Name that Telephony will bind to.
4700 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08004701 * @param slotIndex the slot ID that the ImsService should bind for.
4702 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004703 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004704 * @param featureTypes An integer array of feature types associated with a packageName.
4705 * @param packageName The name of the package that the current configuration will be replaced
4706 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004707 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004708 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004709 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4710 int[] featureTypes, String packageName) {
4711 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4712 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004713 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4714 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08004715 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004716
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004717 final long identity = Binder.clearCallingIdentity();
4718 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004719 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004720 // may happen if the device does not support IMS.
4721 return false;
4722 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004723 Map<Integer, String> featureConfig = new HashMap<>();
4724 for (int featureType : featureTypes) {
4725 featureConfig.put(featureType, packageName);
4726 }
4727 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4728 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004729 } finally {
4730 Binder.restoreCallingIdentity(identity);
4731 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004732 }
4733
4734 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08004735 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004736 *
4737 * @param slotId The slot that the ImsService is associated with.
4738 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4739 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004740 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004741 * @return the package name of the ImsService configuration.
4742 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004743 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4744 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004745 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08004746 TelephonyPermissions
4747 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4748 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4749 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004750
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004751 final long identity = Binder.clearCallingIdentity();
4752 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004753 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004754 // may happen if the device does not support IMS.
4755 return "";
4756 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004757 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004758 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4759 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004760 } finally {
4761 Binder.restoreCallingIdentity(identity);
4762 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004763 }
4764
Brad Ebinger77b832e2019-10-17 17:03:22 -07004765 /**
4766 * Get the MmTelFeature state associated with the requested subscription id.
4767 * @param subId The subscription that the MmTelFeature is associated with.
4768 * @param callback A callback with an integer containing the
4769 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4770 */
4771 @Override
4772 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4773 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4774 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4775 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4776 "IMS not available on device.");
4777 }
4778 final long token = Binder.clearCallingIdentity();
4779 try {
4780 int slotId = getSlotIndex(subId);
4781 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4782 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4783 + subId + "'");
4784 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4785 }
4786 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4787 try {
4788 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4789 } catch (RemoteException e) {
4790 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4791 + "Ignore");
4792 }
4793 });
4794 } finally {
4795 Binder.restoreCallingIdentity(token);
4796 }
4797 }
4798
Wink Saville36469e72014-06-11 15:17:00 -07004799 public void setImsRegistrationState(boolean registered) {
4800 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004801
4802 final long identity = Binder.clearCallingIdentity();
4803 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004804 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004805 } finally {
4806 Binder.restoreCallingIdentity(identity);
4807 }
Wink Saville36469e72014-06-11 15:17:00 -07004808 }
4809
4810 /**
Stuart Scott54788802015-03-30 13:18:01 -07004811 * Set the network selection mode to automatic.
4812 *
4813 */
4814 @Override
4815 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004816 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4817 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004818
Pengquan Menge92a50d2018-09-21 15:54:48 -07004819 if (!isActiveSubscription(subId)) {
4820 return;
4821 }
4822
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004823 final long identity = Binder.clearCallingIdentity();
4824 try {
4825 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4826 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4827 } finally {
4828 Binder.restoreCallingIdentity(identity);
4829 }
Stuart Scott54788802015-03-30 13:18:01 -07004830 }
4831
Pengquan Mengea84e042018-09-20 14:57:26 -07004832 /**
4833 * Ask the radio to connect to the input network and change selection mode to manual.
4834 *
4835 * @param subId the id of the subscription.
4836 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4837 * the operator to attach to.
4838 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4839 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4840 * normal network selection next time.
4841 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004842 */
4843 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004844 public boolean setNetworkSelectionModeManual(
4845 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004846 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4847 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004848
4849 if (!isActiveSubscription(subId)) {
4850 return false;
4851 }
4852
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004853 final long identity = Binder.clearCallingIdentity();
4854 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004855 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004856 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004857 if (DBG) {
4858 log("setNetworkSelectionModeManual: subId: " + subId
4859 + " operator: " + operatorInfo);
4860 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004861 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4862 } finally {
4863 Binder.restoreCallingIdentity(identity);
4864 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004865 }
4866
4867 /**
4868 * Scans for available networks.
4869 */
4870 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004871 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4872 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4874 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004875 LocationAccessPolicy.LocationPermissionResult locationResult =
4876 LocationAccessPolicy.checkLocationPermission(mApp,
4877 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4878 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004879 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004880 .setCallingPid(Binder.getCallingPid())
4881 .setCallingUid(Binder.getCallingUid())
4882 .setMethod("getCellNetworkScanResults")
4883 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4884 .build());
4885 switch (locationResult) {
4886 case DENIED_HARD:
4887 throw new SecurityException("Not allowed to access scan results -- location");
4888 case DENIED_SOFT:
4889 return null;
4890 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004891
Pengquan Menga1bb6272018-09-06 09:59:22 -07004892 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004893 try {
4894 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004895 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004896 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004897 } finally {
4898 Binder.restoreCallingIdentity(identity);
4899 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004900 }
4901
4902 /**
yinxub1bed742017-04-17 11:45:04 -07004903 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004904 *
yinxub1bed742017-04-17 11:45:04 -07004905 * @param subId id of the subscription
4906 * @param request contains the radio access networks with bands/channels to scan
4907 * @param messenger callback messenger for scan results or errors
4908 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004909 * @return the id of the requested scan which can be used to stop the scan.
4910 */
4911 @Override
4912 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004913 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004914 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4915 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004916 LocationAccessPolicy.LocationPermissionResult locationResult =
4917 LocationAccessPolicy.checkLocationPermission(mApp,
4918 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4919 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004920 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004921 .setCallingPid(Binder.getCallingPid())
4922 .setCallingUid(Binder.getCallingUid())
4923 .setMethod("requestNetworkScan")
4924 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4925 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004926 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004927 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004928 if (e != null) {
4929 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4930 throw e;
4931 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004932 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004933 return TelephonyScanManager.INVALID_SCAN_ID;
4934 }
4935 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004936 }
Hall Liu912dfd32019-04-25 14:02:26 -07004937 int callingUid = Binder.getCallingUid();
4938 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004939 final long identity = Binder.clearCallingIdentity();
4940 try {
4941 return mNetworkScanRequestTracker.startNetworkScan(
4942 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004943 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004944 } finally {
4945 Binder.restoreCallingIdentity(identity);
4946 }
yinxu504e1392017-04-12 16:03:22 -07004947 }
4948
Hall Liub2ac8ef2019-02-28 15:56:23 -08004949 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004950 NetworkScanRequest request, int subId) {
4951 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4952 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4953 boolean hasNetworkScanPermission =
4954 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4955 == PERMISSION_GRANTED;
4956
4957 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4958 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4959 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004960 }
4961
4962 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4963 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004964 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4965 return new SecurityException("Specific channels must not be"
4966 + " scanned without location access.");
4967 }
4968 }
4969 }
4970
Hall Liub2ac8ef2019-02-28 15:56:23 -08004971 return null;
4972 }
4973
yinxu504e1392017-04-12 16:03:22 -07004974 /**
4975 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004976 *
4977 * @param subId id of the subscription
4978 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004979 */
4980 @Override
4981 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4983 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004984
Hall Liu912dfd32019-04-25 14:02:26 -07004985 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004986 final long identity = Binder.clearCallingIdentity();
4987 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004988 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004989 } finally {
4990 Binder.restoreCallingIdentity(identity);
4991 }
yinxu504e1392017-04-12 16:03:22 -07004992 }
4993
4994 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004995 * Get the calculated preferred network type.
4996 * Used for debugging incorrect network type.
4997 *
4998 * @return the preferred network type, defined in RILConstants.java.
4999 */
5000 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005001 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005002 final Phone defaultPhone = getDefaultPhone();
5003 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005004 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005005 return RILConstants.PREFERRED_NETWORK_MODE;
5006 }
5007
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005008 final long identity = Binder.clearCallingIdentity();
5009 try {
5010 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005011 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005012 } finally {
5013 Binder.restoreCallingIdentity(identity);
5014 }
Junda Liu84d15a22014-07-02 11:21:04 -07005015 }
5016
5017 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005018 * Get the preferred network type.
5019 * Used for device configuration by some CDMA operators.
5020 *
5021 * @return the preferred network type, defined in RILConstants.java.
5022 */
5023 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005024 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005025 TelephonyPermissions
5026 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5027 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005028
5029 final long identity = Binder.clearCallingIdentity();
5030 try {
5031 if (DBG) log("getPreferredNetworkType");
5032 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5033 int networkType = (result != null ? result[0] : -1);
5034 if (DBG) log("getPreferredNetworkType: " + networkType);
5035 return networkType;
5036 } finally {
5037 Binder.restoreCallingIdentity(identity);
5038 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005039 }
5040
5041 /**
5042 * Set the preferred network type.
5043 * Used for device configuration by some CDMA operators.
5044 *
5045 * @param networkType the preferred network type, defined in RILConstants.java.
5046 * @return true on success; false on any failure.
5047 */
5048 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005049 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005050 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5051 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005052
5053 final long identity = Binder.clearCallingIdentity();
5054 try {
5055 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
5056 Boolean success = (Boolean) sendRequest(
5057 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5058 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5059 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005060 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005061 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5062 }
5063 return success;
5064 } finally {
5065 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005066 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005067 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005068
5069 /**
Miaoa84611c2019-03-15 09:21:10 +08005070 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005071 *
Miaoa84611c2019-03-15 09:21:10 +08005072 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005073 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005074 * @hide
5075 */
5076 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005077 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005078 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005079 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005080 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005081 try {
Miaoa84611c2019-03-15 09:21:10 +08005082 if (phone != null) {
5083 return phone.hasMatchedTetherApnSetting();
5084 } else {
5085 return false;
5086 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005087 } finally {
5088 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005089 }
Junda Liu475951f2014-11-07 16:45:03 -08005090 }
5091
5092 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005093 * Set mobile data enabled
5094 * Used by the user through settings etc to turn on/off mobile data
5095 *
5096 * @param enable {@code true} turn turn data on, else {@code false}
5097 */
5098 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005099 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005100 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5101 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005102
5103 final long identity = Binder.clearCallingIdentity();
5104 try {
5105 int phoneId = mSubscriptionController.getPhoneId(subId);
5106 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5107 Phone phone = PhoneFactory.getPhone(phoneId);
5108 if (phone != null) {
5109 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005110 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005111 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005112 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005113 }
5114 } finally {
5115 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005116 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005117 }
5118
5119 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005120 * Get the user enabled state of Mobile Data.
5121 *
5122 * TODO: remove and use isUserDataEnabled.
5123 * This can't be removed now because some vendor codes
5124 * calls through ITelephony directly while they should
5125 * use TelephonyManager.
5126 *
5127 * @return true on enabled
5128 */
5129 @Override
5130 public boolean getDataEnabled(int subId) {
5131 return isUserDataEnabled(subId);
5132 }
5133
5134 /**
5135 * Get whether mobile data is enabled per user setting.
5136 *
5137 * There are other factors deciding whether mobile data is actually enabled, but they are
5138 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005139 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005140 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005141 *
5142 * @return {@code true} if data is enabled else {@code false}
5143 */
5144 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005145 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005146 try {
5147 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5148 null);
5149 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5151 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005152 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005153
5154 final long identity = Binder.clearCallingIdentity();
5155 try {
5156 int phoneId = mSubscriptionController.getPhoneId(subId);
5157 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5158 Phone phone = PhoneFactory.getPhone(phoneId);
5159 if (phone != null) {
5160 boolean retVal = phone.isUserDataEnabled();
5161 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5162 return retVal;
5163 } else {
5164 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5165 return false;
5166 }
5167 } finally {
5168 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005169 }
5170 }
5171
5172 /**
5173 * Get whether mobile data is enabled.
5174 *
5175 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5176 * whether mobile data is actually enabled.
5177 *
5178 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5179 *
5180 * @return {@code true} if data is enabled else {@code false}
5181 */
5182 @Override
5183 public boolean isDataEnabled(int subId) {
5184 try {
5185 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5186 null);
5187 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005188 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5189 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005190 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005191
5192 final long identity = Binder.clearCallingIdentity();
5193 try {
5194 int phoneId = mSubscriptionController.getPhoneId(subId);
5195 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5196 Phone phone = PhoneFactory.getPhone(phoneId);
5197 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005198 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005199 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5200 return retVal;
5201 } else {
5202 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5203 return false;
5204 }
5205 } finally {
5206 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005207 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005208 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005209
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005210 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5211 Phone phone) {
5212 //load access rules from carrier configs, and check those as well: b/139133814
5213 SubscriptionController subController = SubscriptionController.getInstance();
5214 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5215 || subController == null) return privilegeFromSim;
5216
5217 int uid = Binder.getCallingUid();
5218 PackageManager pkgMgr = phone.getContext().getPackageManager();
5219 String[] packages = pkgMgr.getPackagesForUid(uid);
5220
5221 final long identity = Binder.clearCallingIdentity();
5222 try {
5223 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5224 SubscriptionManager subManager = (SubscriptionManager)
5225 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5226 for (String pkg : packages) {
5227 if (subManager.canManageSubscription(subInfo, pkg)) {
5228 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5229 }
5230 }
5231 return privilegeFromSim;
5232 } finally {
5233 Binder.restoreCallingIdentity(identity);
5234 }
5235 }
5236
5237 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5238 String pkgName) {
5239 //load access rules from carrier configs, and check those as well: b/139133814
5240 SubscriptionController subController = SubscriptionController.getInstance();
5241 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5242 || subController == null) return privilegeFromSim;
5243
5244 final long identity = Binder.clearCallingIdentity();
5245 try {
5246 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5247 SubscriptionManager subManager = (SubscriptionManager)
5248 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5249 return subManager.canManageSubscription(subInfo, pkgName)
5250 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5251 } finally {
5252 Binder.restoreCallingIdentity(identity);
5253 }
5254 }
5255
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005256 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005257 public int getCarrierPrivilegeStatus(int subId) {
5258 final Phone phone = getPhone(subId);
5259 if (phone == null) {
5260 loge("getCarrierPrivilegeStatus: Invalid subId");
5261 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5262 }
5263 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005264 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005265 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005266 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5267 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005268
5269 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5270 card.getCarrierPrivilegeStatusForCurrentTransaction(
5271 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005272 }
Junda Liu29340342014-07-10 15:23:27 -07005273
5274 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005275 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005276 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005277 final Phone phone = getPhone(subId);
5278 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005279 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005280 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5281 }
5282 UiccProfile profile =
5283 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5284 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005285 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005286 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5287 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005288 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005289 profile.getCarrierPrivilegeStatusForUid(
5290 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005291 }
5292
5293 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005294 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5295 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005296 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005297 }
5298
5299 int phoneId = SubscriptionManager.getPhoneId(subId);
5300 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005301 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005302 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005303 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5304 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005305 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5306 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5307 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005308 }
5309
5310 @Override
5311 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005312 if (TextUtils.isEmpty(pkgName))
5313 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005314 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5315 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5316 UiccCard card = UiccController.getInstance().getUiccCard(i);
5317 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005318 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005319 continue;
5320 }
5321
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005322 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5323 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5324 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005325 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5326 break;
5327 }
5328 }
5329
5330 return result;
Junda Liu29340342014-07-10 15:23:27 -07005331 }
Derek Tan89e89d42014-07-08 17:00:10 -07005332
5333 @Override
Junda Liue64de782015-04-16 17:19:16 -07005334 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5335 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5336 loge("phoneId " + phoneId + " is not valid.");
5337 return null;
5338 }
5339 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005340 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005341 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005342 return null ;
5343 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005344 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005345 }
5346
Amith Yamasani6e118872016-02-19 12:53:51 -08005347 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005348 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005349 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005350 List<String> privilegedPackages = new ArrayList<>();
5351 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005352 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5353 // has UICC in that slot.
5354 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005355 if (card.hasCarrierPrivilegeRules()) {
5356 if (packages == null) {
5357 // Only check packages in user 0 for now
5358 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005359 PackageManager.MATCH_DISABLED_COMPONENTS
5360 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005361 | PackageManager.GET_SIGNING_CERTIFICATES,
5362 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005363 }
5364 for (int p = packages.size() - 1; p >= 0; p--) {
5365 PackageInfo pkgInfo = packages.get(p);
5366 if (pkgInfo != null && pkgInfo.packageName != null
5367 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005368 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005369 privilegedPackages.add(pkgInfo.packageName);
5370 }
5371 }
5372 }
5373 }
5374 return privilegedPackages;
5375 }
5376
chen xuf7e9fe82019-05-09 19:31:02 -07005377 @Override
5378 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005379 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5380
5381 final long identity = Binder.clearCallingIdentity();
5382
chen xuf7e9fe82019-05-09 19:31:02 -07005383 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005384 try {
5385 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5386 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5387 }
5388 } finally {
5389 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005390 }
5391 return privilegedPackages;
5392 }
5393
Wink Savilleb564aae2014-10-23 10:18:09 -07005394 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005395 final Phone phone = getPhone(subId);
5396 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005397 if (card == null) {
5398 loge("getIccId: No UICC");
5399 return null;
5400 }
5401 String iccId = card.getIccId();
5402 if (TextUtils.isEmpty(iccId)) {
5403 loge("getIccId: ICC ID is null or empty.");
5404 return null;
5405 }
5406 return iccId;
5407 }
5408
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005409 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005410 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5411 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08005412 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005413 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005414
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005415 final long identity = Binder.clearCallingIdentity();
5416 try {
5417 final String iccId = getIccId(subId);
5418 final Phone phone = getPhone(subId);
5419 if (phone == null) {
5420 return false;
5421 }
5422 final String subscriberId = phone.getSubscriberId();
5423
5424 if (DBG_MERGE) {
5425 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5426 + subscriberId + " to " + number);
5427 }
5428
5429 if (TextUtils.isEmpty(iccId)) {
5430 return false;
5431 }
5432
5433 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5434
5435 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5436 if (alphaTag == null) {
5437 editor.remove(alphaTagPrefKey);
5438 } else {
5439 editor.putString(alphaTagPrefKey, alphaTag);
5440 }
5441
5442 // Record both the line number and IMSI for this ICCID, since we need to
5443 // track all merged IMSIs based on line number
5444 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5445 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5446 if (number == null) {
5447 editor.remove(numberPrefKey);
5448 editor.remove(subscriberPrefKey);
5449 } else {
5450 editor.putString(numberPrefKey, number);
5451 editor.putString(subscriberPrefKey, subscriberId);
5452 }
5453
5454 editor.commit();
5455 return true;
5456 } finally {
5457 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005458 }
Derek Tan7226c842014-07-02 17:42:23 -07005459 }
5460
5461 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005462 public String getLine1NumberForDisplay(int subId, String callingPackage,
5463 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005464 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005465 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005466 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005467 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005468 return null;
5469 }
Derek Tan97ebb422014-09-05 16:55:38 -07005470
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005471 final long identity = Binder.clearCallingIdentity();
5472 try {
5473 String iccId = getIccId(subId);
5474 if (iccId != null) {
5475 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5476 if (DBG_MERGE) {
5477 log("getLine1NumberForDisplay returning "
5478 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5479 }
5480 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005481 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005482 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5483 return null;
5484 } finally {
5485 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005486 }
Derek Tan7226c842014-07-02 17:42:23 -07005487 }
5488
5489 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005490 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5491 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005492 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005493 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005494 return null;
5495 }
Derek Tan97ebb422014-09-05 16:55:38 -07005496
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005497 final long identity = Binder.clearCallingIdentity();
5498 try {
5499 String iccId = getIccId(subId);
5500 if (iccId != null) {
5501 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5502 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5503 }
5504 return null;
5505 } finally {
5506 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005507 }
Derek Tan7226c842014-07-02 17:42:23 -07005508 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005509
5510 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005511 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5512 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005513 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5514 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005515 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005516 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005517 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005518 return null;
5519 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005520
Jordan Liub49b04b2019-05-06 14:45:15 -07005521 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5522 // the process, where TelephonyManager was instantiated.
5523 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005524 final long identity = Binder.clearCallingIdentity();
5525 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005526 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005527 final TelephonyManager tele = TelephonyManager.from(context);
5528 final SubscriptionManager sub = SubscriptionManager.from(context);
5529
5530 // Figure out what subscribers are currently active
5531 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005532
Jordan Liub49b04b2019-05-06 14:45:15 -07005533 // Only consider subs which match the current subId
5534 // This logic can be simplified. See b/131189269 for progress.
5535 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005536 activeSubscriberIds.add(tele.getSubscriberId(subId));
5537 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005538
5539 // First pass, find a number override for an active subscriber
5540 String mergeNumber = null;
5541 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5542 for (String key : prefs.keySet()) {
5543 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5544 final String subscriberId = (String) prefs.get(key);
5545 if (activeSubscriberIds.contains(subscriberId)) {
5546 final String iccId = key.substring(
5547 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5548 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5549 mergeNumber = (String) prefs.get(numberKey);
5550 if (DBG_MERGE) {
5551 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5552 + " for active subscriber " + subscriberId);
5553 }
5554 if (!TextUtils.isEmpty(mergeNumber)) {
5555 break;
5556 }
5557 }
5558 }
5559 }
5560
5561 // Shortcut when no active merged subscribers
5562 if (TextUtils.isEmpty(mergeNumber)) {
5563 return null;
5564 }
5565
5566 // Second pass, find all subscribers under that line override
5567 final ArraySet<String> result = new ArraySet<>();
5568 for (String key : prefs.keySet()) {
5569 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5570 final String number = (String) prefs.get(key);
5571 if (mergeNumber.equals(number)) {
5572 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5573 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5574 final String subscriberId = (String) prefs.get(subscriberKey);
5575 if (!TextUtils.isEmpty(subscriberId)) {
5576 result.add(subscriberId);
5577 }
5578 }
5579 }
5580 }
5581
5582 final String[] resultArray = result.toArray(new String[result.size()]);
5583 Arrays.sort(resultArray);
5584 if (DBG_MERGE) {
5585 Slog.d(LOG_TAG,
5586 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5587 }
5588 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005589 } finally {
5590 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005591 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005592 }
5593
5594 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005595 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5596 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5597
5598 final long identity = Binder.clearCallingIdentity();
5599 try {
5600 final TelephonyManager telephonyManager = mApp.getSystemService(
5601 TelephonyManager.class);
5602 String subscriberId = telephonyManager.getSubscriberId(subId);
5603 if (subscriberId == null) {
5604 if (DBG) {
5605 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5606 + subId);
5607 }
5608 return null;
5609 }
5610
5611 final SubscriptionInfo info = SubscriptionController.getInstance()
5612 .getSubscriptionInfo(subId);
5613 final ParcelUuid groupUuid = info.getGroupUuid();
5614 // If it doesn't belong to any group, return just subscriberId of itself.
5615 if (groupUuid == null) {
5616 return new String[]{subscriberId};
5617 }
5618
5619 // Get all subscriberIds from the group.
5620 final List<String> mergedSubscriberIds = new ArrayList<>();
5621 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005622 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5623 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07005624 for (SubscriptionInfo subInfo : groupInfos) {
5625 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5626 if (subscriberId != null) {
5627 mergedSubscriberIds.add(subscriberId);
5628 }
5629 }
5630
5631 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5632 } finally {
5633 Binder.restoreCallingIdentity(identity);
5634
5635 }
5636 }
5637
5638 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005639 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08005640 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005641 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005642
5643 final long identity = Binder.clearCallingIdentity();
5644 try {
5645 final Phone phone = getPhone(subId);
5646 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5647 } finally {
5648 Binder.restoreCallingIdentity(identity);
5649 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005650 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005651
5652 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005653 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005654 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5655 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08005656 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5657 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005658
5659 final long identity = Binder.clearCallingIdentity();
5660 try {
5661 final Phone phone = getPhone(subId);
5662 if (phone == null) {
5663 return false;
5664 }
5665 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5666 cdmaNonRoamingList);
5667 } finally {
5668 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005669 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005670 }
5671
5672 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005673 @Deprecated
5674 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5675 enforceModifyPermission();
5676
5677 int returnValue = 0;
5678 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005679 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005680 if(result.exception == null) {
5681 if (result.result != null) {
5682 byte[] responseData = (byte[])(result.result);
5683 if(responseData.length > oemResp.length) {
5684 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5685 responseData.length + "bytes. Buffer Size is " +
5686 oemResp.length + "bytes.");
5687 }
5688 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5689 returnValue = responseData.length;
5690 }
5691 } else {
5692 CommandException ex = (CommandException) result.exception;
5693 returnValue = ex.getCommandError().ordinal();
5694 if(returnValue > 0) returnValue *= -1;
5695 }
5696 } catch (RuntimeException e) {
5697 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5698 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5699 if(returnValue > 0) returnValue *= -1;
5700 }
5701
5702 return returnValue;
5703 }
5704
5705 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005706 public void setRadioCapability(RadioAccessFamily[] rafs) {
5707 try {
5708 ProxyController.getInstance().setRadioCapability(rafs);
5709 } catch (RuntimeException e) {
5710 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5711 }
5712 }
5713
5714 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005715 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005716 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005717 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005718 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005719 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005720 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005721 final long identity = Binder.clearCallingIdentity();
5722 try {
chen xub97461a2018-10-26 14:17:57 -07005723 TelephonyPermissions
5724 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5725 mApp, phone.getSubId(), "getRadioAccessFamily");
5726 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005727 } finally {
5728 Binder.restoreCallingIdentity(identity);
5729 }
chen xub97461a2018-10-26 14:17:57 -07005730 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005731 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005732
5733 @Override
5734 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005735 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005736 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005737
5738 final long identity = Binder.clearCallingIdentity();
5739 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005740 ImsManager.getInstance(defaultPhone.getContext(),
5741 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005742 } finally {
5743 Binder.restoreCallingIdentity(identity);
5744 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005745 }
5746
5747 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005748 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005749 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005750 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5751 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005752 return false;
5753 }
Svet Ganovb320e182015-04-16 12:30:10 -07005754
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005755 final long identity = Binder.clearCallingIdentity();
5756 try {
5757 // Check the user preference and the system-level IMS setting. Even if the user has
5758 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5759 // In the long run, we may instead need to check if there exists a connection service
5760 // which can support video calling.
5761 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005762 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005763 return imsManager.isVtEnabledByPlatform()
5764 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5765 && imsManager.isVtEnabledByUser();
5766 } finally {
5767 Binder.restoreCallingIdentity(identity);
5768 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005769 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005770
Andrew Leea1239f22015-03-02 17:44:07 -08005771 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005772 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5773 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005774 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005775 mApp, subId, callingPackage, callingFeatureId,
5776 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005777 return false;
5778 }
5779
5780 final long identity = Binder.clearCallingIdentity();
5781 try {
5782 CarrierConfigManager configManager =
5783 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005784 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005785 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5786 } finally {
5787 Binder.restoreCallingIdentity(identity);
5788 }
Andrew Leea1239f22015-03-02 17:44:07 -08005789 }
5790
5791 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005792 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005793 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005794 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005795 return false;
5796 }
5797
5798 final long identity = Binder.clearCallingIdentity();
5799 try {
5800 CarrierConfigManager configManager =
5801 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005802 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005803 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5804 } finally {
5805 Binder.restoreCallingIdentity(identity);
5806 }
Andrew Leea1239f22015-03-02 17:44:07 -08005807 }
5808
Andrew Lee9431b832015-03-09 18:46:45 -07005809 @Override
5810 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07005811 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005812 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005813 }
5814
5815 @Override
5816 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005817 final long identity = Binder.clearCallingIdentity();
5818 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005819 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005820 } finally {
5821 Binder.restoreCallingIdentity(identity);
5822 }
Andrew Lee9431b832015-03-09 18:46:45 -07005823 }
5824
Hall Liuf6668912018-10-31 17:05:23 -07005825 /**
5826 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5827 * support for the feature and device firmware support.
5828 *
5829 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5830 */
5831 @Override
5832 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005833 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005834 final Phone phone = getPhone(subscriptionId);
5835 if (phone == null) {
5836 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5837 return false;
5838 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005839 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005840 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005841 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5842 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005843 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005844 return isCarrierSupported && isDeviceSupported;
5845 } finally {
5846 Binder.restoreCallingIdentity(identity);
5847 }
Hall Liu98187582018-01-22 19:15:32 -08005848 }
5849
Hall Liuf6668912018-10-31 17:05:23 -07005850 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005851 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5852 * RTT setting, will return true if the device and carrier both support RTT.
5853 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005854 */
5855 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005856 final long identity = Binder.clearCallingIdentity();
5857 try {
Hall Liu63767ec2019-12-11 23:58:20 +00005858 boolean isRttSupported = isRttSupported(subscriptionId);
5859 boolean isUserRttSettingOn = Settings.Secure.getInt(
5860 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
5861 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5862 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5863 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005864 } finally {
5865 Binder.restoreCallingIdentity(identity);
5866 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005867 }
5868
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005869 @Deprecated
5870 @Override
5871 public String getDeviceId(String callingPackage) {
5872 return getDeviceIdWithFeature(callingPackage, null);
5873 }
5874
Sanket Padawe7310cc72015-01-14 09:53:20 -08005875 /**
5876 * Returns the unique device ID of phone, for example, the IMEI for
5877 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5878 *
5879 * <p>Requires Permission:
5880 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5881 */
5882 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005883 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005884 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005885 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005886 return null;
5887 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005888 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005889 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005890 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005891 return null;
5892 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005893
5894 final long identity = Binder.clearCallingIdentity();
5895 try {
5896 return phone.getDeviceId();
5897 } finally {
5898 Binder.restoreCallingIdentity(identity);
5899 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005900 }
5901
Ping Sunc67b7c22016-03-02 19:16:45 +08005902 /**
5903 * {@hide}
5904 * Returns the IMS Registration Status on a particular subid
5905 *
5906 * @param subId
5907 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005908 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005909 Phone phone = getPhone(subId);
5910 if (phone != null) {
5911 return phone.isImsRegistered();
5912 } else {
5913 return false;
5914 }
5915 }
5916
Santos Cordon7a1885b2015-02-03 11:15:19 -08005917 @Override
5918 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005919 final long identity = Binder.clearCallingIdentity();
5920 try {
5921 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5922 } finally {
5923 Binder.restoreCallingIdentity(identity);
5924 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005925 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005926
Tyler Gunnf70ed162019-04-03 15:28:53 -07005927 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07005928 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005929 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07005930 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005931 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07005932 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5933 }
5934 final long identity = Binder.clearCallingIdentity();
5935 try {
5936 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5937 } finally {
5938 Binder.restoreCallingIdentity(identity);
5939 }
5940 }
5941
5942 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005943 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5944 final long identity = Binder.clearCallingIdentity();
5945 try {
5946 Phone phone = getPhone(subscriptionId);
5947 if (phone == null) {
5948 return null;
5949 }
5950 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5951 } finally {
5952 Binder.restoreCallingIdentity(identity);
5953 }
5954 }
5955
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005956 /**
5957 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005958 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005959 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005960 final long identity = Binder.clearCallingIdentity();
5961 try {
5962 Phone phone = getPhone(subId);
5963 if (phone != null) {
5964 return phone.isWifiCallingEnabled();
5965 } else {
5966 return false;
5967 }
5968 } finally {
5969 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005970 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005971 }
5972
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005973 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005974 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005975 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005976 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005977 final long identity = Binder.clearCallingIdentity();
5978 try {
5979 Phone phone = getPhone(subId);
5980 if (phone != null) {
5981 return phone.isVideoEnabled();
5982 } else {
5983 return false;
5984 }
5985 } finally {
5986 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005987 }
5988 }
5989
5990 /**
5991 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5992 * defined in {@link ImsRegistrationImplBase}.
5993 */
5994 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005995 final long identity = Binder.clearCallingIdentity();
5996 try {
5997 Phone phone = getPhone(subId);
5998 if (phone != null) {
5999 return phone.getImsRegistrationTech();
6000 } else {
6001 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6002 }
6003 } finally {
6004 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006005 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006006 }
6007
Stuart Scott8eef64f2015-04-08 15:13:54 -07006008 @Override
6009 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006010 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006011 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6012 return;
6013 }
6014
Svet Ganovcc087f82015-05-12 20:35:54 -07006015 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006016
Svet Ganovcc087f82015-05-12 20:35:54 -07006017 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006018 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6019 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006020 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006021 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006022 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006023 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6024 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006025 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006026 // There has been issues when Sms raw table somehow stores orphan
6027 // fragments. They lead to garbled message when new fragments come
6028 // in and combined with those stale ones. In case this happens again,
6029 // user can reset all network settings which will clean up this table.
6030 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006031 // Clean up IMS settings as well here.
6032 int slotId = getSlotIndex(subId);
6033 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6034 ImsManager.getInstance(mApp, slotId).factoryReset();
6035 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006036
6037 // Erase modem config if erase modem on network setting is enabled.
6038 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6039 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6040 if (configValue != null && Boolean.parseBoolean(configValue)) {
6041 sendEraseModemConfig(getDefaultPhone());
6042 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006043 } finally {
6044 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006045 }
6046 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006047
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006048 private void cleanUpSmsRawTable(Context context) {
6049 ContentResolver resolver = context.getContentResolver();
6050 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6051 resolver.delete(uri, null, null);
6052 }
6053
Narayan Kamath1c496c22015-04-16 14:40:19 +01006054 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006055 public String getSimLocaleForSubscriber(int subId) {
6056 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6057 final Phone phone = getPhone(subId);
6058 if (phone == null) {
6059 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006060 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006061 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006062 final long identity = Binder.clearCallingIdentity();
6063 try {
chen xu5d3637b2019-01-21 23:31:38 -08006064 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006065 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08006066 if (info == null) {
6067 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6068 return null;
6069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006070 // Try and fetch the locale from the carrier properties or from the SIM language
6071 // preferences (EF-PL and EF-LI)...
6072 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006073 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006074 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6075 if (localeFromDefaultSim != null) {
6076 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6077 if (DBG) log("Using locale from subId: " + subId + " locale: "
6078 + localeFromDefaultSim);
6079 return localeFromDefaultSim.toLanguageTag();
6080 } else {
6081 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006082 }
6083 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006084
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006085 // The SIM language preferences only store a language (e.g. fr = French), not an
6086 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6087 // the SIM and carrier preferences does not include a country we add the country
6088 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006089 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006090 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006091 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006092 return mccLocale.toLanguageTag();
6093 }
6094
6095 if (DBG) log("No locale found - returning null");
6096 return null;
6097 } finally {
6098 Binder.restoreCallingIdentity(identity);
6099 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006100 }
6101
6102 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006103 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6104 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006105 }
6106
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107 /**
6108 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6109 */
6110 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006111 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6112 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006113 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006114
Chenjie Yu1ba97252018-01-11 18:16:20 -08006115 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006116 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006117
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006118 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006119 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6120 * representing the state of the modem.
6121 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006122 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6123 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006124 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006125 */
6126 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006127 public void requestModemActivityInfo(ResultReceiver result) {
6128 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006129 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006130
6131 final long identity = Binder.clearCallingIdentity();
6132 try {
6133 ModemActivityInfo ret = null;
6134 synchronized (mLastModemActivityInfo) {
6135 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6136 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006137 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006138 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006139 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xu13851032019-09-10 18:49:52 -07006140 int[] txTimeMs = info.getTransmitTimeMillis();
6141 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006142 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xu13851032019-09-10 18:49:52 -07006143 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006144 }
6145 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006146 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6147 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006148 mLastModemActivityInfo.setIdleTimeMillis(
6149 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xu13851032019-09-10 18:49:52 -07006150 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6151 mLastModemActivityInfo.setReceiveTimeMillis(
6152 info.getReceiveTimeMillis() + mLastModemActivityInfo
6153 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006154 }
Chen Xu13851032019-09-10 18:49:52 -07006155
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006156 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6157 mLastModemActivityInfo.getSleepTimeMillis(),
6158 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xu13851032019-09-10 18:49:52 -07006159 mLastModemActivityInfo.getTransmitTimeMillis(),
6160 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006161 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006162 Bundle bundle = new Bundle();
6163 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6164 result.send(0, bundle);
6165 } finally {
6166 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006167 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006168 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006169
Siddharth Rayb8114062018-06-17 15:02:38 -07006170 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6171 // less than total activity duration.
6172 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6173 if (info == null) {
6174 return false;
6175 }
6176 int activityDurationMs =
6177 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6178 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006179 int[] txTimeMs = info.getTransmitTimeMillis();
6180 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6181 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006182 }
6183 return (info.isValid()
6184 && (info.getSleepTimeMillis() <= activityDurationMs)
6185 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006186 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006187 && (totalTxTimeMs <= activityDurationMs));
6188 }
6189
Jack Yu85bd38a2015-11-09 11:34:32 -08006190 /**
6191 * {@hide}
6192 * Returns the service state information on specified subscription.
6193 */
6194 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006195 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6196 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006197 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006198 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006199 return null;
6200 }
6201
Hall Liuf19c44f2018-11-27 14:38:17 -08006202 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6203 LocationAccessPolicy.checkLocationPermission(mApp,
6204 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6205 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006206 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006207 .setCallingPid(Binder.getCallingPid())
6208 .setCallingUid(Binder.getCallingUid())
6209 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006210 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006211 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6212 .build());
6213
6214 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6215 LocationAccessPolicy.checkLocationPermission(mApp,
6216 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6217 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006218 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006219 .setCallingPid(Binder.getCallingPid())
6220 .setCallingUid(Binder.getCallingUid())
6221 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006222 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006223 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6224 .build());
6225 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6226 boolean hasFinePermission =
6227 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6228 boolean hasCoarsePermission =
6229 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6230
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006231 final long identity = Binder.clearCallingIdentity();
6232 try {
6233 final Phone phone = getPhone(subId);
6234 if (phone == null) {
6235 return null;
6236 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006237
Hall Liuf19c44f2018-11-27 14:38:17 -08006238 ServiceState ss = phone.getServiceState();
6239
6240 // Scrub out the location info in ServiceState depending on what level of access
6241 // the caller has.
6242 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006243 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6244 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006245 } finally {
6246 Binder.restoreCallingIdentity(identity);
6247 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006248 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006249
6250 /**
6251 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6252 *
6253 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6254 * voicemail ringtone.
6255 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6256 * PhoneAccount.
6257 */
6258 @Override
6259 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006260 final long identity = Binder.clearCallingIdentity();
6261 try {
6262 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6263 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006264 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006265 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006266
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006267 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6268 } finally {
6269 Binder.restoreCallingIdentity(identity);
6270 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006271 }
6272
6273 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006274 * Sets the per-account voicemail ringtone.
6275 *
6276 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6277 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6278 *
6279 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6280 * voicemail ringtone.
6281 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6282 * PhoneAccount.
6283 */
6284 @Override
6285 public void setVoicemailRingtoneUri(String callingPackage,
6286 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006287 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006288 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006289 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6290 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006291 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6292 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6293 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006294 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006295
6296 final long identity = Binder.clearCallingIdentity();
6297 try {
6298 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6299 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006300 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006301 }
6302 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6303 } finally {
6304 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006305 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006306 }
6307
6308 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006309 * Returns whether vibration is set for voicemail notification in Phone settings.
6310 *
6311 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6312 * voicemail vibration setting.
6313 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6314 */
6315 @Override
6316 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006317 final long identity = Binder.clearCallingIdentity();
6318 try {
6319 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6320 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006321 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006322 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006323
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006324 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6325 } finally {
6326 Binder.restoreCallingIdentity(identity);
6327 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006328 }
6329
Youhan Wange64578a2016-05-02 15:32:42 -07006330 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006331 * Sets the per-account voicemail vibration.
6332 *
6333 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6334 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6335 *
6336 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6337 * voicemail vibration setting.
6338 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6339 * specific PhoneAccount.
6340 */
6341 @Override
6342 public void setVoicemailVibrationEnabled(String callingPackage,
6343 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006344 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006345 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006346 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6347 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6349 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6350 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006351 }
6352
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006353 final long identity = Binder.clearCallingIdentity();
6354 try {
6355 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6356 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006357 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006358 }
6359 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6360 } finally {
6361 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006362 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006363 }
6364
6365 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006366 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6367 *
6368 * @throws SecurityException if the caller does not have the required permission
6369 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006370 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006371 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006372 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006373 }
6374
6375 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006376 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6377 * permission.
6378 *
6379 * @throws SecurityException if the caller does not have the required permission
6380 */
6381 private void enforceSendSmsPermission() {
6382 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6383 }
6384
6385 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006386 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006387 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006388 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006389 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006390 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006391 final long identity = Binder.clearCallingIdentity();
6392 try {
6393 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006394 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006395 if (componentName == null) {
6396 throw new SecurityException(
6397 "Caller not current active visual voicemail package[null]");
6398 }
6399 String vvmPackage = componentName.getPackageName();
6400 if (!callingPackage.equals(vvmPackage)) {
6401 throw new SecurityException("Caller not current active visual voicemail package["
6402 + vvmPackage + "]");
6403 }
6404 } finally {
6405 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006406 }
6407 }
6408
6409 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006410 * Return the application ID for the app type.
6411 *
6412 * @param subId the subscription ID that this request applies to.
6413 * @param appType the uicc app type.
6414 * @return Application ID for specificied app type, or null if no uicc.
6415 */
6416 @Override
6417 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006418 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006419 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006420
6421 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006422 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006423 if (phone == null) {
6424 return null;
6425 }
6426 String aid = null;
6427 try {
6428 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6429 .getApplicationByType(appType).getAid();
6430 } catch (Exception e) {
6431 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6432 }
6433 return aid;
6434 } finally {
6435 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006436 }
Youhan Wange64578a2016-05-02 15:32:42 -07006437 }
6438
Youhan Wang4001d252016-05-11 10:29:41 -07006439 /**
6440 * Return the Electronic Serial Number.
6441 *
6442 * @param subId the subscription ID that this request applies to.
6443 * @return ESN or null if error.
6444 */
6445 @Override
6446 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006447 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006448 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006449
6450 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006451 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006452 if (phone == null) {
6453 return null;
6454 }
6455 String esn = null;
6456 try {
6457 esn = phone.getEsn();
6458 } catch (Exception e) {
6459 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6460 }
6461 return esn;
6462 } finally {
6463 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006464 }
Youhan Wang4001d252016-05-11 10:29:41 -07006465 }
6466
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006467 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006468 * Return the Preferred Roaming List Version.
6469 *
6470 * @param subId the subscription ID that this request applies to.
6471 * @return PRLVersion or null if error.
6472 */
6473 @Override
6474 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006475 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006476 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006477
6478 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006479 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006480 if (phone == null) {
6481 return null;
6482 }
6483 String cdmaPrlVersion = null;
6484 try {
6485 cdmaPrlVersion = phone.getCdmaPrlVersion();
6486 } catch (Exception e) {
6487 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6488 }
6489 return cdmaPrlVersion;
6490 } finally {
6491 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006492 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006493 }
6494
6495 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006496 * Get snapshot of Telephony histograms
6497 * @return List of Telephony histograms
6498 * @hide
6499 */
6500 @Override
6501 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006502 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6503 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006504
6505 final long identity = Binder.clearCallingIdentity();
6506 try {
6507 return RIL.getTelephonyRILTimingHistograms();
6508 } finally {
6509 Binder.restoreCallingIdentity(identity);
6510 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006511 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006512
6513 /**
6514 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006515 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6516 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006517 * Require system privileges. In the future we may add this to carrier APIs.
6518 *
Michele Berionne482f8202018-11-27 18:57:59 -08006519 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006520 */
6521 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006522 @TelephonyManager.SetCarrierRestrictionResult
6523 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006524 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006525 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006526
Michele Berionne482f8202018-11-27 18:57:59 -08006527 if (carrierRestrictionRules == null) {
6528 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006529 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006530
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006531 final long identity = Binder.clearCallingIdentity();
6532 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006533 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006534 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006535 } finally {
6536 Binder.restoreCallingIdentity(identity);
6537 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006538 }
6539
6540 /**
6541 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006542 * Get the allowed carrier list and the excluded carrier list, including the priority between
6543 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006544 * Require system privileges. In the future we may add this to carrier APIs.
6545 *
Michele Berionne482f8202018-11-27 18:57:59 -08006546 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006547 */
6548 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006549 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006550 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006551 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006552
6553 final long identity = Binder.clearCallingIdentity();
6554 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006555 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6556 if (response instanceof CarrierRestrictionRules) {
6557 return (CarrierRestrictionRules) response;
6558 }
6559 // Response is an Exception of some kind,
6560 // which is signalled to the user as a NULL retval
6561 return null;
6562 } catch (Exception e) {
6563 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6564 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006565 } finally {
6566 Binder.restoreCallingIdentity(identity);
6567 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006568 }
6569
fionaxu59545b42016-05-25 15:53:37 -07006570 /**
6571 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6572 * @param subId the subscription ID that this action applies to.
6573 * @param enabled control enable or disable metered apns.
6574 * {@hide}
6575 */
6576 @Override
6577 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6578 enforceModifyPermission();
6579 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006580
6581 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006582 if (phone == null) {
6583 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6584 return;
6585 }
6586 try {
6587 phone.carrierActionSetMeteredApnsEnabled(enabled);
6588 } catch (Exception e) {
6589 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006590 } finally {
6591 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006592 }
6593 }
6594
6595 /**
6596 * Action set from carrier signalling broadcast receivers to enable/disable radio
6597 * @param subId the subscription ID that this action applies to.
6598 * @param enabled control enable or disable radio.
6599 * {@hide}
6600 */
6601 @Override
6602 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6603 enforceModifyPermission();
6604 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006605
6606 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006607 if (phone == null) {
6608 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6609 return;
6610 }
6611 try {
6612 phone.carrierActionSetRadioEnabled(enabled);
6613 } catch (Exception e) {
6614 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006615 } finally {
6616 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006617 }
6618 }
6619
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006620 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006621 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6622 * network status based on which carrier apps could apply actions accordingly,
6623 * enable/disable default url handler for example.
6624 *
6625 * @param subId the subscription ID that this action applies to.
6626 * @param report control start/stop reporting the default network status.
6627 * {@hide}
6628 */
6629 @Override
6630 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6631 enforceModifyPermission();
6632 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006633
6634 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006635 if (phone == null) {
6636 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6637 return;
6638 }
6639 try {
6640 phone.carrierActionReportDefaultNetworkStatus(report);
6641 } catch (Exception e) {
6642 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006643 } finally {
6644 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006645 }
6646 }
6647
6648 /**
fionaxud9622282017-07-17 17:51:30 -07006649 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6650 * @param subId the subscription ID that this action applies to.
6651 * {@hide}
6652 */
6653 @Override
6654 public void carrierActionResetAll(int subId) {
6655 enforceModifyPermission();
6656 final Phone phone = getPhone(subId);
6657 if (phone == null) {
6658 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6659 return;
6660 }
6661 try {
6662 phone.carrierActionResetAll();
6663 } catch (Exception e) {
6664 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6665 }
6666 }
6667
6668 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006669 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6670 * bug report is being generated.
6671 */
6672 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006673 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006674 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6675 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006676 writer.println("Permission Denial: can't dump Phone from pid="
6677 + Binder.getCallingPid()
6678 + ", uid=" + Binder.getCallingUid()
6679 + "without permission "
6680 + android.Manifest.permission.DUMP);
6681 return;
6682 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006683 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006684 }
Jack Yueb89b242016-06-22 13:27:47 -07006685
Brad Ebingerdac2f002018-04-03 15:17:52 -07006686 @Override
6687 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6688 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6689 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006690 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6691 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006692 }
6693
Jack Yueb89b242016-06-22 13:27:47 -07006694 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006695 * Get aggregated video call data usage since boot.
6696 *
6697 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6698 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006699 * {@hide}
6700 */
6701 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006702 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006703 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6704 null);
6705
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006706 final long identity = Binder.clearCallingIdentity();
6707 try {
6708 // NetworkStatsService keeps tracking the active network interface and identity. It
6709 // records the delta with the corresponding network identity.
6710 // We just return the total video call data usage snapshot since boot.
6711 Phone phone = getPhone(subId);
6712 if (phone != null) {
6713 return phone.getVtDataUsage(perUidStats);
6714 }
6715 return null;
6716 } finally {
6717 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006718 }
Jack Yueb89b242016-06-22 13:27:47 -07006719 }
Jack Yu75ab2952016-07-08 14:29:33 -07006720
6721 /**
6722 * Policy control of data connection. Usually used when data limit is passed.
6723 * @param enabled True if enabling the data, otherwise disabling.
6724 * @param subId Subscription index
6725 * {@hide}
6726 */
6727 @Override
6728 public void setPolicyDataEnabled(boolean enabled, int subId) {
6729 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006730
6731 final long identity = Binder.clearCallingIdentity();
6732 try {
6733 Phone phone = getPhone(subId);
6734 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006735 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006736 }
6737 } finally {
6738 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006739 }
6740 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006741
6742 /**
6743 * Get Client request stats
6744 * @return List of Client Request Stats
6745 * @hide
6746 */
6747 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006748 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6749 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006750 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006751 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006752 return null;
6753 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006754 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006755
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006756 final long identity = Binder.clearCallingIdentity();
6757 try {
6758 if (phone != null) {
6759 return phone.getClientRequestStats();
6760 }
6761
6762 return null;
6763 } finally {
6764 Binder.restoreCallingIdentity(identity);
6765 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006766 }
6767
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006768 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006769 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006770 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006771 }
Jack Yueb4124c2017-02-16 15:32:43 -08006772
6773 /**
Grace Chen70990072017-03-24 17:21:30 -07006774 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006775 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006776 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006777 * @param state State of SIM (power down, power up, pass through)
6778 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6779 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6780 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006781 *
6782 **/
6783 @Override
Grace Chen70990072017-03-24 17:21:30 -07006784 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006785 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006786 Phone phone = PhoneFactory.getPhone(slotIndex);
6787
vagdeviaf9a5b92018-08-15 16:01:53 -07006788 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6789
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006790 final long identity = Binder.clearCallingIdentity();
6791 try {
6792 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006793 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006794 }
6795 } finally {
6796 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006797 }
6798 }
Shuo Qiandd210312017-04-12 22:11:33 +00006799
Tyler Gunn65d45c22017-06-05 11:22:26 -07006800 private boolean isUssdApiAllowed(int subId) {
6801 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006802 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006803 if (configManager == null) {
6804 return false;
6805 }
6806 PersistableBundle pb = configManager.getConfigForSubId(subId);
6807 if (pb == null) {
6808 return false;
6809 }
6810 return pb.getBoolean(
6811 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6812 }
6813
Shuo Qiandd210312017-04-12 22:11:33 +00006814 /**
6815 * Check if phone is in emergency callback mode
6816 * @return true if phone is in emergency callback mode
6817 * @param subId sub id
6818 */
goneil9c5f4872017-12-05 14:07:56 -08006819 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006820 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006821 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006822 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006823
6824 final long identity = Binder.clearCallingIdentity();
6825 try {
6826 if (phone != null) {
6827 return phone.isInEcm();
6828 } else {
6829 return false;
6830 }
6831 } finally {
6832 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006833 }
6834 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006835
6836 /**
6837 * Get the current signal strength information for the given subscription.
6838 * Because this information is not updated when the device is in a low power state
6839 * it should not be relied-upon to be current.
6840 * @param subId Subscription index
6841 * @return the most recent cached signal strength info from the modem
6842 */
6843 @Override
6844 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006845 final long identity = Binder.clearCallingIdentity();
6846 try {
6847 Phone p = getPhone(subId);
6848 if (p == null) {
6849 return null;
6850 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006851
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006852 return p.getSignalStrength();
6853 } finally {
6854 Binder.restoreCallingIdentity(identity);
6855 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006856 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006857
Pengquan Meng77b7f132018-08-22 14:49:57 -07006858 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006859 * Get the current modem radio state for the given slot.
6860 * @param slotIndex slot index.
6861 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006862 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00006863 * @return the current radio power state from the modem
6864 */
6865 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006866 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00006867 Phone phone = PhoneFactory.getPhone(slotIndex);
6868 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006869 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
6870 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00006871 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6872 }
6873
6874 final long identity = Binder.clearCallingIdentity();
6875 try {
6876 return phone.getRadioPowerState();
6877 } finally {
6878 Binder.restoreCallingIdentity(identity);
6879 }
6880 }
6881 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6882 }
6883
6884 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006885 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6886 *
6887 * <p>Requires one of the following permissions:
6888 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6889 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6890 * privileges.
6891 *
6892 * @param subId subscription id
6893 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6894 * {@code false}.
6895 */
6896 @Override
6897 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006898 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6899 null /* message */);
6900
Pengquan Menga1bb6272018-09-06 09:59:22 -07006901 boolean isEnabled = false;
6902 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006903 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006904 Phone phone = getPhone(subId);
6905 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006906 } catch (Exception e) {
6907 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6908 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006909 } finally {
6910 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006911 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006912 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006913 }
6914
6915
6916 /**
6917 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6918 *
6919 * <p> Requires permission:
6920 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6921 * privileges.
6922 *
6923 * @param subId subscription id
6924 * @param isEnabled {@code true} means enable, {@code false} means disable.
6925 */
6926 @Override
6927 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006928 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6929 mApp, subId, "setDataRoamingEnabled");
6930
Pengquan Menga1bb6272018-09-06 09:59:22 -07006931 final long identity = Binder.clearCallingIdentity();
6932 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006933 Phone phone = getPhone(subId);
6934 if (phone != null) {
6935 phone.setDataRoamingEnabled(isEnabled);
6936 }
6937 } finally {
6938 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006939 }
6940 }
6941
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006942 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006943 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08006944 TelephonyPermissions
6945 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07006946 mApp, subId, "isManualNetworkSelectionAllowed");
6947
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006948 boolean isAllowed = true;
6949 final long identity = Binder.clearCallingIdentity();
6950 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006951 Phone phone = getPhone(subId);
6952 if (phone != null) {
6953 isAllowed = phone.isCspPlmnEnabled();
6954 }
6955 } finally {
6956 Binder.restoreCallingIdentity(identity);
6957 }
6958 return isAllowed;
6959 }
6960
6961 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006962 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006963 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006964 try {
6965 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006966 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006967 } catch (SecurityException e) {
6968 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6969 // has carrier privileges on an active UICC
6970 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6971 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006972 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006973 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006974 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006975
6976 final long identity = Binder.clearCallingIdentity();
6977 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006978 UiccController uiccController = UiccController.getInstance();
6979 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006980 if (hasReadPermission) {
6981 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006982 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006983
6984 // Remove private info if the caller doesn't have access
6985 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6986 for (UiccCardInfo cardInfo : cardInfos) {
6987 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6988 // is available
6989 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6990 if (card == null || card.getUiccProfile() == null) {
6991 // assume no access if the card or profile is unavailable
6992 filteredInfos.add(cardInfo.getUnprivileged());
6993 continue;
6994 }
6995 UiccProfile profile = card.getUiccProfile();
6996 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6997 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6998 filteredInfos.add(cardInfo);
6999 } else {
7000 filteredInfos.add(cardInfo.getUnprivileged());
7001 }
7002 }
7003 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007004 } finally {
7005 Binder.restoreCallingIdentity(identity);
7006 }
7007 }
7008
7009 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007010 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007011 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007012
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007013 final long identity = Binder.clearCallingIdentity();
7014 try {
7015 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7016 if (slots == null) {
7017 Rlog.i(LOG_TAG, "slots is null.");
7018 return null;
7019 }
7020
7021 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7022 for (int i = 0; i < slots.length; i++) {
7023 UiccSlot slot = slots[i];
7024 if (slot == null) {
7025 continue;
7026 }
7027
Jordan Liu7be7e652019-05-06 18:55:02 +00007028 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007029 UiccCard card = slot.getUiccCard();
7030 if (card != null) {
7031 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007032 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007033 cardId = slot.getEid();
7034 if (TextUtils.isEmpty(cardId)) {
7035 cardId = slot.getIccId();
7036 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007037 }
7038
Jordan Liu857451f2019-05-09 16:35:35 -07007039 if (cardId != null) {
7040 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7041 // if cardId is an EID, it's all digits so this is fine
7042 cardId = IccUtils.stripTrailingFs(cardId);
7043 }
7044
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007045 int cardState = 0;
7046 switch (slot.getCardState()) {
7047 case CARDSTATE_ABSENT:
7048 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7049 break;
7050 case CARDSTATE_PRESENT:
7051 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7052 break;
7053 case CARDSTATE_ERROR:
7054 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7055 break;
7056 case CARDSTATE_RESTRICTED:
7057 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7058 break;
7059 default:
7060 break;
7061
7062 }
7063
7064 infos[i] = new UiccSlotInfo(
7065 slot.isActive(),
7066 slot.isEuicc(),
7067 cardId,
7068 cardState,
7069 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007070 slot.isExtendedApduSupported(),
7071 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007072 }
7073 return infos;
7074 } finally {
7075 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007076 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007077 }
7078
7079 @Override
7080 public boolean switchSlots(int[] physicalSlots) {
7081 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007082
7083 final long identity = Binder.clearCallingIdentity();
7084 try {
7085 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7086 } finally {
7087 Binder.restoreCallingIdentity(identity);
7088 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007089 }
Jack Yu4c988042018-02-27 15:30:01 -08007090
7091 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007092 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007093 final long identity = Binder.clearCallingIdentity();
7094 try {
7095 return UiccController.getInstance().getCardIdForDefaultEuicc();
7096 } finally {
7097 Binder.restoreCallingIdentity(identity);
7098 }
7099 }
7100
7101 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007102 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7103 enforceModifyPermission();
7104 final Phone phone = getPhone(subId);
7105 if (phone == null) {
7106 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7107 return;
7108 }
7109
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007110 final long identity = Binder.clearCallingIdentity();
7111 try {
7112 phone.setRadioIndicationUpdateMode(filters, mode);
7113 } finally {
7114 Binder.restoreCallingIdentity(identity);
7115 }
Jack Yu4c988042018-02-27 15:30:01 -08007116 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007117
7118 /**
goneil47ffb6e2018-04-06 15:40:58 -07007119 * A test API to reload the UICC profile.
7120 *
7121 * <p>Requires that the calling app has permission
7122 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7123 * @hide
7124 */
7125 @Override
7126 public void refreshUiccProfile(int subId) {
7127 enforceModifyPermission();
7128
7129 final long identity = Binder.clearCallingIdentity();
7130 try {
7131 Phone phone = getPhone(subId);
7132 if (phone == null) {
7133 return;
7134 }
7135 UiccCard uiccCard = phone.getUiccCard();
7136 if (uiccCard == null) {
7137 return;
7138 }
7139 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7140 if (uiccProfile == null) {
7141 return;
7142 }
7143 uiccProfile.refresh();
7144 } finally {
7145 Binder.restoreCallingIdentity(identity);
7146 }
7147 }
7148
7149 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007150 * Returns false if the mobile data is disabled by default, otherwise return true.
7151 */
7152 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007153 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007154 }
7155
7156 /**
7157 * Returns true if the data roaming is enabled by default, i.e the system property
7158 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7159 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7160 */
7161 private boolean getDefaultDataRoamingEnabled(int subId) {
7162 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007163 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007164 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007165 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7166 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7167 return isDataRoamingEnabled;
7168 }
7169
7170 /**
7171 * Returns the default network type for the given {@code subId}, if the default network type is
7172 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7173 */
7174 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007175 List<Integer> list = TelephonyProperties.default_network();
7176 int phoneId = mSubscriptionController.getPhoneId(subId);
7177 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7178 return list.get(phoneId);
7179 }
7180 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007181 }
fionaxua13278b2018-03-21 00:08:13 -07007182
7183 @Override
7184 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007185 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007186 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007187
7188 final long identity = Binder.clearCallingIdentity();
7189 try {
7190 final Phone phone = getPhone(subId);
7191 if (phone == null) {
7192 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7193 return;
7194 }
chen xueaba88a2019-03-15 13:15:10 -07007195 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7196 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007197 } finally {
7198 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007199 }
fionaxua13278b2018-03-21 00:08:13 -07007200 }
7201
7202 @Override
7203 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007204 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007205
7206 final long identity = Binder.clearCallingIdentity();
7207 try {
7208 final Phone phone = getPhone(subId);
7209 if (phone == null) {
7210 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7211 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7212 }
7213 return phone.getCarrierIdListVersion();
7214 } finally {
7215 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007216 }
fionaxua13278b2018-03-21 00:08:13 -07007217 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007218
7219 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007220 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7221 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007222 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007223 mApp, subId, callingPackage, callingFeatureId,
7224 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007225 return -1;
7226 }
7227
7228 final long identity = Binder.clearCallingIdentity();
7229 try {
7230 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7231 } finally {
7232 Binder.restoreCallingIdentity(identity);
7233 }
7234 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007235
7236 @Override
7237 public int getCdmaRoamingMode(int subId) {
7238 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7239 mApp, subId, "getCdmaRoamingMode");
7240
7241 final long identity = Binder.clearCallingIdentity();
7242 try {
7243 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7244 } finally {
7245 Binder.restoreCallingIdentity(identity);
7246 }
7247 }
7248
7249 @Override
7250 public boolean setCdmaRoamingMode(int subId, int mode) {
7251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7252 mApp, subId, "setCdmaRoamingMode");
7253
7254 final long identity = Binder.clearCallingIdentity();
7255 try {
7256 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7257 } finally {
7258 Binder.restoreCallingIdentity(identity);
7259 }
7260 }
7261
7262 @Override
7263 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7264 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7265 mApp, subId, "setCdmaSubscriptionMode");
7266
7267 final long identity = Binder.clearCallingIdentity();
7268 try {
7269 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7270 } finally {
7271 Binder.restoreCallingIdentity(identity);
7272 }
7273 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007274
sqianc5eccab2018-10-19 18:46:41 -07007275 @Override
sqian8c685422019-02-22 15:55:18 -08007276 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007277 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007278 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007279 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7280 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007281 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7282 }
7283 final long identity = Binder.clearCallingIdentity();
7284 try {
sqian854d44b2018-12-12 16:48:18 -08007285 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7286 for (Phone phone: PhoneFactory.getPhones()) {
7287 if (phone.getEmergencyNumberTracker() != null
7288 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7289 emergencyNumberListInternal.put(
7290 phone.getSubId(),
7291 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7292 }
sqian11b7a0e2018-12-05 18:48:28 -08007293 }
sqian854d44b2018-12-12 16:48:18 -08007294 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007295 } finally {
7296 Binder.restoreCallingIdentity(identity);
7297 }
sqianc5eccab2018-10-19 18:46:41 -07007298 }
7299
7300 @Override
sqian8c685422019-02-22 15:55:18 -08007301 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007302 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007303 if (!exactMatch) {
7304 TelephonyPermissions
7305 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007306 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007307 }
7308 final long identity = Binder.clearCallingIdentity();
7309 try {
sqian854d44b2018-12-12 16:48:18 -08007310 for (Phone phone: PhoneFactory.getPhones()) {
7311 if (phone.getEmergencyNumberTracker() != null
7312 && phone.getEmergencyNumberTracker() != null) {
7313 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7314 number, exactMatch)) {
7315 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007316 }
7317 }
sqian11b7a0e2018-12-05 18:48:28 -08007318 }
7319 return false;
7320 } finally {
7321 Binder.restoreCallingIdentity(identity);
7322 }
7323 }
7324
sqianf4ca7ed2019-01-15 18:32:07 -08007325 /**
7326 * Update emergency number list for test mode.
7327 */
7328 @Override
7329 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7330 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7331 "updateEmergencyNumberListTestMode");
7332
7333 final long identity = Binder.clearCallingIdentity();
7334 try {
7335 for (Phone phone: PhoneFactory.getPhones()) {
7336 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7337 if (tracker != null) {
7338 tracker.executeEmergencyNumberTestModeCommand(action, num);
7339 }
7340 }
7341 } finally {
7342 Binder.restoreCallingIdentity(identity);
7343 }
7344 }
7345
7346 /**
7347 * Get the full emergency number list for test mode.
7348 */
7349 @Override
7350 public List<String> getEmergencyNumberListTestMode() {
7351 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7352 "getEmergencyNumberListTestMode");
7353
7354 final long identity = Binder.clearCallingIdentity();
7355 try {
7356 Set<String> emergencyNumbers = new HashSet<>();
7357 for (Phone phone: PhoneFactory.getPhones()) {
7358 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7359 if (tracker != null) {
7360 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7361 emergencyNumbers.add(num.getNumber());
7362 }
7363 }
7364 }
7365 return new ArrayList<>(emergencyNumbers);
7366 } finally {
7367 Binder.restoreCallingIdentity(identity);
7368 }
7369 }
7370
chen xud6b45bd2018-10-30 22:27:10 -07007371 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007372 public int getEmergencyNumberDbVersion(int subId) {
7373 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7374
7375 final long identity = Binder.clearCallingIdentity();
7376 try {
7377 final Phone phone = getPhone(subId);
7378 if (phone == null) {
7379 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7380 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7381 }
7382 return phone.getEmergencyNumberDbVersion();
7383 } finally {
7384 Binder.restoreCallingIdentity(identity);
7385 }
7386 }
7387
7388 @Override
7389 public void notifyOtaEmergencyNumberDbInstalled() {
7390 enforceModifyPermission();
7391
7392 final long identity = Binder.clearCallingIdentity();
7393 try {
7394 for (Phone phone: PhoneFactory.getPhones()) {
7395 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7396 if (tracker != null) {
7397 tracker.updateOtaEmergencyNumberDatabase();
7398 }
7399 }
7400 } finally {
7401 Binder.restoreCallingIdentity(identity);
7402 }
7403 }
7404
7405 @Override
7406 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7407 enforceActiveEmergencySessionPermission();
7408
7409 final long identity = Binder.clearCallingIdentity();
7410 try {
7411 for (Phone phone: PhoneFactory.getPhones()) {
7412 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7413 if (tracker != null) {
7414 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7415 }
7416 }
7417 } finally {
7418 Binder.restoreCallingIdentity(identity);
7419 }
7420 }
7421
7422 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007423 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7424 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7425 Phone phone = getPhone(subId);
7426 if (phone == null) {
7427 return null;
7428 }
7429 final long identity = Binder.clearCallingIdentity();
7430 try {
7431 UiccProfile profile = UiccController.getInstance()
7432 .getUiccProfileForPhone(phone.getPhoneId());
7433 if (profile != null) {
7434 return profile.getCertsFromCarrierPrivilegeAccessRules();
7435 }
7436 } finally {
7437 Binder.restoreCallingIdentity(identity);
7438 }
7439 return null;
7440 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007441
7442 /**
7443 * Enable or disable a modem stack.
7444 */
7445 @Override
7446 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7447 enforceModifyPermission();
7448
7449 final long identity = Binder.clearCallingIdentity();
7450 try {
7451 Phone phone = PhoneFactory.getPhone(slotIndex);
7452 if (phone == null) {
7453 return false;
7454 } else {
7455 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7456 }
7457 } finally {
7458 Binder.restoreCallingIdentity(identity);
7459 }
7460 }
Michelecea4cf22018-12-21 15:00:11 -08007461
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007462 /**
7463 * Whether a modem stack is enabled or not.
7464 */
7465 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007466 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7467 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007468 Phone phone = PhoneFactory.getPhone(slotIndex);
7469 if (phone == null) return false;
7470
7471 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007472 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7473 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007474 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7475 }
7476
7477 final long identity = Binder.clearCallingIdentity();
7478 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007479 try {
7480 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7481 } catch (NoSuchElementException ex) {
7482 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7483 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007484 } finally {
7485 Binder.restoreCallingIdentity(identity);
7486 }
7487 }
7488
Michelecea4cf22018-12-21 15:00:11 -08007489 @Override
Michele0ea7d782019-03-19 14:58:42 -07007490 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007491 enforceModifyPermission();
7492
7493 final long identity = Binder.clearCallingIdentity();
7494 try {
7495 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007496 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007497 .commit();
7498 } finally {
7499 Binder.restoreCallingIdentity(identity);
7500 }
7501 }
7502
7503 @Override
Michele0ea7d782019-03-19 14:58:42 -07007504 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007505 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007506 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007507 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7508 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007509 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007510 }
Michelecea4cf22018-12-21 15:00:11 -08007511
7512 final long identity = Binder.clearCallingIdentity();
7513 try {
Michele0ea7d782019-03-19 14:58:42 -07007514 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007515 } finally {
7516 Binder.restoreCallingIdentity(identity);
7517 }
7518 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007519
Michele0ea7d782019-03-19 14:58:42 -07007520 @TelephonyManager.IsMultiSimSupportedResult
7521 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007522 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7523 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7524 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007525 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7526 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007527 }
7528 // Check if the hardware supports multisim functionality. If usage of multisim is not
7529 // supported by the modem, indicate that it is restricted.
7530 PhoneCapability staticCapability =
7531 mPhoneConfigurationManager.getStaticPhoneCapability();
7532 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007533 loge("isMultiSimSupportedInternal: no static configuration available");
7534 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007535 }
7536 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007537 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7538 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007539 }
7540 // Check if support of multiple SIMs is restricted by carrier
7541 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007542 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007543 }
7544
Michele0ea7d782019-03-19 14:58:42 -07007545 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007546 }
7547
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007548 /**
7549 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007550 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7551 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7552 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007553 * @param numOfSims number of active sims we want to switch to
7554 */
7555 @Override
7556 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007557 if (numOfSims == 1) {
7558 enforceModifyPermission();
7559 } else {
7560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7561 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7562 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007563 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007564
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007565 try {
Michele30b57b22019-03-01 12:01:14 -08007566 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007567 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007568 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7569 return;
7570 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007571 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7572 } finally {
7573 Binder.restoreCallingIdentity(identity);
7574 }
7575 }
7576
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007577 @Override
7578 public boolean isApplicationOnUicc(int subId, int appType) {
7579 enforceReadPrivilegedPermission("isApplicationOnUicc");
7580 Phone phone = getPhone(subId);
7581 if (phone == null) {
7582 return false;
7583 }
7584 final long identity = Binder.clearCallingIdentity();
7585 try {
7586 UiccCard uiccCard = phone.getUiccCard();
7587 if (uiccCard == null) {
7588 return false;
7589 }
7590 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7591 if (uiccProfile == null) {
7592 return false;
7593 }
7594 if (TelephonyManager.APPTYPE_SIM <= appType
7595 && appType <= TelephonyManager.APPTYPE_ISIM) {
7596 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7597 }
7598 return false;
7599 } finally {
7600 Binder.restoreCallingIdentity(identity);
7601 }
7602 }
7603
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007604 /**
chen xub4baa772019-04-03 10:23:41 -07007605 * Get whether making changes to modem configurations will trigger reboot.
7606 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007607 */
7608 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007609 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7610 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007611 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007612 mApp, subId, callingPackage, callingFeatureId,
7613 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007614 return false;
7615 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007616 final long identity = Binder.clearCallingIdentity();
7617 try {
7618 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7619 } finally {
7620 Binder.restoreCallingIdentity(identity);
7621 }
7622 }
7623
Nathan Harold29f5f052019-02-15 13:41:57 -08007624 private void updateModemStateMetrics() {
7625 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7626 // TODO: check the state for each modem if the api is ready.
7627 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7628 }
7629
Pengquan Meng3889a572019-01-23 11:16:29 -08007630 @Override
7631 public int[] getSlotsMapping() {
7632 enforceReadPrivilegedPermission("getSlotsMapping");
7633
7634 final long identity = Binder.clearCallingIdentity();
7635 try {
7636 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7637 // All logical slots should have a mapping to a physical slot.
7638 int[] logicalSlotsMapping = new int[phoneCount];
7639 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7640 for (int i = 0; i < slotInfos.length; i++) {
7641 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7642 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7643 }
7644 }
7645 return logicalSlotsMapping;
7646 } finally {
7647 Binder.restoreCallingIdentity(identity);
7648 }
7649 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007650
7651 /**
7652 * Get the IRadio HAL Version
7653 */
7654 @Override
7655 public int getRadioHalVersion() {
7656 Phone phone = getDefaultPhone();
7657 if (phone == null) return -1;
7658 HalVersion hv = phone.getHalVersion();
7659 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7660 return hv.major * 100 + hv.minor;
7661 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007662
7663 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007664 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7665 * corresponding network requests on a subId.
7666 *
7667 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007668 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007669 * 2) APN is un-metered for this subscription, or
7670 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7671 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7672 *
7673 * @return whether data is allowed for a apn type.
7674 *
7675 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007676 */
7677 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007678 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07007679 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7680 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007681
7682 // Now that all security checks passes, perform the operation as ourselves.
7683 final long identity = Binder.clearCallingIdentity();
7684 try {
7685 Phone phone = getPhone(subId);
7686 if (phone == null) return false;
7687
Jack Yu41407ee2019-05-13 16:54:09 -07007688 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007689 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7690 } finally {
7691 Binder.restoreCallingIdentity(identity);
7692 }
7693 }
7694
7695 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007696 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007697 enforceReadPrivilegedPermission("isApnMetered");
7698
7699 // Now that all security checks passes, perform the operation as ourselves.
7700 final long identity = Binder.clearCallingIdentity();
7701 try {
7702 Phone phone = getPhone(subId);
7703 if (phone == null) return true; // By default return true.
7704
Jack Yu41407ee2019-05-13 16:54:09 -07007705 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007706 } finally {
7707 Binder.restoreCallingIdentity(identity);
7708 }
7709 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007710
7711 @Override
changbetty363e8ac2019-12-06 18:16:37 +08007712 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
7713 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
7714 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
7715 if (iccRecords == null) {
7716 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
7717 return false;
7718 }
7719 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
7720 }
7721
7722 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07007723 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7724 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7725 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7726 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7727 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7728 }
7729 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7730 Intent intent = new Intent();
7731 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7732 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7733 // Bring up choose default SMS subscription dialog right now
7734 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7735 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7736 mApp.startActivity(intent);
7737 }
chen xud5ca2d52019-05-28 15:20:57 -07007738
7739 @Override
7740 public String getMmsUAProfUrl(int subId) {
7741 //TODO investigate if this API should require proper permission check in R b/133791609
7742 final long identity = Binder.clearCallingIdentity();
7743 try {
7744 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7745 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7746 } finally {
7747 Binder.restoreCallingIdentity(identity);
7748 }
7749 }
7750
7751 @Override
7752 public String getMmsUserAgent(int subId) {
7753 //TODO investigate if this API should require proper permission check in R b/133791609
7754 final long identity = Binder.clearCallingIdentity();
7755 try {
7756 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7757 .getString(com.android.internal.R.string.config_mms_user_agent);
7758 } finally {
7759 Binder.restoreCallingIdentity(identity);
7760 }
7761 }
Jack Yub07d4972019-05-28 16:12:25 -07007762
7763 @Override
7764 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7765 enforceModifyPermission();
7766
7767 // Now that all security checks passes, perform the operation as ourselves.
7768 final long identity = Binder.clearCallingIdentity();
7769 try {
7770 Phone phone = getPhone(subId);
7771 if (phone == null) return false;
7772
7773 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7774 } finally {
7775 Binder.restoreCallingIdentity(identity);
7776 }
7777 }
7778
7779 @Override
7780 public boolean isDataAllowedInVoiceCall(int subId) {
7781 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7782
7783 // Now that all security checks passes, perform the operation as ourselves.
7784 final long identity = Binder.clearCallingIdentity();
7785 try {
7786 Phone phone = getPhone(subId);
7787 if (phone == null) return false;
7788
7789 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7790 } finally {
7791 Binder.restoreCallingIdentity(identity);
7792 }
7793 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007794
7795 /**
7796 * Updates whether conference event pacakge handling is enabled.
7797 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7798 * otherwise.
7799 */
7800 @Override
7801 public void setCepEnabled(boolean isCepEnabled) {
7802 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7803
7804 final long identity = Binder.clearCallingIdentity();
7805 try {
7806 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7807 for (Phone phone : PhoneFactory.getPhones()) {
7808 Phone defaultPhone = phone.getImsPhone();
7809 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7810 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7811 ImsPhoneCallTracker imsPhoneCallTracker =
7812 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7813 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7814 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7815 + imsPhone.getMsisdn());
7816 }
7817 }
7818 } finally {
7819 Binder.restoreCallingIdentity(identity);
7820 }
7821 }
allenwtsu46dcc572020-01-08 18:24:03 +08007822
7823 /**
7824 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
7825 *
7826 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
7827 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
7828 * before being read.
7829 */
7830 @Override
7831 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
7832 isCompressed) {
7833 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7834 mApp, subId, "notifyRcsAutoConfigurationReceived");
7835 try {
7836 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
7837 if (configBinder == null) {
7838 Rlog.e(LOG_TAG, "null result for getImsConfig");
7839 } else {
7840 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
7841 }
7842 } catch (RemoteException e) {
7843 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
7844 }
7845 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007846}