blob: 6a72eb16e89e3528d82cf9b5f1c64bdc4f555c8b [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;
Hall Liua1548bd2019-12-24 14:14:12 -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;
Hall Liua1548bd2019-12-24 14:14:12 -080049import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070050import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070051import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080052import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080053import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070054import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070055import android.os.ServiceSpecificException;
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 Nallurid63128d2019-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 Kim14bb3d02018-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 Xu227e06f2019-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 zhao2737e882019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080071import android.telephony.CellIdentityCdma;
72import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070074import android.telephony.CellInfoGsm;
75import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070076import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070077import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070078import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080079import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070080import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070082import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080083import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080084import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080088import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080089import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080091import android.telephony.TelephonyFrameworkInitializer;
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 Ebingera34a6c22019-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 Ebingerbc7dd582019-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;
Hall Liu73f5d362020-01-20 13:42:00 -0800132import com.android.internal.telephony.IBooleanConsumer;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700133import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800134import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700135import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800136import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700137import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700138import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700139import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700141import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800142import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700143import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700144import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700145import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700146import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700147import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700148import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700149import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700150import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800151import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800152import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700153import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800154import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700155import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800156import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700157import com.android.internal.telephony.imsphone.ImsPhone;
158import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800159import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700160import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700161import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800162import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800164import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700165import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800166import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700167import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800168import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000169import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800170import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700171import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800172import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700173import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700174import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800175import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700176import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700177import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang44b186e2020-01-13 23:33:09 -0800178import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800179
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700180import java.io.FileDescriptor;
181import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700182import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800183import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800184import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800185import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800186import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100187import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800188import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700189import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800190import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800191import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800192import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193
194/**
195 * Implementation of the ITelephony interface.
196 */
Santos Cordon117fee72014-05-16 17:56:12 -0700197public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198 private static final String LOG_TAG = "PhoneInterfaceManager";
199 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
200 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800201 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700202
203 // Message codes used with mMainThreadHandler
204 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700205 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
206 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700207 private static final int CMD_OPEN_CHANNEL = 9;
208 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
209 private static final int CMD_CLOSE_CHANNEL = 11;
210 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800211 private static final int CMD_NV_READ_ITEM = 13;
212 private static final int EVENT_NV_READ_ITEM_DONE = 14;
213 private static final int CMD_NV_WRITE_ITEM = 15;
214 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
215 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
216 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700217 private static final int CMD_RESET_MODEM_CONFIG = 19;
218 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800219 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
220 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
221 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
222 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800223 private static final int CMD_SEND_ENVELOPE = 25;
224 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000225 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
226 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700227 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
228 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
229 private static final int CMD_EXCHANGE_SIM_IO = 31;
230 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800231 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
232 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700233 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
234 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700235 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
236 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700237 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
238 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
239 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
240 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700241 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
242 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
243 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
244 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700245 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800246 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
247 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000248 private static final int CMD_SWITCH_SLOTS = 50;
249 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700250 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
251 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
252 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
253 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
254 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
255 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
256 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
257 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700258 private static final int CMD_GET_ALL_CELL_INFO = 60;
259 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
260 private static final int CMD_GET_CELL_LOCATION = 62;
261 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700262 private static final int CMD_MODEM_REBOOT = 64;
263 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700264 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
265 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800266 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
267 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700268 private static final int CMD_GET_MODEM_STATUS = 70;
269 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700270 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
271 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700272 private static final int CMD_ERASE_MODEM_CONFIG = 74;
273 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800274 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
275 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
276 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
277 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800278 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
279 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800280 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700281
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800282 // Parameters of select command.
283 private static final int SELECT_COMMAND = 0xA4;
284 private static final int SELECT_P1 = 0x04;
285 private static final int SELECT_P2 = 0;
286 private static final int SELECT_P3 = 0x10;
287
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700288 /** The singleton instance. */
289 private static PhoneInterfaceManager sInstance;
290
Wink Saville3ab207e2014-11-20 13:07:20 -0800291 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800292 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800293 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700294 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800295 private AppOpsManager mAppOps;
296 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800297 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800298 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700299 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700300
Peter Wangdafb9ac2020-01-15 14:13:38 -0800301 /** User Activity */
302 private AtomicBoolean mNotifyUserActivity;
303 private static final String ACTION_USER_ACTIVITY_NOTIFICATION =
304 "android.intent.action.USER_ACTIVITY_NOTIFICATION";
305 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
306
Derek Tan97ebb422014-09-05 16:55:38 -0700307 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
308 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800309 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800310 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700311
Michelecea4cf22018-12-21 15:00:11 -0800312 // String to store multi SIM allowed
313 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
314
Derek Tan740e1672017-06-27 14:56:27 -0700315 // The AID of ISD-R.
316 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
317
yinxub1bed742017-04-17 11:45:04 -0700318 private NetworkScanRequestTracker mNetworkScanRequestTracker;
319
David Kelly5e06a7f2018-03-12 14:10:59 +0000320 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
321 private static final int MANUFACTURER_CODE_LENGTH = 8;
322
Derek Tan89e89d42014-07-08 17:00:10 -0700323 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700324 * Experiment flag to enable erase modem config on reset network, default value is false
325 */
326 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
327 "reset_network_erase_modem_config_enabled";
328
329 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700330 * A request object to use for transmitting data to an ICC.
331 */
332 private static final class IccAPDUArgument {
333 public int channel, cla, command, p1, p2, p3;
334 public String data;
335
336 public IccAPDUArgument(int channel, int cla, int command,
337 int p1, int p2, int p3, String data) {
338 this.channel = channel;
339 this.cla = cla;
340 this.command = command;
341 this.p1 = p1;
342 this.p2 = p2;
343 this.p3 = p3;
344 this.data = data;
345 }
346 }
347
348 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700349 * A request object to use for transmitting data to an ICC.
350 */
351 private static final class ManualNetworkSelectionArgument {
352 public OperatorInfo operatorInfo;
353 public boolean persistSelection;
354
355 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
356 this.operatorInfo = operatorInfo;
357 this.persistSelection = persistSelection;
358 }
359 }
360
361 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
363 * request after sending. The main thread will notify the request when it is complete.
364 */
365 private static final class MainThreadRequest {
366 /** The argument to use for the request */
367 public Object argument;
368 /** The result of the request that is run on the main thread */
369 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800370 // The subscriber id that this request applies to. Defaults to
371 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
372 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373
Nathan Harold92bed182018-10-12 18:16:49 -0700374 // In cases where subId is unavailable, the caller needs to specify the phone.
375 public Phone phone;
376
vagdeviaf9a5b92018-08-15 16:01:53 -0700377 public WorkSource workSource;
378
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700379 public MainThreadRequest(Object argument) {
380 this.argument = argument;
381 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800382
Nathan Harold92bed182018-10-12 18:16:49 -0700383 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
384 this.argument = argument;
385 if (phone != null) {
386 this.phone = phone;
387 }
388 this.workSource = workSource;
389 }
390
vagdeviaf9a5b92018-08-15 16:01:53 -0700391 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800392 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800393 if (subId != null) {
394 this.subId = subId;
395 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700396 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800397 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398 }
399
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800400 private static final class IncomingThirdPartyCallArgs {
401 public final ComponentName component;
402 public final String callId;
403 public final String callerDisplayName;
404
405 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
406 String callerDisplayName) {
407 this.component = component;
408 this.callId = callId;
409 this.callerDisplayName = callerDisplayName;
410 }
411 }
412
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413 /**
414 * A handler that processes messages on the main thread in the phone process. Since many
415 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
416 * inbound binder threads to the main thread in the phone process. The Binder thread
417 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
418 * on, which will be notified when the operation completes and will contain the result of the
419 * request.
420 *
421 * <p>If a MainThreadRequest object is provided in the msg.obj field,
422 * note that request.result must be set to something non-null for the calling thread to
423 * unblock.
424 */
425 private final class MainThreadHandler extends Handler {
426 @Override
427 public void handleMessage(Message msg) {
428 MainThreadRequest request;
429 Message onCompleted;
430 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800431 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700432 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800433 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434
435 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700436 case CMD_HANDLE_USSD_REQUEST: {
437 request = (MainThreadRequest) msg.obj;
438 final Phone phone = getPhoneFromRequest(request);
439 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
440 String ussdRequest = ussdObject.first;
441 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700442
Pengquan Menga1bb6272018-09-06 09:59:22 -0700443 if (!isUssdApiAllowed(request.subId)) {
444 // Carrier does not support use of this API, return failure.
445 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
446 UssdResponse response = new UssdResponse(ussdRequest, null);
447 Bundle returnData = new Bundle();
448 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
449 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700450
Pengquan Menga1bb6272018-09-06 09:59:22 -0700451 request.result = true;
452 notifyRequester(request);
453 return;
454 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700455
Pengquan Menga1bb6272018-09-06 09:59:22 -0700456 try {
457 request.result = phone != null
458 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
459 } catch (CallStateException cse) {
460 request.result = false;
461 }
462 // Wake up the requesting thread
463 notifyRequester(request);
464 break;
pkanwar32d516d2016-10-14 19:37:38 -0700465 }
466
Yorke Lee716f67e2015-06-17 15:39:16 -0700467 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700468 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700469 final Phone phone = getPhoneFromRequest(request);
470 request.result = phone != null ?
471 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
472 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700473 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700474 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700475 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700476 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700477
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700478 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700479 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700480 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800481 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700482 if (uiccCard == null) {
483 loge("iccTransmitApduLogicalChannel: No UICC");
484 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700485 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700486 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
488 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700489 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 iccArgument.channel, iccArgument.cla, iccArgument.command,
491 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700492 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700493 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700494 break;
495
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700497 ar = (AsyncResult) msg.obj;
498 request = (MainThreadRequest) ar.userObj;
499 if (ar.exception == null && ar.result != null) {
500 request.result = ar.result;
501 } else {
502 request.result = new IccIoResult(0x6F, 0, (byte[])null);
503 if (ar.result == null) {
504 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800505 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700506 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800507 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700508 } else {
509 loge("iccTransmitApduLogicalChannel: Unknown exception");
510 }
511 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700512 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700513 break;
514
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700515 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
516 request = (MainThreadRequest) msg.obj;
517 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800518 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700519 if (uiccCard == null) {
520 loge("iccTransmitApduBasicChannel: No UICC");
521 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700522 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 } else {
524 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
525 request);
526 uiccCard.iccTransmitApduBasicChannel(
527 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
528 iccArgument.p3, iccArgument.data, onCompleted);
529 }
530 break;
531
532 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
533 ar = (AsyncResult) msg.obj;
534 request = (MainThreadRequest) ar.userObj;
535 if (ar.exception == null && ar.result != null) {
536 request.result = ar.result;
537 } else {
538 request.result = new IccIoResult(0x6F, 0, (byte[])null);
539 if (ar.result == null) {
540 loge("iccTransmitApduBasicChannel: Empty response");
541 } else if (ar.exception instanceof CommandException) {
542 loge("iccTransmitApduBasicChannel: CommandException: " +
543 ar.exception);
544 } else {
545 loge("iccTransmitApduBasicChannel: Unknown exception");
546 }
547 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700548 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700549 break;
550
551 case CMD_EXCHANGE_SIM_IO:
552 request = (MainThreadRequest) msg.obj;
553 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800554 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700555 if (uiccCard == null) {
556 loge("iccExchangeSimIO: No UICC");
557 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700558 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700559 } else {
560 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
561 request);
562 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
563 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
564 iccArgument.data, onCompleted);
565 }
566 break;
567
568 case EVENT_EXCHANGE_SIM_IO_DONE:
569 ar = (AsyncResult) msg.obj;
570 request = (MainThreadRequest) ar.userObj;
571 if (ar.exception == null && ar.result != null) {
572 request.result = ar.result;
573 } else {
574 request.result = new IccIoResult(0x6f, 0, (byte[])null);
575 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700576 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700577 break;
578
Derek Tan4d5e5c12014-02-04 11:54:58 -0800579 case CMD_SEND_ENVELOPE:
580 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800581 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700582 if (uiccCard == null) {
583 loge("sendEnvelopeWithStatus: No UICC");
584 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700585 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700586 } else {
587 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
588 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
589 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800590 break;
591
592 case EVENT_SEND_ENVELOPE_DONE:
593 ar = (AsyncResult) msg.obj;
594 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700595 if (ar.exception == null && ar.result != null) {
596 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800597 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700598 request.result = new IccIoResult(0x6F, 0, (byte[])null);
599 if (ar.result == null) {
600 loge("sendEnvelopeWithStatus: Empty response");
601 } else if (ar.exception instanceof CommandException) {
602 loge("sendEnvelopeWithStatus: CommandException: " +
603 ar.exception);
604 } else {
605 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
606 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800607 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700608 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800609 break;
610
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 case CMD_OPEN_CHANNEL:
612 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800613 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800614 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700615 if (uiccCard == null) {
616 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800617 request.result = new IccOpenLogicalChannelResponse(-1,
618 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700620 } else {
621 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800622 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
623 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700624 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 break;
626
627 case EVENT_OPEN_CHANNEL_DONE:
628 ar = (AsyncResult) msg.obj;
629 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700632 int[] result = (int[]) ar.result;
633 int channelId = result[0];
634 byte[] selectResponse = null;
635 if (result.length > 1) {
636 selectResponse = new byte[result.length - 1];
637 for (int i = 1; i < result.length; ++i) {
638 selectResponse[i - 1] = (byte) result[i];
639 }
640 }
641 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700642 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 if (ar.result == null) {
645 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700647 if (ar.exception != null) {
648 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
649 }
650
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700651 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700652 if (ar.exception instanceof CommandException) {
653 CommandException.Error error =
654 ((CommandException) (ar.exception)).getCommandError();
655 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700656 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700657 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700658 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700659 }
660 }
661 openChannelResp = new IccOpenLogicalChannelResponse(
662 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700664 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700665 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700666 break;
667
668 case CMD_CLOSE_CHANNEL:
669 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800670 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700671 if (uiccCard == null) {
672 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900673 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700674 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700675 } else {
676 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
677 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
678 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 break;
680
681 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800682 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
683 break;
684
685 case CMD_NV_READ_ITEM:
686 request = (MainThreadRequest) msg.obj;
687 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800688 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
689 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800690 break;
691
692 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700693 ar = (AsyncResult) msg.obj;
694 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800695 if (ar.exception == null && ar.result != null) {
696 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700697 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800698 request.result = "";
699 if (ar.result == null) {
700 loge("nvReadItem: Empty response");
701 } else if (ar.exception instanceof CommandException) {
702 loge("nvReadItem: CommandException: " +
703 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700704 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800705 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 }
707 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700708 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700709 break;
710
Jake Hambye994d462014-02-03 13:10:13 -0800711 case CMD_NV_WRITE_ITEM:
712 request = (MainThreadRequest) msg.obj;
713 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
714 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800715 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700716 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800717 break;
718
719 case EVENT_NV_WRITE_ITEM_DONE:
720 handleNullReturnEvent(msg, "nvWriteItem");
721 break;
722
723 case CMD_NV_WRITE_CDMA_PRL:
724 request = (MainThreadRequest) msg.obj;
725 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800726 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800727 break;
728
729 case EVENT_NV_WRITE_CDMA_PRL_DONE:
730 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
731 break;
732
chen xu6dac5ab2018-10-26 17:39:23 -0700733 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800734 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700735 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800736 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800737 break;
738
chen xu6dac5ab2018-10-26 17:39:23 -0700739 case EVENT_RESET_MODEM_CONFIG_DONE:
740 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800741 break;
742
Jake Hamby7c27be32014-03-03 13:25:59 -0800743 case CMD_GET_PREFERRED_NETWORK_TYPE:
744 request = (MainThreadRequest) msg.obj;
745 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700746 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800747 break;
748
749 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
750 ar = (AsyncResult) msg.obj;
751 request = (MainThreadRequest) ar.userObj;
752 if (ar.exception == null && ar.result != null) {
753 request.result = ar.result; // Integer
754 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800755 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800756 if (ar.result == null) {
757 loge("getPreferredNetworkType: Empty response");
758 } else if (ar.exception instanceof CommandException) {
759 loge("getPreferredNetworkType: CommandException: " +
760 ar.exception);
761 } else {
762 loge("getPreferredNetworkType: Unknown exception");
763 }
764 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700765 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800766 break;
767
768 case CMD_SET_PREFERRED_NETWORK_TYPE:
769 request = (MainThreadRequest) msg.obj;
770 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
771 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700772 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800773 break;
774
775 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
776 handleNullReturnEvent(msg, "setPreferredNetworkType");
777 break;
778
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000779 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
780 request = (MainThreadRequest)msg.obj;
781 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800782 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000783 break;
784
785 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
786 ar = (AsyncResult)msg.obj;
787 request = (MainThreadRequest)ar.userObj;
788 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700789 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000790 break;
791
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800792 case CMD_SET_VOICEMAIL_NUMBER:
793 request = (MainThreadRequest) msg.obj;
794 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
795 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800796 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
797 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800798 break;
799
800 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
801 handleNullReturnEvent(msg, "setVoicemailNumber");
802 break;
803
Stuart Scott54788802015-03-30 13:18:01 -0700804 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
805 request = (MainThreadRequest) msg.obj;
806 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
807 request);
808 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
809 break;
810
811 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
812 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
813 break;
814
Shishir Agrawal302c8692015-06-19 13:49:39 -0700815 case CMD_PERFORM_NETWORK_SCAN:
816 request = (MainThreadRequest) msg.obj;
817 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
818 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
819 break;
820
821 case EVENT_PERFORM_NETWORK_SCAN_DONE:
822 ar = (AsyncResult) msg.obj;
823 request = (MainThreadRequest) ar.userObj;
824 CellNetworkScanResult cellScanResult;
825 if (ar.exception == null && ar.result != null) {
826 cellScanResult = new CellNetworkScanResult(
827 CellNetworkScanResult.STATUS_SUCCESS,
828 (List<OperatorInfo>) ar.result);
829 } else {
830 if (ar.result == null) {
831 loge("getCellNetworkScanResults: Empty response");
832 }
833 if (ar.exception != null) {
834 loge("getCellNetworkScanResults: Exception: " + ar.exception);
835 }
836 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
837 if (ar.exception instanceof CommandException) {
838 CommandException.Error error =
839 ((CommandException) (ar.exception)).getCommandError();
840 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
841 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
842 } else if (error == CommandException.Error.GENERIC_FAILURE) {
843 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
844 }
845 }
846 cellScanResult = new CellNetworkScanResult(errorCode, null);
847 }
848 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700849 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700850 break;
851
852 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
853 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700854 ManualNetworkSelectionArgument selArg =
855 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700856 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
857 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700858 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
859 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700860 break;
861
862 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700863 ar = (AsyncResult) msg.obj;
864 request = (MainThreadRequest) ar.userObj;
865 if (ar.exception == null) {
866 request.result = true;
867 } else {
868 request.result = false;
869 loge("setNetworkSelectionModeManual " + ar.exception);
870 }
871 notifyRequester(request);
872 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700873 break;
874
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700875 case CMD_GET_MODEM_ACTIVITY_INFO:
876 request = (MainThreadRequest) msg.obj;
877 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700878 if (defaultPhone != null) {
879 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
880 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700881 break;
882
883 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
884 ar = (AsyncResult) msg.obj;
885 request = (MainThreadRequest) ar.userObj;
886 if (ar.exception == null && ar.result != null) {
887 request.result = ar.result;
888 } else {
889 if (ar.result == null) {
890 loge("queryModemActivityInfo: Empty response");
891 } else if (ar.exception instanceof CommandException) {
892 loge("queryModemActivityInfo: CommandException: " +
893 ar.exception);
894 } else {
895 loge("queryModemActivityInfo: Unknown exception");
896 }
897 }
Amit Mahajand4766222016-01-28 15:28:28 -0800898 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
899 if (request.result == null) {
Peter Collingbournec00e9022019-11-26 09:56:26 -0800900 request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800901 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700902 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700903 break;
904
Meng Wang1a7c35a2016-05-05 20:56:15 -0700905 case CMD_SET_ALLOWED_CARRIERS:
906 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800907 CarrierRestrictionRules argument =
908 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700909 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800910 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700911 break;
912
913 case EVENT_SET_ALLOWED_CARRIERS_DONE:
914 ar = (AsyncResult) msg.obj;
915 request = (MainThreadRequest) ar.userObj;
916 if (ar.exception == null && ar.result != null) {
917 request.result = ar.result;
918 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800919 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
920 if (ar.exception instanceof CommandException) {
921 loge("setAllowedCarriers: CommandException: " + ar.exception);
922 CommandException.Error error =
923 ((CommandException) (ar.exception)).getCommandError();
924 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
925 request.result =
926 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
927 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700928 } else {
929 loge("setAllowedCarriers: Unknown exception");
930 }
931 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700932 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700933 break;
934
935 case CMD_GET_ALLOWED_CARRIERS:
936 request = (MainThreadRequest) msg.obj;
937 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800938 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700939 break;
940
941 case EVENT_GET_ALLOWED_CARRIERS_DONE:
942 ar = (AsyncResult) msg.obj;
943 request = (MainThreadRequest) ar.userObj;
944 if (ar.exception == null && ar.result != null) {
945 request.result = ar.result;
946 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800947 request.result = new IllegalStateException(
948 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700949 if (ar.result == null) {
950 loge("getAllowedCarriers: Empty response");
951 } else if (ar.exception instanceof CommandException) {
952 loge("getAllowedCarriers: CommandException: " +
953 ar.exception);
954 } else {
955 loge("getAllowedCarriers: Unknown exception");
956 }
957 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700958 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700959 break;
960
Nathan Haroldb3014052017-01-25 15:57:32 -0800961 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
962 ar = (AsyncResult) msg.obj;
963 request = (MainThreadRequest) ar.userObj;
964 if (ar.exception == null && ar.result != null) {
965 request.result = ar.result;
966 } else {
967 request.result = new IllegalArgumentException(
968 "Failed to retrieve Forbidden Plmns");
969 if (ar.result == null) {
970 loge("getForbiddenPlmns: Empty response");
971 } else {
972 loge("getForbiddenPlmns: Unknown exception");
973 }
974 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700975 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800976 break;
977
978 case CMD_GET_FORBIDDEN_PLMNS:
979 request = (MainThreadRequest) msg.obj;
980 uiccCard = getUiccCardFromRequest(request);
981 if (uiccCard == null) {
982 loge("getForbiddenPlmns() UiccCard is null");
983 request.result = new IllegalArgumentException(
984 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700985 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800986 break;
987 }
988 Integer appType = (Integer) request.argument;
989 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
990 if (uiccApp == null) {
991 loge("getForbiddenPlmns() no app with specified type -- "
992 + appType);
993 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700994 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800995 break;
996 } else {
997 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
998 + " specified type -- " + appType);
999 }
1000 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1001 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1002 onCompleted);
1003 break;
1004
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001005 case CMD_SWITCH_SLOTS:
1006 request = (MainThreadRequest) msg.obj;
1007 int[] physicalSlots = (int[]) request.argument;
1008 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1009 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1010 break;
1011
1012 case EVENT_SWITCH_SLOTS_DONE:
1013 ar = (AsyncResult) msg.obj;
1014 request = (MainThreadRequest) ar.userObj;
1015 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001016 notifyRequester(request);
1017 break;
1018 case CMD_GET_NETWORK_SELECTION_MODE:
1019 request = (MainThreadRequest) msg.obj;
1020 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1021 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1022 break;
1023
1024 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1025 ar = (AsyncResult) msg.obj;
1026 request = (MainThreadRequest) ar.userObj;
1027 if (ar.exception != null) {
1028 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1029 } else {
1030 int mode = ((int[]) ar.result)[0];
1031 if (mode == 0) {
1032 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1033 } else {
1034 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1035 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001036 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001037 notifyRequester(request);
1038 break;
1039 case CMD_GET_CDMA_ROAMING_MODE:
1040 request = (MainThreadRequest) msg.obj;
1041 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1042 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1043 break;
1044 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1045 ar = (AsyncResult) msg.obj;
1046 request = (MainThreadRequest) ar.userObj;
1047 if (ar.exception != null) {
1048 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1049 } else {
1050 request.result = ((int[]) ar.result)[0];
1051 }
1052 notifyRequester(request);
1053 break;
1054 case CMD_SET_CDMA_ROAMING_MODE:
1055 request = (MainThreadRequest) msg.obj;
1056 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1057 int mode = (int) request.argument;
1058 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1059 break;
1060 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1061 ar = (AsyncResult) msg.obj;
1062 request = (MainThreadRequest) ar.userObj;
1063 request.result = ar.exception == null;
1064 notifyRequester(request);
1065 break;
1066 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1067 request = (MainThreadRequest) msg.obj;
1068 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1069 int subscriptionMode = (int) request.argument;
1070 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1071 break;
1072 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1073 ar = (AsyncResult) msg.obj;
1074 request = (MainThreadRequest) ar.userObj;
1075 request.result = ar.exception == null;
1076 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001077 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001078 case CMD_GET_ALL_CELL_INFO:
1079 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001080 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001081 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001082 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001083 case EVENT_GET_ALL_CELL_INFO_DONE:
1084 ar = (AsyncResult) msg.obj;
1085 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001086 // If a timeout occurs, the response will be null
1087 request.result = (ar.exception == null && ar.result != null)
1088 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001089 synchronized (request) {
1090 request.notifyAll();
1091 }
1092 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001093 case CMD_REQUEST_CELL_INFO_UPDATE:
1094 request = (MainThreadRequest) msg.obj;
1095 request.phone.requestCellInfoUpdate(request.workSource,
1096 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1097 break;
1098 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1099 ar = (AsyncResult) msg.obj;
1100 request = (MainThreadRequest) ar.userObj;
1101 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1102 try {
1103 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001104 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001105 cb.onError(
1106 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1107 ar.exception.getClass().getName(),
1108 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001109 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001110 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001111 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001112 } else {
1113 // use the result as returned
1114 cb.onCellInfo((List<CellInfo>) ar.result);
1115 }
1116 } catch (RemoteException re) {
1117 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1118 }
1119 break;
1120 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001121 request = (MainThreadRequest) msg.obj;
1122 WorkSource ws = (WorkSource) request.argument;
1123 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001124 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001125 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001126 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001127 ar = (AsyncResult) msg.obj;
1128 request = (MainThreadRequest) ar.userObj;
1129 if (ar.exception == null) {
1130 request.result = ar.result;
1131 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001132 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001133 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001134 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001135 }
1136
1137 synchronized (request) {
1138 request.notifyAll();
1139 }
1140 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001141 case CMD_MODEM_REBOOT:
1142 request = (MainThreadRequest) msg.obj;
1143 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001144 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001145 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001146 case EVENT_CMD_MODEM_REBOOT_DONE:
1147 handleNullReturnEvent(msg, "rebootModem");
1148 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001149 case CMD_REQUEST_ENABLE_MODEM:
1150 request = (MainThreadRequest) msg.obj;
1151 boolean enable = (boolean) request.argument;
1152 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001153 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001154 PhoneConfigurationManager.getInstance()
1155 .enablePhone(request.phone, enable, onCompleted);
1156 break;
1157 case EVENT_ENABLE_MODEM_DONE:
1158 ar = (AsyncResult) msg.obj;
1159 request = (MainThreadRequest) ar.userObj;
1160 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001161 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001162 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001163 if ((boolean) request.result) {
1164 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1165 updateModemStateMetrics();
1166 } else {
1167 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1168 + ar.exception);
1169 }
1170 notifyRequester(request);
1171 break;
1172 case CMD_GET_MODEM_STATUS:
1173 request = (MainThreadRequest) msg.obj;
1174 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1175 PhoneConfigurationManager.getInstance()
1176 .getPhoneStatusFromModem(request.phone, onCompleted);
1177 break;
1178 case EVENT_GET_MODEM_STATUS_DONE:
1179 ar = (AsyncResult) msg.obj;
1180 request = (MainThreadRequest) ar.userObj;
1181 int id = request.phone.getPhoneId();
1182 if (ar.exception == null && ar.result != null) {
1183 request.result = ar.result;
1184 //update the cache as modem status has changed
1185 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1186 (boolean) request.result);
1187 } else {
1188 // Return true if modem status cannot be retrieved. For most cases,
1189 // modem status is on. And for older version modems, GET_MODEM_STATUS
1190 // and disable modem are not supported. Modem is always on.
1191 // TODO: this should be fixed in R to support a third
1192 // status UNKNOWN b/131631629
1193 request.result = true;
1194 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1195 + ar.exception);
1196 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001197 notifyRequester(request);
1198 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001199 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1200 request = (MainThreadRequest) msg.obj;
1201 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1202 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1203 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1204 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1205 break;
1206 }
1207 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1208 ar = (AsyncResult) msg.obj;
1209 request = (MainThreadRequest) ar.userObj;
1210 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1211 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1212 args.second.accept(ar.exception == null);
1213 notifyRequester(request);
1214 break;
1215 }
yincheng zhao2737e882019-09-06 17:06:54 -07001216 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1217 ar = (AsyncResult) msg.obj;
1218 request = (MainThreadRequest) ar.userObj;
1219 if (ar.exception == null && ar.result != null) {
1220 request.result = ar.result;
1221 } else {
1222 request.result = -1;
1223 loge("Failed to set Forbidden Plmns");
1224 if (ar.result == null) {
1225 loge("setForbidenPlmns: Empty response");
1226 } else if (ar.exception != null) {
1227 loge("setForbiddenPlmns: Exception: " + ar.exception);
1228 request.result = -1;
1229 } else {
1230 loge("setForbiddenPlmns: Unknown exception");
1231 }
1232 }
1233 notifyRequester(request);
1234 break;
1235 case CMD_SET_FORBIDDEN_PLMNS:
1236 request = (MainThreadRequest) msg.obj;
1237 uiccCard = getUiccCardFromRequest(request);
1238 if (uiccCard == null) {
1239 loge("setForbiddenPlmns: UiccCard is null");
1240 request.result = -1;
1241 notifyRequester(request);
1242 break;
1243 }
1244 Pair<Integer, List<String>> setFplmnsArgs =
1245 (Pair<Integer, List<String>>) request.argument;
1246 appType = setFplmnsArgs.first;
1247 List<String> fplmns = setFplmnsArgs.second;
1248 uiccApp = uiccCard.getApplicationByType(appType);
1249 if (uiccApp == null) {
1250 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1251 request.result = -1;
1252 loge("Failed to get UICC App");
1253 notifyRequester(request);
1254 } else {
1255 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1256 ((SIMRecords) uiccApp.getIccRecords())
1257 .setForbiddenPlmns(onCompleted, fplmns);
1258 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001259 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001260 case CMD_ERASE_MODEM_CONFIG:
1261 request = (MainThreadRequest) msg.obj;
1262 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1263 defaultPhone.eraseModemConfig(onCompleted);
1264 break;
1265 case EVENT_ERASE_MODEM_CONFIG_DONE:
1266 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001267 break;
zoey chene02881a2019-12-30 16:11:23 +08001268
1269 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1270 request = (MainThreadRequest) msg.obj;
1271 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1272 Pair<String, String> changed = (Pair<String, String>) request.argument;
1273 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1274 changed.first, changed.second, onCompleted);
1275 break;
1276 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1277 ar = (AsyncResult) msg.obj;
1278 request = (MainThreadRequest) ar.userObj;
1279 if (ar.exception == null) {
1280 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1281 } else {
1282 request.result = msg.arg1;
1283 }
1284 notifyRequester(request);
1285 break;
1286
1287 case CMD_SET_ICC_LOCK_ENABLED:
1288 request = (MainThreadRequest) msg.obj;
1289 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1290 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1291 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1292 enabled.first, enabled.second, onCompleted);
1293 break;
1294 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1295 ar = (AsyncResult) msg.obj;
1296 request = (MainThreadRequest) ar.userObj;
1297 if (ar.exception == null) {
1298 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1299 } else {
1300 request.result = msg.arg1;
1301 }
1302 notifyRequester(request);
1303 break;
1304
Peter Wangdafb9ac2020-01-15 14:13:38 -08001305 case MSG_NOTIFY_USER_ACTIVITY:
1306 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
1307 Intent intent = new Intent(ACTION_USER_ACTIVITY_NOTIFICATION);
1308 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1309 getDefaultPhone().getContext().sendBroadcastAsUser(
1310 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1311 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001312 default:
1313 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1314 break;
1315 }
1316 }
Jake Hambye994d462014-02-03 13:10:13 -08001317
Pengquan Menga1bb6272018-09-06 09:59:22 -07001318 private void notifyRequester(MainThreadRequest request) {
1319 synchronized (request) {
1320 request.notifyAll();
1321 }
1322 }
1323
Jake Hambye994d462014-02-03 13:10:13 -08001324 private void handleNullReturnEvent(Message msg, String command) {
1325 AsyncResult ar = (AsyncResult) msg.obj;
1326 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1327 if (ar.exception == null) {
1328 request.result = true;
1329 } else {
1330 request.result = false;
1331 if (ar.exception instanceof CommandException) {
1332 loge(command + ": CommandException: " + ar.exception);
1333 } else {
1334 loge(command + ": Unknown exception");
1335 }
1336 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001337 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001338 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001339 }
1340
1341 /**
1342 * Posts the specified command to be executed on the main thread,
1343 * waits for the request to complete, and returns the result.
1344 * @see #sendRequestAsync
1345 */
1346 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001347 return sendRequest(
1348 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001349 }
1350
1351 /**
1352 * Posts the specified command to be executed on the main thread,
1353 * waits for the request to complete, and returns the result.
1354 * @see #sendRequestAsync
1355 */
1356 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1357 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001358 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001359 }
1360
1361 /**
1362 * Posts the specified command to be executed on the main thread,
1363 * waits for the request to complete, and returns the result.
1364 * @see #sendRequestAsync
1365 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001366 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001367 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001368 }
1369
1370 /**
1371 * Posts the specified command to be executed on the main thread,
1372 * waits for the request to complete, and returns the result.
1373 * @see #sendRequestAsync
1374 */
Nathan Harold92bed182018-10-12 18:16:49 -07001375 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1376 return sendRequest(command, argument, subId, null, workSource);
1377 }
1378
1379 /**
1380 * Posts the specified command to be executed on the main thread,
1381 * waits for the request to complete, and returns the result.
1382 * @see #sendRequestAsync
1383 */
1384 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1385 return sendRequest(
1386 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1387 }
1388
1389 /**
1390 * Posts the specified command to be executed on the main thread,
1391 * waits for the request to complete, and returns the result.
1392 * @see #sendRequestAsync
1393 */
1394 private Object sendRequest(
1395 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001396 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1397 throw new RuntimeException("This method will deadlock if called from the main thread.");
1398 }
1399
Nathan Harold92bed182018-10-12 18:16:49 -07001400 MainThreadRequest request = null;
1401 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1402 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1403 } else if (phone != null) {
1404 request = new MainThreadRequest(argument, phone, workSource);
1405 } else {
1406 request = new MainThreadRequest(argument, subId, workSource);
1407 }
1408
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001409 Message msg = mMainThreadHandler.obtainMessage(command, request);
1410 msg.sendToTarget();
1411
1412 // Wait for the request to complete
1413 synchronized (request) {
1414 while (request.result == null) {
1415 try {
1416 request.wait();
1417 } catch (InterruptedException e) {
1418 // Do nothing, go back and wait until the request is complete
1419 }
1420 }
1421 }
1422 return request.result;
1423 }
1424
1425 /**
1426 * Asynchronous ("fire and forget") version of sendRequest():
1427 * Posts the specified command to be executed on the main thread, and
1428 * returns immediately.
1429 * @see #sendRequest
1430 */
1431 private void sendRequestAsync(int command) {
1432 mMainThreadHandler.sendEmptyMessage(command);
1433 }
1434
1435 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001436 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001437 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001438 */
1439 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001440 sendRequestAsync(command, argument, null, null);
1441 }
1442
1443 /**
1444 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1445 * @see {@link #sendRequest(int,Object)}
1446 */
1447 private void sendRequestAsync(
1448 int command, Object argument, Phone phone, WorkSource workSource) {
1449 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001450 Message msg = mMainThreadHandler.obtainMessage(command, request);
1451 msg.sendToTarget();
1452 }
1453
1454 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001455 * Initialize the singleton PhoneInterfaceManager instance.
1456 * This is only done once, at startup, from PhoneApp.onCreate().
1457 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001458 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459 synchronized (PhoneInterfaceManager.class) {
1460 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001461 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001462 } else {
1463 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1464 }
1465 return sInstance;
1466 }
1467 }
1468
1469 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001470 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001471 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001472 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001473 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001474 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001475 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1476 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001477 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001478 mTelephonySharedPreferences =
1479 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001480 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001481 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001482
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001483 publish();
1484 }
1485
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001486 private Phone getDefaultPhone() {
1487 Phone thePhone = getPhone(getDefaultSubscription());
1488 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1489 }
1490
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001491 private void publish() {
1492 if (DBG) log("publish: " + this);
1493
Peter Wangc035ce42020-01-08 21:00:22 -08001494 TelephonyFrameworkInitializer
1495 .getTelephonyServiceManager()
1496 .getTelephonyServiceRegisterer()
1497 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001498 }
1499
Stuart Scott584921c2015-01-15 17:10:34 -08001500 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001501 if (request.phone != null) {
1502 return request.phone;
1503 } else {
1504 return getPhoneFromSubId(request.subId);
1505 }
1506 }
1507
1508 private Phone getPhoneFromSubId(int subId) {
1509 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1510 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001511 }
1512
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001513 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1514 Phone phone = getPhoneFromRequest(request);
1515 return phone == null ? null :
1516 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1517 }
1518
Wink Saville36469e72014-06-11 15:17:00 -07001519 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001520 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001521 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001522 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001523
Naina Nallurid63128d2019-09-17 14:10:30 -07001524 private void sendEraseModemConfig(Phone phone) {
1525 if (phone != null) {
1526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1527 mApp, phone.getSubId(), "eraseModemConfig");
1528 final long identity = Binder.clearCallingIdentity();
1529 try {
1530 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1531 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1532 } finally {
1533 Binder.restoreCallingIdentity(identity);
1534 }
1535 }
1536 }
1537
Peter Wang44b186e2020-01-13 23:33:09 -08001538 private boolean isImsAvailableOnDevice() {
1539 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1540 if (pm == null) {
1541 // For some reason package manger is not available.. This will fail internally anyway,
1542 // so do not throw error and allow.
1543 return true;
1544 }
1545 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1546 }
1547
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001548 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001549 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001550 }
1551
Wink Savilleb564aae2014-10-23 10:18:09 -07001552 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001553 if (DBG) log("dial: " + number);
1554 // No permission check needed here: This is just a wrapper around the
1555 // ACTION_DIAL intent, which is available to any app since it puts up
1556 // the UI before it does anything.
1557
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001558 final long identity = Binder.clearCallingIdentity();
1559 try {
1560 String url = createTelUrl(number);
1561 if (url == null) {
1562 return;
1563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001564
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001565 // PENDING: should we just silently fail if phone is offhook or ringing?
1566 PhoneConstants.State state = mCM.getState(subId);
1567 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1568 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1569 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1570 mApp.startActivity(intent);
1571 }
1572 } finally {
1573 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001574 }
1575 }
1576
1577 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001578 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001579 }
1580
Wink Savilleb564aae2014-10-23 10:18:09 -07001581 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001582 if (DBG) log("call: " + number);
1583
1584 // This is just a wrapper around the ACTION_CALL intent, but we still
1585 // need to do a permission check since we're calling startActivity()
1586 // from the context of the phone app.
1587 enforceCallPermission();
1588
Jordan Liu1617b712019-07-10 15:06:26 -07001589 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001590 != AppOpsManager.MODE_ALLOWED) {
1591 return;
1592 }
1593
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001594 final long identity = Binder.clearCallingIdentity();
1595 try {
1596 String url = createTelUrl(number);
1597 if (url == null) {
1598 return;
1599 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001600
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001601 boolean isValid = false;
1602 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1603 if (slist != null) {
1604 for (SubscriptionInfo subInfoRecord : slist) {
1605 if (subInfoRecord.getSubscriptionId() == subId) {
1606 isValid = true;
1607 break;
1608 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001609 }
Wink Saville08874612014-08-31 19:19:58 -07001610 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001611 if (!isValid) {
1612 return;
1613 }
Wink Saville08874612014-08-31 19:19:58 -07001614
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001615 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1616 intent.putExtra(SUBSCRIPTION_KEY, subId);
1617 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1618 mApp.startActivity(intent);
1619 } finally {
1620 Binder.restoreCallingIdentity(identity);
1621 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001622 }
1623
Wink Savilleb564aae2014-10-23 10:18:09 -07001624 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001625 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001626 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1627 }
1628
Wink Savilleb564aae2014-10-23 10:18:09 -07001629 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001630 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001631 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1632 }
1633
Wink Savilleb564aae2014-10-23 10:18:09 -07001634 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001635 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001636
1637 final long identity = Binder.clearCallingIdentity();
1638 try {
1639 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1640 checkSimPin.start();
1641 return checkSimPin.unlockSim(null, pin);
1642 } finally {
1643 Binder.restoreCallingIdentity(identity);
1644 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001645 }
1646
Wink Savilleb564aae2014-10-23 10:18:09 -07001647 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001648 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001649
1650 final long identity = Binder.clearCallingIdentity();
1651 try {
1652 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1653 checkSimPuk.start();
1654 return checkSimPuk.unlockSim(puk, pin);
1655 } finally {
1656 Binder.restoreCallingIdentity(identity);
1657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 }
1659
1660 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001661 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001662 * a synchronous one.
1663 */
1664 private static class UnlockSim extends Thread {
1665
1666 private final IccCard mSimCard;
1667
1668 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001669 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1670 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671
1672 // For replies from SimCard interface
1673 private Handler mHandler;
1674
1675 // For async handler to identify request type
1676 private static final int SUPPLY_PIN_COMPLETE = 100;
1677
1678 public UnlockSim(IccCard simCard) {
1679 mSimCard = simCard;
1680 }
1681
1682 @Override
1683 public void run() {
1684 Looper.prepare();
1685 synchronized (UnlockSim.this) {
1686 mHandler = new Handler() {
1687 @Override
1688 public void handleMessage(Message msg) {
1689 AsyncResult ar = (AsyncResult) msg.obj;
1690 switch (msg.what) {
1691 case SUPPLY_PIN_COMPLETE:
1692 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1693 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001694 mRetryCount = msg.arg1;
1695 if (ar.exception != null) {
1696 if (ar.exception instanceof CommandException &&
1697 ((CommandException)(ar.exception)).getCommandError()
1698 == CommandException.Error.PASSWORD_INCORRECT) {
1699 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1700 } else {
1701 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1702 }
1703 } else {
1704 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1705 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001706 mDone = true;
1707 UnlockSim.this.notifyAll();
1708 }
1709 break;
1710 }
1711 }
1712 };
1713 UnlockSim.this.notifyAll();
1714 }
1715 Looper.loop();
1716 }
1717
1718 /*
1719 * Use PIN or PUK to unlock SIM card
1720 *
1721 * If PUK is null, unlock SIM card with PIN
1722 *
1723 * If PUK is not null, unlock SIM card with PUK and set PIN code
1724 */
Wink Saville9de0f752013-10-22 19:04:03 -07001725 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001726
1727 while (mHandler == null) {
1728 try {
1729 wait();
1730 } catch (InterruptedException e) {
1731 Thread.currentThread().interrupt();
1732 }
1733 }
1734 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1735
1736 if (puk == null) {
1737 mSimCard.supplyPin(pin, callback);
1738 } else {
1739 mSimCard.supplyPuk(puk, pin, callback);
1740 }
1741
1742 while (!mDone) {
1743 try {
1744 Log.d(LOG_TAG, "wait for done");
1745 wait();
1746 } catch (InterruptedException e) {
1747 // Restore the interrupted status
1748 Thread.currentThread().interrupt();
1749 }
1750 }
1751 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001752 int[] resultArray = new int[2];
1753 resultArray[0] = mResult;
1754 resultArray[1] = mRetryCount;
1755 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 }
1757 }
1758
1759 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001760 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001761
1762 }
1763
Wink Savilleb564aae2014-10-23 10:18:09 -07001764 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001765 // No permission check needed here: this call is harmless, and it's
1766 // needed for the ServiceState.requestStateUpdate() call (which is
1767 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001768 final long identity = Binder.clearCallingIdentity();
1769 try {
1770 final Phone phone = getPhone(subId);
1771 if (phone != null) {
1772 phone.updateServiceLocation();
1773 }
1774 } finally {
1775 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001777 }
1778
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001779 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001780 @Override
1781 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001782 return isRadioOnWithFeature(callingPackage, null);
1783 }
1784
1785
1786 @Override
1787 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1788 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1789 callingFeatureId);
1790 }
1791
1792 @Deprecated
1793 @Override
1794 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1795 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001796 }
1797
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001798 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001799 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1800 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001801 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001802 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001803 return false;
1804 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001805
1806 final long identity = Binder.clearCallingIdentity();
1807 try {
1808 return isRadioOnForSubscriber(subId);
1809 } finally {
1810 Binder.restoreCallingIdentity(identity);
1811 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001812 }
1813
1814 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001815 final long identity = Binder.clearCallingIdentity();
1816 try {
1817 final Phone phone = getPhone(subId);
1818 if (phone != null) {
1819 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1820 } else {
1821 return false;
1822 }
1823 } finally {
1824 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001825 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001826 }
1827
1828 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001829 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001830 }
Wink Saville36469e72014-06-11 15:17:00 -07001831
Wink Savilleb564aae2014-10-23 10:18:09 -07001832 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001833 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001834
1835 final long identity = Binder.clearCallingIdentity();
1836 try {
1837 final Phone phone = getPhone(subId);
1838 if (phone != null) {
1839 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1840 }
1841 } finally {
1842 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001843 }
Wink Saville36469e72014-06-11 15:17:00 -07001844 }
1845
1846 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001847 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001848 }
1849
Wink Savilleb564aae2014-10-23 10:18:09 -07001850 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001851 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001852
1853 final long identity = Binder.clearCallingIdentity();
1854 try {
1855 final Phone phone = getPhone(subId);
1856 if (phone == null) {
1857 return false;
1858 }
1859 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1860 toggleRadioOnOffForSubscriber(subId);
1861 }
1862 return true;
1863 } finally {
1864 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001865 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001866 }
Wink Saville36469e72014-06-11 15:17:00 -07001867
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001868 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08001869 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001870 /*
1871 * If any of the Radios are available, it will need to be
1872 * shutdown. So return true if any Radio is available.
1873 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001874 final long identity = Binder.clearCallingIdentity();
1875 try {
1876 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1877 Phone phone = PhoneFactory.getPhone(i);
1878 if (phone != null && phone.isRadioAvailable()) return true;
1879 }
1880 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1881 return false;
1882 } finally {
1883 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001884 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001885 }
1886
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001887 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001888 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001889 enforceModifyPermission();
1890
1891 final long identity = Binder.clearCallingIdentity();
1892 try {
1893 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1894 logv("Shutting down Phone " + i);
1895 shutdownRadioUsingPhoneId(i);
1896 }
1897 } finally {
1898 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001899 }
1900 }
1901
1902 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001903 Phone phone = PhoneFactory.getPhone(phoneId);
1904 if (phone != null && phone.isRadioAvailable()) {
1905 phone.shutdownRadio();
1906 }
1907 }
1908
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001909 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001910 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001911
1912 final long identity = Binder.clearCallingIdentity();
1913 try {
1914 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1915 if (defaultPhone != null) {
1916 defaultPhone.setRadioPower(turnOn);
1917 return true;
1918 } else {
1919 loge("There's no default phone.");
1920 return false;
1921 }
1922 } finally {
1923 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001924 }
Wink Saville36469e72014-06-11 15:17:00 -07001925 }
1926
Wink Savilleb564aae2014-10-23 10:18:09 -07001927 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001928 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001929
1930 final long identity = Binder.clearCallingIdentity();
1931 try {
1932 final Phone phone = getPhone(subId);
1933 if (phone != null) {
1934 phone.setRadioPower(turnOn);
1935 return true;
1936 } else {
1937 return false;
1938 }
1939 } finally {
1940 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001941 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 }
1943
Wink Saville36469e72014-06-11 15:17:00 -07001944 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001945 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946 public boolean enableDataConnectivity() {
1947 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001948
1949 final long identity = Binder.clearCallingIdentity();
1950 try {
1951 int subId = mSubscriptionController.getDefaultDataSubId();
1952 final Phone phone = getPhone(subId);
1953 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001954 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001955 return true;
1956 } else {
1957 return false;
1958 }
1959 } finally {
1960 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001961 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001962 }
1963
Wink Saville36469e72014-06-11 15:17:00 -07001964 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001965 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001966 public boolean disableDataConnectivity() {
1967 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001968
1969 final long identity = Binder.clearCallingIdentity();
1970 try {
1971 int subId = mSubscriptionController.getDefaultDataSubId();
1972 final Phone phone = getPhone(subId);
1973 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001974 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001975 return true;
1976 } else {
1977 return false;
1978 }
1979 } finally {
1980 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001981 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001982 }
1983
Sanket Padawe356d7632015-06-22 14:03:32 -07001984 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001985 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001986 final long identity = Binder.clearCallingIdentity();
1987 try {
1988 final Phone phone = getPhone(subId);
1989 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001990 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001991 } else {
1992 return false;
1993 }
1994 } finally {
1995 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001996 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001997 }
1998
1999 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002000 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002001 }
2002
pkanwarae03a6b2016-11-06 20:37:09 -08002003 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002004 enforceCallPermission();
2005
2006 final long identity = Binder.clearCallingIdentity();
2007 try {
2008 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2009 return;
2010 }
2011 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2012 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2013 } finally {
2014 Binder.restoreCallingIdentity(identity);
2015 }
pkanwar32d516d2016-10-14 19:37:38 -07002016 };
2017
Wink Savilleb564aae2014-10-23 10:18:09 -07002018 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002019 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002020
2021 final long identity = Binder.clearCallingIdentity();
2022 try {
2023 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2024 return false;
2025 }
2026 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2027 } finally {
2028 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002029 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002030 }
2031
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002032 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002033 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002034 }
2035
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002036 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002037 final long identity = Binder.clearCallingIdentity();
2038 try {
2039 Phone phone = PhoneFactory.getPhone(slotIndex);
2040 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2041 PhoneConstantConversions.convertCallState(phone.getState());
2042 } finally {
2043 Binder.restoreCallingIdentity(identity);
2044 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002045 }
2046
Sanket Padawe356d7632015-06-22 14:03:32 -07002047 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002048 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002049 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2050 }
2051
2052 @Override
2053 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002054 final long identity = Binder.clearCallingIdentity();
2055 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002056 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002057 if (phone != null) {
2058 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2059 } else {
2060 return PhoneConstantConversions.convertDataState(
2061 PhoneConstants.DataState.DISCONNECTED);
2062 }
2063 } finally {
2064 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002065 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002066 }
2067
Sanket Padawe356d7632015-06-22 14:03:32 -07002068 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002069 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002070 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2071 }
2072
2073 @Override
2074 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002075 final long identity = Binder.clearCallingIdentity();
2076 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002077 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002078 if (phone != null) {
2079 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2080 } else {
2081 return TelephonyManager.DATA_ACTIVITY_NONE;
2082 }
2083 } finally {
2084 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002085 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002086 }
2087
2088 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002089 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002090 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002091 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002092
2093 LocationAccessPolicy.LocationPermissionResult locationResult =
2094 LocationAccessPolicy.checkLocationPermission(mApp,
2095 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2096 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002097 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002098 .setCallingPid(Binder.getCallingPid())
2099 .setCallingUid(Binder.getCallingUid())
2100 .setMethod("getCellLocation")
2101 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2102 .build());
2103 switch (locationResult) {
2104 case DENIED_HARD:
2105 throw new SecurityException("Not allowed to access cell location");
2106 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002107 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2108 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002109 }
2110
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002111 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002112 final long identity = Binder.clearCallingIdentity();
2113 try {
2114 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002115 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002116 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002117 } finally {
2118 Binder.restoreCallingIdentity(identity);
2119 }
Svetoslav64fad262015-04-14 14:35:21 -07002120 }
2121
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002122 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002123 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2124 String callingFeatureId) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002125 if (!TextUtils.isEmpty(callingPackage)) {
2126 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002127 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2128 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002129 return "";
2130 }
2131 }
2132
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002133 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2134 // registered cell info, so return a NULL country instead.
2135 final long identity = Binder.clearCallingIdentity();
2136 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002137 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2138 // Get default phone in this case.
2139 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2140 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002141 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002142 // Todo: fix this when we can get the actual cellular network info when the device
2143 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002144 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002145 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2146 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002147 return "";
2148 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002149 Phone phone = PhoneFactory.getPhone(phoneId);
2150 if (phone != null) {
2151 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002152 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002153 if (sst != null) {
2154 LocaleTracker lt = sst.getLocaleTracker();
2155 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002156 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2157 return lt.getCurrentCountry();
2158 } else if (emergencyNumberTracker != null) {
2159 return emergencyNumberTracker.getEmergencyCountryIso();
2160 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002161 }
2162 }
2163 }
2164 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002165 } finally {
2166 Binder.restoreCallingIdentity(identity);
2167 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002168 }
2169
2170 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002171 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002172 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002173 }
2174
Sanket Padawe356d7632015-06-22 14:03:32 -07002175 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002176 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002177 mApp.enforceCallingOrSelfPermission(
2178 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002179
2180 final long identity = Binder.clearCallingIdentity();
2181 try {
2182 final Phone phone = getPhone(subId);
2183 if (phone != null) {
2184 phone.enableLocationUpdates();
2185 }
2186 } finally {
2187 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002188 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002189 }
2190
2191 @Override
2192 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002193 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002194 }
2195
Sanket Padawe356d7632015-06-22 14:03:32 -07002196 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002197 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002198 mApp.enforceCallingOrSelfPermission(
2199 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002200
2201 final long identity = Binder.clearCallingIdentity();
2202 try {
2203 final Phone phone = getPhone(subId);
2204 if (phone != null) {
2205 phone.disableLocationUpdates();
2206 }
2207 } finally {
2208 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002209 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 }
2211
Nathan Harold31d7ff32018-10-15 20:20:30 -07002212 /**
2213 * Returns the target SDK version number for a given package name.
2214 *
Nathan Haroldec184742019-07-10 17:04:16 -07002215 * This call MUST be invoked before clearing the calling UID.
2216 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002217 * @return target SDK if the package is found or INT_MAX.
2218 */
2219 private int getTargetSdk(String packageName) {
2220 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002221 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002222 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002223 if (ai != null) return ai.targetSdkVersion;
2224 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002225 loge("Failed to get package info for pkg="
2226 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002227 }
2228 return Integer.MAX_VALUE;
2229 }
2230
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002231 @Override
2232 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002233 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2234 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002235 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002236 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2237 throw new SecurityException(
2238 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2239 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002240
Jordan Liu1617b712019-07-10 15:06:26 -07002241 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2243 return null;
2244 }
Svetoslav64fad262015-04-14 14:35:21 -07002245
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002246 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002247
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002248 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002249 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002250
Nathan Haroldf180aac2018-06-01 18:43:55 -07002251 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2252 for (CellInfo ci : info) {
2253 if (ci instanceof CellInfoGsm) {
2254 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2255 } else if (ci instanceof CellInfoWcdma) {
2256 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002259 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002260 }
2261
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002262 private List<CellInfo> getCachedCellInfo() {
2263 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2264 for (Phone phone : PhoneFactory.getPhones()) {
2265 List<CellInfo> info = phone.getAllCellInfo();
2266 if (info != null) cellInfos.addAll(info);
2267 }
2268 return cellInfos;
2269 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270
2271 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002272 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002273 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002274 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002275
2276 LocationAccessPolicy.LocationPermissionResult locationResult =
2277 LocationAccessPolicy.checkLocationPermission(mApp,
2278 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2279 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002280 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002281 .setCallingPid(Binder.getCallingPid())
2282 .setCallingUid(Binder.getCallingUid())
2283 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002284 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002285 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2286 .build());
2287 switch (locationResult) {
2288 case DENIED_HARD:
2289 throw new SecurityException("Not allowed to access cell info");
2290 case DENIED_SOFT:
2291 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002292 }
2293
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002294 final int targetSdk = getTargetSdk(callingPackage);
2295 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2296 return getCachedCellInfo();
2297 }
2298
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002299 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002300 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002301 final long identity = Binder.clearCallingIdentity();
2302 try {
2303 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2304 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002305 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002306 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002307 if (info != null) cellInfos.addAll(info);
2308 }
2309 return cellInfos;
2310 } finally {
2311 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 }
2313 }
2314
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002315 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002316 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2317 String callingFeatureId) {
2318 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2319 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002320 }
2321
2322 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002323 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2324 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002325 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002326 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002327 }
2328
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002329 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2330 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002331 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002332 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002333
2334 LocationAccessPolicy.LocationPermissionResult locationResult =
2335 LocationAccessPolicy.checkLocationPermission(mApp,
2336 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2337 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002338 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002339 .setCallingPid(Binder.getCallingPid())
2340 .setCallingUid(Binder.getCallingUid())
2341 .setMethod("requestCellInfoUpdate")
2342 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2343 .build());
2344 switch (locationResult) {
2345 case DENIED_HARD:
2346 throw new SecurityException("Not allowed to access cell info");
2347 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002348 try {
2349 cb.onCellInfo(new ArrayList<CellInfo>());
2350 } catch (RemoteException re) {
2351 // Drop without consequences
2352 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002353 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002354 }
2355
Nathan Harolda939a962019-05-09 10:13:47 -07002356
2357 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002358 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2359
2360 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2361 }
2362
2363 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002365 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002366 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002367
2368 final long identity = Binder.clearCallingIdentity();
2369 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002370 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002371 } finally {
2372 Binder.restoreCallingIdentity(identity);
2373 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002374 }
2375
Shishir Agrawala9f32182016-04-12 12:00:16 -07002376 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002377 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002378 Phone phone = PhoneFactory.getPhone(slotIndex);
2379 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002380 return null;
2381 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002382 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002383 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002384 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002385 return null;
2386 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002387
2388 final long identity = Binder.clearCallingIdentity();
2389 try {
2390 return phone.getImei();
2391 } finally {
2392 Binder.restoreCallingIdentity(identity);
2393 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002394 }
2395
2396 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002397 public String getTypeAllocationCodeForSlot(int slotIndex) {
2398 Phone phone = PhoneFactory.getPhone(slotIndex);
2399 String tac = null;
2400 if (phone != null) {
2401 String imei = phone.getImei();
2402 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2403 }
2404 return tac;
2405 }
2406
2407 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002408 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002409 Phone phone = PhoneFactory.getPhone(slotIndex);
2410 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002411 return null;
2412 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002413
Jeff Davidson913390f2018-02-23 17:11:49 -08002414 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002415 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002416 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002417 return null;
2418 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002419
2420 final long identity = Binder.clearCallingIdentity();
2421 try {
2422 return phone.getMeid();
2423 } finally {
2424 Binder.restoreCallingIdentity(identity);
2425 }
Jack Yu2af8d712017-03-15 17:14:14 -07002426 }
2427
2428 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002429 public String getManufacturerCodeForSlot(int slotIndex) {
2430 Phone phone = PhoneFactory.getPhone(slotIndex);
2431 String manufacturerCode = null;
2432 if (phone != null) {
2433 String meid = phone.getMeid();
2434 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2435 }
2436 return manufacturerCode;
2437 }
2438
2439 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002440 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2441 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002442 Phone phone = PhoneFactory.getPhone(slotIndex);
2443 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002444 return null;
2445 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002446 int subId = phone.getSubId();
2447 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002448 mApp, subId, callingPackage, callingFeatureId,
2449 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002450 return null;
2451 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002452
2453 final long identity = Binder.clearCallingIdentity();
2454 try {
2455 return phone.getDeviceSvn();
2456 } finally {
2457 Binder.restoreCallingIdentity(identity);
2458 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002459 }
2460
fionaxu43304da2017-11-27 22:51:16 -08002461 @Override
2462 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002463 final long identity = Binder.clearCallingIdentity();
2464 try {
2465 final Phone phone = getPhone(subId);
2466 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2467 } finally {
2468 Binder.restoreCallingIdentity(identity);
2469 }
fionaxu43304da2017-11-27 22:51:16 -08002470 }
2471
2472 @Override
2473 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002474 final long identity = Binder.clearCallingIdentity();
2475 try {
2476 final Phone phone = getPhone(subId);
2477 return phone == null ? null : phone.getCarrierName();
2478 } finally {
2479 Binder.restoreCallingIdentity(identity);
2480 }
fionaxu43304da2017-11-27 22:51:16 -08002481 }
2482
calvinpanffe225e2018-11-01 19:43:06 +08002483 @Override
chen xu0026ca62019-03-06 15:28:50 -08002484 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002485 final long identity = Binder.clearCallingIdentity();
2486 try {
2487 final Phone phone = getPhone(subId);
2488 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002489 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002490 } finally {
2491 Binder.restoreCallingIdentity(identity);
2492 }
2493 }
2494
2495 @Override
chen xu0026ca62019-03-06 15:28:50 -08002496 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002497 final long identity = Binder.clearCallingIdentity();
2498 try {
2499 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002500 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002501 } finally {
2502 Binder.restoreCallingIdentity(identity);
2503 }
2504 }
2505
chen xu651eec72018-11-11 19:03:44 -08002506 @Override
chen xu864e11c2018-12-06 22:10:03 -08002507 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2508 if (!isSubscriptionMccMnc) {
2509 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2510 }
chen xu651eec72018-11-11 19:03:44 -08002511 final Phone phone = PhoneFactory.getPhone(slotIndex);
2512 if (phone == null) {
2513 return TelephonyManager.UNKNOWN_CARRIER_ID;
2514 }
2515 final long identity = Binder.clearCallingIdentity();
2516 try {
2517 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2518 } finally {
2519 Binder.restoreCallingIdentity(identity);
2520 }
2521 }
2522
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002523 //
2524 // Internal helper methods.
2525 //
2526
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002527 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002528 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2529 *
2530 * @throws SecurityException if the caller does not have the required permission
2531 */
2532 private void enforceModifyPermission() {
2533 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2534 }
2535
Shuo Qiancd19c462020-01-16 20:51:11 -08002536 /**
2537 * Make sure the caller is system.
2538 *
2539 * @throws SecurityException if the caller is not system.
2540 */
2541 private void enforceSystemCaller() {
2542 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2543 throw new SecurityException("Caller must be system");
2544 }
2545 }
2546
Shuo Qian3b6ee772019-11-13 17:43:31 -08002547 private void enforceActiveEmergencySessionPermission() {
2548 mApp.enforceCallingOrSelfPermission(
2549 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2550 }
2551
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002552 /**
2553 * Make sure the caller has the CALL_PHONE permission.
2554 *
2555 * @throws SecurityException if the caller does not have the required permission
2556 */
2557 private void enforceCallPermission() {
2558 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2559 }
2560
paulhu5a773602019-08-23 19:17:33 +08002561 private void enforceSettingsPermission() {
2562 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002563 }
2564
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002565 private String createTelUrl(String number) {
2566 if (TextUtils.isEmpty(number)) {
2567 return null;
2568 }
2569
Jake Hambye994d462014-02-03 13:10:13 -08002570 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002571 }
2572
Ihab Awadf9e92732013-12-05 18:02:52 -08002573 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002574 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2575 }
2576
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002577 private static void logv(String msg) {
2578 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2579 }
2580
Ihab Awadf9e92732013-12-05 18:02:52 -08002581 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2583 }
2584
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002585 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002586 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002587 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002588 }
2589
Sanket Padawe356d7632015-06-22 14:03:32 -07002590 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002591 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002592 final long identity = Binder.clearCallingIdentity();
2593 try {
2594 final Phone phone = PhoneFactory.getPhone(slotIndex);
2595 if (phone == null) {
2596 return PhoneConstants.PHONE_TYPE_NONE;
2597 } else {
2598 return phone.getPhoneType();
2599 }
2600 } finally {
2601 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002602 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002603 }
2604
2605 /**
2606 * Returns the CDMA ERI icon index to display
2607 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002608 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002609 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2610 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2611 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002612 }
2613
Sanket Padawe356d7632015-06-22 14:03:32 -07002614 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002615 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2616 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002617 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002618 mApp, subId, callingPackage, callingFeatureId,
2619 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002620 return -1;
2621 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002622
2623 final long identity = Binder.clearCallingIdentity();
2624 try {
2625 final Phone phone = getPhone(subId);
2626 if (phone != null) {
2627 return phone.getCdmaEriIconIndex();
2628 } else {
2629 return -1;
2630 }
2631 } finally {
2632 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002633 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002634 }
2635
2636 /**
2637 * Returns the CDMA ERI icon mode,
2638 * 0 - ON
2639 * 1 - FLASHING
2640 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002641 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002642 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2643 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2644 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002645 }
2646
Sanket Padawe356d7632015-06-22 14:03:32 -07002647 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002648 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2649 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002650 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002651 mApp, subId, callingPackage, callingFeatureId,
2652 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002653 return -1;
2654 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655
2656 final long identity = Binder.clearCallingIdentity();
2657 try {
2658 final Phone phone = getPhone(subId);
2659 if (phone != null) {
2660 return phone.getCdmaEriIconMode();
2661 } else {
2662 return -1;
2663 }
2664 } finally {
2665 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002666 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002667 }
2668
2669 /**
2670 * Returns the CDMA ERI text,
2671 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002672 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002673 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2674 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2675 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002676 }
2677
Sanket Padawe356d7632015-06-22 14:03:32 -07002678 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002679 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2680 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002681 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002682 mApp, subId, callingPackage, callingFeatureId,
2683 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002684 return null;
2685 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686
2687 final long identity = Binder.clearCallingIdentity();
2688 try {
2689 final Phone phone = getPhone(subId);
2690 if (phone != null) {
2691 return phone.getCdmaEriText();
2692 } else {
2693 return null;
2694 }
2695 } finally {
2696 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002697 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002698 }
2699
2700 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002701 * Returns the CDMA MDN.
2702 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002703 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002704 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002705 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2706 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002707
2708 final long identity = Binder.clearCallingIdentity();
2709 try {
2710 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002711 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002712 return phone.getLine1Number();
2713 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002714 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002715 return null;
2716 }
2717 } finally {
2718 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002719 }
2720 }
2721
2722 /**
2723 * Returns the CDMA MIN.
2724 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002725 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002726 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002727 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2728 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002729
2730 final long identity = Binder.clearCallingIdentity();
2731 try {
2732 final Phone phone = getPhone(subId);
2733 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2734 return phone.getCdmaMin();
2735 } else {
2736 return null;
2737 }
2738 } finally {
2739 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002740 }
2741 }
2742
Hall Liud892bec2018-11-30 14:51:45 -08002743 @Override
2744 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2745 INumberVerificationCallback callback, String callingPackage) {
2746 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2747 != PERMISSION_GRANTED) {
2748 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2749 }
2750 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2751
2752 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2753 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2754 throw new SecurityException("Calling package must be configured in the device config");
2755 }
2756
2757 if (range == null) {
2758 throw new NullPointerException("Range must be non-null");
2759 }
2760
2761 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002762 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002763
2764 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2765 }
2766
Junda Liuca05d5d2014-08-14 22:36:34 -07002767 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002768 * Returns true if CDMA provisioning needs to run.
2769 */
2770 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002771 final long identity = Binder.clearCallingIdentity();
2772 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002773 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002774 } finally {
2775 Binder.restoreCallingIdentity(identity);
2776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002777 }
2778
2779 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002780 * Sets the voice mail number of a given subId.
2781 */
2782 @Override
2783 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002784 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2785 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786
2787 final long identity = Binder.clearCallingIdentity();
2788 try {
2789 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2790 new Pair<String, String>(alphaTag, number), new Integer(subId));
2791 return success;
2792 } finally {
2793 Binder.restoreCallingIdentity(identity);
2794 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002795 }
2796
Ta-wei Yen87c49842016-05-13 21:19:52 -07002797 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002798 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2799 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002800 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2801 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002802 if (!TextUtils.equals(callingPackage, systemDialer)) {
2803 throw new SecurityException("caller must be system dialer");
2804 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002805
2806 final long identity = Binder.clearCallingIdentity();
2807 try {
2808 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2809 if (phoneAccountHandle == null) {
2810 return null;
2811 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002812 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002813 } finally {
2814 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002815 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002816 }
2817
2818 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002819 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2820 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002821 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002822 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002823 mApp, subId, callingPackage, callingFeatureId,
2824 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002825 return null;
2826 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002827
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002828 final long identity = Binder.clearCallingIdentity();
2829 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002830 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002831 } finally {
2832 Binder.restoreCallingIdentity(identity);
2833 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002834 }
2835
2836 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002837 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2838 VisualVoicemailSmsFilterSettings settings) {
2839 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002840
2841 final long identity = Binder.clearCallingIdentity();
2842 try {
2843 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002844 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002845 } finally {
2846 Binder.restoreCallingIdentity(identity);
2847 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002848 }
2849
2850 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002851 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2852 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002853
2854 final long identity = Binder.clearCallingIdentity();
2855 try {
2856 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002857 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002858 } finally {
2859 Binder.restoreCallingIdentity(identity);
2860 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002861 }
2862
2863 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002864 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2865 String callingPackage, int subId) {
2866 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002867
2868 final long identity = Binder.clearCallingIdentity();
2869 try {
2870 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002871 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002872 } finally {
2873 Binder.restoreCallingIdentity(identity);
2874 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002875 }
2876
2877 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002878 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002879 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880
2881 final long identity = Binder.clearCallingIdentity();
2882 try {
2883 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002884 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002885 } finally {
2886 Binder.restoreCallingIdentity(identity);
2887 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002888 }
2889
2890 @Override
2891 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2892 String number, int port, String text, PendingIntent sentIntent) {
2893 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002894 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002895 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002896 SmsController smsController = PhoneFactory.getSmsController();
2897 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2898 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002899 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002900
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002901 /**
fionaxu0152e512016-11-14 13:36:14 -08002902 * Sets the voice activation state of a given subId.
2903 */
2904 @Override
2905 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002906 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2907 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002908
2909 final long identity = Binder.clearCallingIdentity();
2910 try {
2911 final Phone phone = getPhone(subId);
2912 if (phone != null) {
2913 phone.setVoiceActivationState(activationState);
2914 } else {
2915 loge("setVoiceActivationState fails with invalid subId: " + subId);
2916 }
2917 } finally {
2918 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002919 }
2920 }
2921
2922 /**
2923 * Sets the data activation state of a given subId.
2924 */
2925 @Override
2926 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002927 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2928 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002929
2930 final long identity = Binder.clearCallingIdentity();
2931 try {
2932 final Phone phone = getPhone(subId);
2933 if (phone != null) {
2934 phone.setDataActivationState(activationState);
2935 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002936 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002937 }
2938 } finally {
2939 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002940 }
2941 }
2942
2943 /**
2944 * Returns the voice activation state of a given subId.
2945 */
2946 @Override
2947 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002948 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002949
fionaxu0152e512016-11-14 13:36:14 -08002950 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951 final long identity = Binder.clearCallingIdentity();
2952 try {
2953 if (phone != null) {
2954 return phone.getVoiceActivationState();
2955 } else {
2956 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2957 }
2958 } finally {
2959 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002960 }
2961 }
2962
2963 /**
2964 * Returns the data activation state of a given subId.
2965 */
2966 @Override
2967 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002968 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002969
fionaxu0152e512016-11-14 13:36:14 -08002970 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002971 final long identity = Binder.clearCallingIdentity();
2972 try {
2973 if (phone != null) {
2974 return phone.getDataActivationState();
2975 } else {
2976 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2977 }
2978 } finally {
2979 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002980 }
2981 }
2982
2983 /**
Wink Saville36469e72014-06-11 15:17:00 -07002984 * Returns the unread count of voicemails for a subId
2985 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002986 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002987 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2988 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002989 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002990 mApp, subId, callingPackage, callingFeatureId,
2991 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002992 return 0;
2993 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002994 final long identity = Binder.clearCallingIdentity();
2995 try {
2996 final Phone phone = getPhone(subId);
2997 if (phone != null) {
2998 return phone.getVoiceMessageCount();
2999 } else {
3000 return 0;
3001 }
3002 } finally {
3003 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003004 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003005 }
3006
3007 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003008 * returns true, if the device is in a state where both voice and data
3009 * are supported simultaneously. This can change based on location or network condition.
3010 */
3011 @Override
3012 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003013 final long identity = Binder.clearCallingIdentity();
3014 try {
3015 final Phone phone = getPhone(subId);
3016 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3017 } finally {
3018 Binder.restoreCallingIdentity(identity);
3019 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003020 }
3021
3022 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003023 * Send the dialer code if called from the current default dialer or the caller has
3024 * carrier privilege.
3025 * @param inputCode The dialer code to send
3026 */
3027 @Override
3028 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003029 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003030 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003031 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3032 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003033 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003034 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003035 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003036 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003037
3038 final long identity = Binder.clearCallingIdentity();
3039 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003040 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003041 } finally {
3042 Binder.restoreCallingIdentity(identity);
3043 }
fionaxu235cc5e2017-03-06 22:25:57 -08003044 }
3045
Pengquan Menga1bb6272018-09-06 09:59:22 -07003046 @Override
3047 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003048 TelephonyPermissions
3049 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3050 mApp, subId, "getNetworkSelectionMode");
3051 final long identity = Binder.clearCallingIdentity();
3052 try {
3053 if (!isActiveSubscription(subId)) {
3054 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3055 }
3056 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3057 } finally {
3058 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003059 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003060 }
3061
Brad Ebinger35c841c2018-10-01 10:40:55 -07003062 @Override
Sarah Chin0605abf2019-12-06 10:24:18 -08003063 public PhoneCapability getPhoneCapability(int subId, String callingPackage,
3064 String callingFeatureId) {
3065 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3066 mApp, subId, callingPackage, callingFeatureId, "getPhoneCapability")) {
3067 return null;
3068 }
3069 final long identity = Binder.clearCallingIdentity();
3070 try {
3071 return mPhoneConfigurationManager.getStaticPhoneCapability();
3072 } finally {
3073 Binder.restoreCallingIdentity(identity);
3074 }
3075 }
3076
3077 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003078 public boolean isInEmergencySmsMode() {
3079 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3080 final long identity = Binder.clearCallingIdentity();
3081 try {
3082 for (Phone phone : PhoneFactory.getPhones()) {
3083 if (phone.isInEmergencySmsMode()) {
3084 return true;
3085 }
3086 }
3087 } finally {
3088 Binder.restoreCallingIdentity(identity);
3089 }
3090 return false;
3091 }
3092
shilu366312e2019-12-17 09:28:10 -08003093 /**
3094 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3095 * @param subId The subscription to use to check the configuration.
3096 * @param c The callback that will be used to send the result.
3097 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003098 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003099 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3100 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003101 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003102 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003103
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003104 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3105 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3106 "IMS not available on device.");
3107 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003108 final long token = Binder.clearCallingIdentity();
3109 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003110 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003111 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003112 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003113 } catch (ImsException e) {
3114 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003115 } finally {
3116 Binder.restoreCallingIdentity(token);
3117 }
3118 }
3119
shilu366312e2019-12-17 09:28:10 -08003120 /**
3121 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3122 * @param subId The subscription to use to check the configuration.
3123 * @param c The callback that will be used to send the result.
3124 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003125 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003126 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
shilu366312e2019-12-17 09:28:10 -08003127 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003128 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003129 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3130 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3131 }
Meng Wangafbc5852019-09-19 17:37:13 -07003132 final long token = Binder.clearCallingIdentity();
3133 try {
3134 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3135 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3136 .removeRegistrationCallbackForSubscription(c, subId);
3137 } catch (ImsException e) {
3138 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3139 + "is inactive, ignoring unregister.");
3140 // If the subscription is no longer active, just return, since the callback
3141 // will already have been removed internally.
3142 } finally {
3143 Binder.restoreCallingIdentity(token);
3144 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003145 }
3146
Brad Ebingera34a6c22019-10-22 17:36:18 -07003147 /**
3148 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3149 */
3150 @Override
3151 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3152 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3153 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3154 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3155 "IMS not available on device.");
3156 }
3157 final long token = Binder.clearCallingIdentity();
3158 try {
3159 Phone phone = getPhone(subId);
3160 if (phone == null) {
3161 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3162 + subId + "'");
3163 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3164 }
3165 phone.getImsRegistrationState(regState -> {
3166 try {
3167 consumer.accept((regState == null)
3168 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3169 } catch (RemoteException e) {
3170 // Ignore if the remote process is no longer available to call back.
3171 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3172 }
3173 });
3174 } finally {
3175 Binder.restoreCallingIdentity(token);
3176 }
3177 }
3178
3179 /**
3180 * Get the transport type for the IMS service registration state.
3181 */
3182 @Override
3183 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
shilu366312e2019-12-17 09:28:10 -08003184 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebingera34a6c22019-10-22 17:36:18 -07003185 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3186 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3187 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3188 "IMS not available on device.");
3189 }
3190 final long token = Binder.clearCallingIdentity();
3191 try {
3192 Phone phone = getPhone(subId);
3193 if (phone == null) {
3194 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3195 + subId + "'");
3196 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3197 }
3198 phone.getImsRegistrationTech(regTech -> {
3199 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3200 int regTechConverted = (regTech == null)
3201 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3202 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3203 regTechConverted);
3204 try {
3205 consumer.accept(regTechConverted);
3206 } catch (RemoteException e) {
3207 // Ignore if the remote process is no longer available to call back.
3208 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3209 }
3210 });
3211 } finally {
3212 Binder.restoreCallingIdentity(token);
3213 }
3214 }
3215
shilu366312e2019-12-17 09:28:10 -08003216 /**
3217 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3218 * @param subId The subscription to use to check the configuration.
3219 * @param c The callback that will be used to send the result.
3220 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003221 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003222 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3223 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003224 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003225 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003226 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3227 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3228 "IMS not available on device.");
3229 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003230 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3231 final long token = Binder.clearCallingIdentity();
3232 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003233 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003234 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003235 } catch (ImsException e) {
3236 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003237 } finally {
3238 Binder.restoreCallingIdentity(token);
3239 }
3240 }
3241
shilu366312e2019-12-17 09:28:10 -08003242 /**
3243 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3244 * @param subId The subscription to use to check the configuration.
3245 * @param c The callback that will be used to send the result.
3246 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003247 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003248 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
shilu366312e2019-12-17 09:28:10 -08003249 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003250 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003251 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3252 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3253 }
Meng Wangafbc5852019-09-19 17:37:13 -07003254
3255 final long token = Binder.clearCallingIdentity();
3256 try {
3257 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3258 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003259 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003260 } catch (ImsException e) {
3261 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3262 + "is inactive, ignoring unregister.");
3263 // If the subscription is no longer active, just return, since the callback
3264 // will already have been removed internally.
3265 } finally {
3266 Binder.restoreCallingIdentity(token);
3267 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003268 }
3269
3270 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003271 public boolean isCapable(int subId, int capability, int regTech) {
3272 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003273 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3274 final long token = Binder.clearCallingIdentity();
3275 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003276 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003277 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003278 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003279 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3280 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003281 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003282 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3283 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003284 } finally {
3285 Binder.restoreCallingIdentity(token);
3286 }
3287 }
3288
3289 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003290 public boolean isAvailable(int subId, int capability, int regTech) {
3291 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003292 final long token = Binder.clearCallingIdentity();
3293 try {
3294 Phone phone = getPhone(subId);
3295 if (phone == null) return false;
3296 return phone.isImsCapabilityAvailable(capability, regTech);
3297 } finally {
3298 Binder.restoreCallingIdentity(token);
3299 }
3300 }
3301
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003302 /**
3303 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3304 * subscription.
3305 * @param subId The subscription to use to check the configuration.
3306 * @param callback The callback that will be used to send the result.
3307 * @param capability The MmTelFeature capability that will be used to send the result.
3308 * @param transportType The transport type of the MmTelFeature capability.
3309 */
3310 @Override
3311 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3312 int transportType) {
3313 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3314 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3315 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3316 "IMS not available on device.");
3317 }
3318 final long token = Binder.clearCallingIdentity();
3319 try {
3320 int slotId = getSlotIndex(subId);
3321 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3322 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3323 + subId + "'");
3324 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3325 }
3326 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3327 transportType, aBoolean -> {
3328 try {
3329 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3330 } catch (RemoteException e) {
3331 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3332 + "running. Ignore");
3333 }
3334 });
3335 } finally {
3336 Binder.restoreCallingIdentity(token);
3337 }
3338 }
3339
shilu366312e2019-12-17 09:28:10 -08003340 /**
3341 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3342 * @param subId The subscription to use to check the configuration.
3343 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003344 @Override
3345 public boolean isAdvancedCallingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003346 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
3347 enforceReadPrivilegedPermission("isAdvancedCallingSettingEnabled");
3348
Brad Ebinger35c841c2018-10-01 10:40:55 -07003349 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3350 final long token = Binder.clearCallingIdentity();
3351 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003352 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003353 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003354 } catch (ImsException e) {
3355 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003356 } finally {
3357 Binder.restoreCallingIdentity(token);
3358 }
3359 }
3360
3361 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003362 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003363 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003364 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003365 final long identity = Binder.clearCallingIdentity();
3366 try {
3367 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003368 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003369 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003370 } catch (ImsException e) {
3371 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003372 } finally {
3373 Binder.restoreCallingIdentity(identity);
3374 }
3375 }
3376
shilu366312e2019-12-17 09:28:10 -08003377 /**
3378 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3379 * @param subId The subscription to use to check the configuration.
3380 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003381 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003382 public boolean isVtSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003383 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003384 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003385 final long identity = Binder.clearCallingIdentity();
3386 try {
3387 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003388 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3389 } catch (ImsException e) {
3390 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003391 } finally {
3392 Binder.restoreCallingIdentity(identity);
3393 }
3394 }
3395
3396 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003397 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003399 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003400 final long identity = Binder.clearCallingIdentity();
3401 try {
3402 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003403 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003404 } catch (ImsException e) {
3405 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003406 } finally {
3407 Binder.restoreCallingIdentity(identity);
3408 }
3409 }
3410
shilu366312e2019-12-17 09:28:10 -08003411 /**
3412 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3413 * @param subId The subscription to use to check the configuration.
3414 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003415 @Override
3416 public boolean isVoWiFiSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003417 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003418 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3419 final long identity = Binder.clearCallingIdentity();
3420 try {
3421 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003422 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003423 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003424 } catch (ImsException e) {
3425 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003426 } finally {
3427 Binder.restoreCallingIdentity(identity);
3428 }
3429 }
3430
3431 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003432 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003433 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003434 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003435 final long identity = Binder.clearCallingIdentity();
3436 try {
3437 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003438 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003439 } catch (ImsException e) {
3440 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003441 } finally {
3442 Binder.restoreCallingIdentity(identity);
3443 }
3444 }
3445
shilu366312e2019-12-17 09:28:10 -08003446 /**
3447 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3448 * @param subId The subscription to use to check the configuration.
3449 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003450 @Override
3451 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003452 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003453 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3454 final long identity = Binder.clearCallingIdentity();
3455 try {
3456 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003457 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003458 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003459 } catch (ImsException e) {
3460 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003461 } finally {
3462 Binder.restoreCallingIdentity(identity);
3463 }
3464 }
3465
3466 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003467 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003468 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003469 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003470 final long identity = Binder.clearCallingIdentity();
3471 try {
3472 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003473 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003474 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003475 } catch (ImsException e) {
3476 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003477 } finally {
3478 Binder.restoreCallingIdentity(identity);
3479 }
3480 }
3481
3482 @Override
3483 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3484 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3485 "setVoWiFiNonPersistent");
3486 final long identity = Binder.clearCallingIdentity();
3487 try {
3488 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003489 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003490 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003491 } catch (ImsException e) {
3492 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003493 } finally {
3494 Binder.restoreCallingIdentity(identity);
3495 }
3496 }
3497
shilu366312e2019-12-17 09:28:10 -08003498 /**
3499 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3500 * @param subId The subscription to use to check the configuration.
3501 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003502 @Override
3503 public int getVoWiFiModeSetting(int subId) {
shilu366312e2019-12-17 09:28:10 -08003504 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003505 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3506 final long identity = Binder.clearCallingIdentity();
3507 try {
3508 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003509 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003510 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003511 } catch (ImsException e) {
3512 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003513 } finally {
3514 Binder.restoreCallingIdentity(identity);
3515 }
3516 }
3517
3518 @Override
3519 public void setVoWiFiModeSetting(int subId, int mode) {
3520 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3521 "setVoWiFiModeSetting");
3522 final long identity = Binder.clearCallingIdentity();
3523 try {
3524 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003525 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003526 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003527 } catch (ImsException e) {
3528 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003529 } finally {
3530 Binder.restoreCallingIdentity(identity);
3531 }
3532 }
3533
3534 @Override
3535 public int getVoWiFiRoamingModeSetting(int subId) {
3536 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3537 final long identity = Binder.clearCallingIdentity();
3538 try {
3539 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003540 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003541 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003542 } catch (ImsException e) {
3543 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003544 } finally {
3545 Binder.restoreCallingIdentity(identity);
3546 }
3547 }
3548
3549 @Override
3550 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3551 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3552 "setVoWiFiRoamingModeSetting");
3553 final long identity = Binder.clearCallingIdentity();
3554 try {
3555 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003556 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003557 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003558 } catch (ImsException e) {
3559 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003560 } finally {
3561 Binder.restoreCallingIdentity(identity);
3562 }
3563 }
3564
3565 @Override
3566 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3568 "setRttCapabilityEnabled");
3569 final long identity = Binder.clearCallingIdentity();
3570 try {
3571 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003572 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3573 } catch (ImsException e) {
3574 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003575 } finally {
3576 Binder.restoreCallingIdentity(identity);
3577 }
3578 }
3579
shilu366312e2019-12-17 09:28:10 -08003580 /**
3581 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3582 * @param subId The subscription to use to check the configuration.
3583 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003584 @Override
3585 public boolean isTtyOverVolteEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003586 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003587 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3588 final long identity = Binder.clearCallingIdentity();
3589 try {
3590 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003591 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003592 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003593 } catch (ImsException e) {
3594 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003595 } finally {
3596 Binder.restoreCallingIdentity(identity);
3597 }
3598 }
3599
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003600 @Override
3601 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3602 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3603 final long identity = Binder.clearCallingIdentity();
3604 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003605 if (!isImsAvailableOnDevice()) {
3606 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3607 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003608 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003609 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003610 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003611 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003612 } catch (ImsException e) {
3613 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003614 } finally {
3615 Binder.restoreCallingIdentity(identity);
3616 }
3617 }
3618
3619 @Override
3620 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3621 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3622 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003623 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3624 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3625 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003626 try {
3627 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003628 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003629 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003630 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003631 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3632 + "is inactive, ignoring unregister.");
3633 // If the subscription is no longer active, just return, since the callback will already
3634 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003635 } finally {
3636 Binder.restoreCallingIdentity(identity);
3637 }
3638 }
3639
allenwtsu99c623b2020-01-03 18:24:23 +08003640
3641 private void checkModifyPhoneStatePermission(int subId, String message) {
3642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3643 message);
3644 }
3645
3646 private boolean isImsProvisioningRequired(int subId, int capability,
3647 boolean isMmtelCapability) {
3648 Phone phone = getPhone(subId);
3649 if (phone == null) {
3650 loge("phone instance null for subid " + subId);
3651 return false;
3652 }
3653 if (isMmtelCapability) {
3654 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3655 return false;
3656 }
3657 } else {
3658 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3659 return false;
3660 }
3661 }
3662 return true;
3663 }
3664
3665 @Override
3666 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3667 boolean isProvisioned) {
3668 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3669
3670 final long identity = Binder.clearCallingIdentity();
3671 try {
3672 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3673 if (!isImsProvisioningRequired(subId, capability, false)) {
3674 return;
3675 }
3676
3677 // this capability requires provisioning, route to the correct API.
3678 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3679 switch (capability) {
3680 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3681 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3682 ims.setEabProvisioned(isProvisioned);
3683 break;
3684 default: {
3685 throw new IllegalArgumentException("Tried to set provisioning for "
3686 + "rcs capability '" + capability + "', which does not require "
3687 + "provisioning.");
3688 }
3689 }
3690 } finally {
3691 Binder.restoreCallingIdentity(identity);
3692 }
3693
3694 }
3695
3696
3697 @Override
3698 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3699 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3700 final long identity = Binder.clearCallingIdentity();
3701 try {
3702 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3703 if (!isImsProvisioningRequired(subId, capability, false)) {
3704 return true;
3705 }
3706
3707 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3708 switch (capability) {
3709 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3710 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3711 return ims.isEabProvisionedOnDevice();
3712
3713 default: {
3714 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3715 + "capability '" + capability + "', which does not require "
3716 + "provisioning.");
3717 }
3718 }
3719
3720 } finally {
3721 Binder.restoreCallingIdentity(identity);
3722 }
3723 }
3724
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003725 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003726 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3727 boolean isProvisioned) {
3728 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3729 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3730 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3731 }
allenwtsu99c623b2020-01-03 18:24:23 +08003732 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003733 final long identity = Binder.clearCallingIdentity();
3734 try {
3735 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003736 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003737 return;
3738 }
3739
3740 // this capability requires provisioning, route to the correct API.
3741 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3742 switch (capability) {
3743 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3744 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3745 ims.setVolteProvisioned(isProvisioned);
3746 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3747 ims.setWfcProvisioned(isProvisioned);
3748 }
3749 break;
3750 }
3751 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3752 // There is currently no difference in VT provisioning type.
3753 ims.setVtProvisioned(isProvisioned);
3754 break;
3755 }
3756 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3757 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3758 // change the capability of the feature instead if needed.
3759 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3760 == isProvisioned) {
3761 // No change in provisioning.
3762 return;
3763 }
3764 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3765 try {
3766 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003767 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003768 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3769 + ", Exception" + e.getMessage());
3770 }
3771 break;
3772 }
3773 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003774 throw new IllegalArgumentException("Tried to set provisioning for "
3775 + "MmTel capability '" + capability + "', which does not require "
3776 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003777 }
3778 }
3779
3780 } finally {
3781 Binder.restoreCallingIdentity(identity);
3782 }
3783 }
3784
3785 @Override
3786 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3787 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3788 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3789 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3790 }
3791 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3792 final long identity = Binder.clearCallingIdentity();
3793 try {
3794 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003795 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003796 return true;
3797 }
3798
3799 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3800 switch (capability) {
3801 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3802 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3803 return ims.isVolteProvisionedOnDevice();
3804 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3805 return ims.isWfcProvisionedOnDevice();
3806 }
3807 // This should never happen, since we are checking tech above to make sure it
3808 // is either LTE or IWLAN.
3809 throw new IllegalArgumentException("Invalid radio technology for voice "
3810 + "capability.");
3811 }
3812 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3813 // There is currently no difference in VT provisioning type.
3814 return ims.isVtProvisionedOnDevice();
3815 }
3816 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3817 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3818 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3819 }
3820 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003821 throw new IllegalArgumentException(
3822 "Tried to get provisioning for MmTel capability '" + capability
3823 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003824 }
3825 }
3826
3827 } finally {
3828 Binder.restoreCallingIdentity(identity);
3829 }
3830 }
3831
3832 @Override
3833 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3834 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3835 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3836 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3837 }
3838 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3839 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3840 return (provisionedBits & capability) > 0;
3841 }
3842
3843 @Override
3844 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3845 boolean isProvisioned) {
3846 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3847 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3848 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3849 }
3850 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3851 "setProvisioningStatusForCapability");
3852 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3853 // If the current provisioning status for capability already matches isProvisioned,
3854 // do nothing.
3855 if (((provisionedBits & capability) > 0) == isProvisioned) {
3856 return;
3857 }
3858 if (isProvisioned) {
3859 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3860 } else {
3861 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3862 }
3863 }
3864
3865 /**
3866 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3867 * technology. The bitfield should mirror the bitfield defined by
3868 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3869 */
3870 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3871 String key = getMmTelProvisioningKey(subId, tech);
3872 // Default is no capabilities are provisioned.
3873 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3874 }
3875
3876 /**
3877 * Sets the MmTel capability provisioning bitfield (defined by
3878 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3879 * technology specified.
3880 *
3881 * Note: This is a synchronous command and should not be called on UI thread.
3882 */
3883 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3884 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3885 String key = getMmTelProvisioningKey(subId, tech);
3886 editor.putInt(key, newField);
3887 editor.commit();
3888 }
3889
3890 private static String getMmTelProvisioningKey(int subId, int tech) {
3891 // resulting key is provision_ims_mmtel_{subId}_{tech}
3892 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3893 }
3894
3895 /**
3896 * Query CarrierConfig to see if the specified capability requires provisioning for the
3897 * carrier associated with the subscription id.
3898 */
3899 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3900 int capability) {
3901 CarrierConfigManager configManager = new CarrierConfigManager(context);
3902 PersistableBundle c = configManager.getConfigForSubId(subId);
3903 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003904 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003905 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3906 false);
3907 boolean requireVoiceVtProvisioning = c.getBoolean(
3908 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3909
3910 // First check to make sure that the capability requires provisioning.
3911 switch (capability) {
3912 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3913 // intentional fallthrough
3914 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3915 if (requireVoiceVtProvisioning) {
3916 // Voice and Video requires provisioning
3917 return true;
3918 }
3919 break;
3920 }
3921 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3922 if (requireUtProvisioning) {
3923 // UT requires provisioning
3924 return true;
3925 }
3926 break;
3927 }
3928 }
3929 return false;
3930 }
3931
allenwtsu99c623b2020-01-03 18:24:23 +08003932 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
3933 int capability) {
3934 CarrierConfigManager configManager = new CarrierConfigManager(context);
3935 PersistableBundle c = configManager.getConfigForSubId(subId);
3936
3937 boolean requireRcsProvisioning = c.getBoolean(
3938 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
3939
3940 // First check to make sure that the capability requires provisioning.
3941 switch (capability) {
3942 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3943 // intentional fallthrough
3944 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
3945 if (requireRcsProvisioning) {
3946 // OPTION or PRESENCE requires provisioning
3947 return true;
3948 }
3949 break;
3950 }
3951 }
3952 return false;
3953 }
3954
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003955 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003956 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003957 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3958 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3959 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003960 enforceReadPrivilegedPermission("getImsProvisioningInt");
3961 final long identity = Binder.clearCallingIdentity();
3962 try {
3963 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003964 int slotId = getSlotIndex(subId);
3965 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3966 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3967 + subId + "' for key:" + key);
3968 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3969 }
3970 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003971 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003972 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3973 + subId + "' for key:" + key);
3974 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003975 } finally {
3976 Binder.restoreCallingIdentity(identity);
3977 }
3978 }
3979
3980 @Override
3981 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003982 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3983 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3984 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003985 enforceReadPrivilegedPermission("getImsProvisioningString");
3986 final long identity = Binder.clearCallingIdentity();
3987 try {
3988 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003989 int slotId = getSlotIndex(subId);
3990 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3991 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3992 + subId + "' for key:" + key);
3993 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3994 }
3995 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003996 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003997 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3998 + subId + "' for key:" + key);
3999 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004000 } finally {
4001 Binder.restoreCallingIdentity(identity);
4002 }
4003 }
4004
4005 @Override
4006 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004007 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4008 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4009 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004010 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4011 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004012 final long identity = Binder.clearCallingIdentity();
4013 try {
4014 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004015 int slotId = getSlotIndex(subId);
4016 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4017 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4018 + subId + "' for key:" + key);
4019 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4020 }
4021 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004022 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004023 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4024 + "' for key:" + key);
4025 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004026 } finally {
4027 Binder.restoreCallingIdentity(identity);
4028 }
4029 }
4030
4031 @Override
4032 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004033 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4034 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4035 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004036 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4037 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004038 final long identity = Binder.clearCallingIdentity();
4039 try {
4040 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004041 int slotId = getSlotIndex(subId);
4042 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4043 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4044 + subId + "' for key:" + key);
4045 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4046 }
4047 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004048 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004049 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4050 + "' for key:" + key);
4051 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004052 } finally {
4053 Binder.restoreCallingIdentity(identity);
4054 }
4055 }
4056
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004057 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004058 int slotId = SubscriptionManager.getSlotIndex(subId);
4059 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004060 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4061 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004062 }
4063 return slotId;
4064 }
4065
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004066 private int getSlotIndex(int subId) {
4067 int slotId = SubscriptionManager.getSlotIndex(subId);
4068 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4069 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4070 }
4071 return slotId;
4072 }
4073
Wink Saville36469e72014-06-11 15:17:00 -07004074 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004075 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004076 */
4077 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004078 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4079 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004080 final int targetSdk = getTargetSdk(callingPackage);
4081 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004082 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004083 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004084 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004085 mApp, subId, callingPackage, callingFeatureId,
4086 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004087 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4088 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004089
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004090 final long identity = Binder.clearCallingIdentity();
4091 try {
4092 final Phone phone = getPhone(subId);
4093 if (phone != null) {
4094 return phone.getServiceState().getDataNetworkType();
4095 } else {
4096 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4097 }
4098 } finally {
4099 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004100 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004101 }
4102
4103 /**
4104 * Returns the data network type
4105 */
4106 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004107 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4108 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4109 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004110 }
4111
4112 /**
4113 * Returns the data network type for a subId
4114 */
4115 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004116 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4117 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004118 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004119 mApp, subId, callingPackage, callingFeatureId,
4120 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004121 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4122 }
4123
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004124 final long identity = Binder.clearCallingIdentity();
4125 try {
4126 final Phone phone = getPhone(subId);
4127 if (phone != null) {
4128 return phone.getServiceState().getDataNetworkType();
4129 } else {
4130 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4131 }
4132 } finally {
4133 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004134 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004135 }
4136
4137 /**
Wink Saville36469e72014-06-11 15:17:00 -07004138 * Returns the Voice network type for a subId
4139 */
4140 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004141 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4142 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004143 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004144 mApp, subId, callingPackage, callingFeatureId,
4145 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004146 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4147 }
4148
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004149 final long identity = Binder.clearCallingIdentity();
4150 try {
4151 final Phone phone = getPhone(subId);
4152 if (phone != null) {
4153 return phone.getServiceState().getVoiceNetworkType();
4154 } else {
4155 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4156 }
4157 } finally {
4158 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004159 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004160 }
4161
4162 /**
4163 * @return true if a ICC card is present
4164 */
4165 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004166 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004167 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4168 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004169 }
4170
4171 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004172 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004173 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004174 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004175 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004176 final long identity = Binder.clearCallingIdentity();
4177 try {
4178 final Phone phone = PhoneFactory.getPhone(slotIndex);
4179 if (phone != null) {
4180 return phone.getIccCard().hasIccCard();
4181 } else {
4182 return false;
4183 }
4184 } finally {
4185 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004186 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004187 }
4188
4189 /**
4190 * Return if the current radio is LTE on CDMA. This
4191 * is a tri-state return value as for a period of time
4192 * the mode may be unknown.
4193 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004194 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004195 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004196 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004197 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004198 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004199 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4200 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4201 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004202 }
4203
Sanket Padawe356d7632015-06-22 14:03:32 -07004204 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004205 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4206 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004207 try {
4208 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4209 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004210 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4211 }
4212
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004213 final long identity = Binder.clearCallingIdentity();
4214 try {
4215 final Phone phone = getPhone(subId);
4216 if (phone == null) {
4217 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4218 } else {
4219 return phone.getLteOnCdmaMode();
4220 }
4221 } finally {
4222 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004223 }
Wink Saville36469e72014-06-11 15:17:00 -07004224 }
4225
Wink Saville36469e72014-06-11 15:17:00 -07004226 /**
4227 * {@hide}
4228 * Returns Default subId, 0 in the case of single standby.
4229 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004230 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004231 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004232 }
4233
Shishir Agrawala9f32182016-04-12 12:00:16 -07004234 private int getSlotForDefaultSubscription() {
4235 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4236 }
4237
Wink Savilleb564aae2014-10-23 10:18:09 -07004238 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004239 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004240 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004241
Pengquan Menge92a50d2018-09-21 15:54:48 -07004242 private boolean isActiveSubscription(int subId) {
4243 return mSubscriptionController.isActiveSubId(subId);
4244 }
4245
Ihab Awadf2177b72013-11-25 13:33:23 -08004246 /**
4247 * @see android.telephony.TelephonyManager.WifiCallingChoices
4248 */
4249 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004250 final long identity = Binder.clearCallingIdentity();
4251 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004252 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004253 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4254 getWhenToMakeWifiCallsDefaultPreference());
4255 } finally {
4256 Binder.restoreCallingIdentity(identity);
4257 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004258 }
4259
4260 /**
4261 * @see android.telephony.TelephonyManager.WifiCallingChoices
4262 */
4263 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004264 final long identity = Binder.clearCallingIdentity();
4265 try {
4266 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004267 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004268 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4269 } finally {
4270 Binder.restoreCallingIdentity(identity);
4271 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004272 }
4273
Sailesh Nepald1e68152013-12-12 19:08:02 -08004274 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004275 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004276 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004277 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004278
Jordan Liu4c733742019-02-28 12:03:40 -08004279 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4280 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4281 if (phoneId == -1) {
4282 throw new IllegalArgumentException("Given slot index: " + slotIndex
4283 + " does not correspond to an active phone");
4284 }
4285 return PhoneFactory.getPhone(phoneId);
4286 }
4287
Shishir Agrawal566b7612013-10-28 14:41:00 -07004288 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004289 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4290 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004291 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4292 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004293 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004294 if (DBG) {
4295 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4296 }
4297 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4298 p2);
4299 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004300
Jordan Liu4c733742019-02-28 12:03:40 -08004301
4302 @Override
4303 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4304 int slotIndex, String callingPackage, String aid, int p2) {
4305 enforceModifyPermission();
4306 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4307 if (DBG) {
4308 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4309 }
4310 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4311 callingPackage, aid, p2);
4312 }
4313
4314 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4315 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004316 final long identity = Binder.clearCallingIdentity();
4317 try {
4318 if (TextUtils.equals(ISDR_AID, aid)) {
4319 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004320 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4321 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004322 if (bestComponent == null
4323 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4324 loge("The calling package is not allowed to access ISD-R.");
4325 throw new SecurityException(
4326 "The calling package is not allowed to access ISD-R.");
4327 }
Derek Tan740e1672017-06-27 14:56:27 -07004328 }
Derek Tan740e1672017-06-27 14:56:27 -07004329
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004330 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004331 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4332 null /* workSource */);
4333 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004334 return response;
4335 } finally {
4336 Binder.restoreCallingIdentity(identity);
4337 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004338 }
4339
4340 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004341 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4343 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004344 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4345 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4346 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004347
Jordan Liu4c733742019-02-28 12:03:40 -08004348 @Override
4349 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4350 enforceModifyPermission();
4351 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4352 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4353 channel);
4354 }
4355
4356 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004357 final long identity = Binder.clearCallingIdentity();
4358 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004359 if (channel < 0) {
4360 return false;
4361 }
Jordan Liu4c733742019-02-28 12:03:40 -08004362 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4363 null /* workSource */);
4364 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004365 return success;
4366 } finally {
4367 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004368 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004369 }
4370
4371 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004372 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004373 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4375 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004376 if (DBG) {
4377 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4378 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4379 + p3 + " data=" + data);
4380 }
4381 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4382 command, p1, p2, p3, data);
4383 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004384
Jordan Liu4c733742019-02-28 12:03:40 -08004385 @Override
4386 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4387 int command, int p1, int p2, int p3, String data) {
4388 enforceModifyPermission();
4389 if (DBG) {
4390 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4391 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4392 + p3 + " data=" + data);
4393 }
4394 return iccTransmitApduLogicalChannelWithPermission(
4395 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4396 data);
4397 }
4398
4399 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4400 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004401 final long identity = Binder.clearCallingIdentity();
4402 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004403 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004404 return "";
4405 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004406
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004407 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004408 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4409 null /* workSource */);
4410 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004411
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004412 // Append the returned status code to the end of the response payload.
4413 String s = Integer.toHexString(
4414 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4415 if (response.payload != null) {
4416 s = IccUtils.bytesToHexString(response.payload) + s;
4417 }
4418 return s;
4419 } finally {
4420 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004421 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004422 }
Jake Hambye994d462014-02-03 13:10:13 -08004423
Evan Charltonc66da362014-05-16 14:06:40 -07004424 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004425 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4426 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004427 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4428 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004429 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004430 if (DBG) {
4431 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4432 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4433 }
4434 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4435 cla, command, p1, p2, p3, data);
4436 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004437
Jordan Liu4c733742019-02-28 12:03:40 -08004438 @Override
4439 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4440 int command, int p1, int p2, int p3, String data) {
4441 enforceModifyPermission();
4442 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4443 if (DBG) {
4444 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4445 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4446 + " data=" + data);
4447 }
4448
4449 return iccTransmitApduBasicChannelWithPermission(
4450 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4451 p2, p3, data);
4452 }
4453
4454 // open APDU basic channel assuming the caller has sufficient permissions
4455 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4456 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004457 final long identity = Binder.clearCallingIdentity();
4458 try {
4459 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4460 && TextUtils.equals(ISDR_AID, data)) {
4461 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004462 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4463 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004464 if (bestComponent == null
4465 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4466 loge("The calling package is not allowed to select ISD-R.");
4467 throw new SecurityException(
4468 "The calling package is not allowed to select ISD-R.");
4469 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004470 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004472 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004473 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4474 null /* workSource */);
4475 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004476
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004477 // Append the returned status code to the end of the response payload.
4478 String s = Integer.toHexString(
4479 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4480 if (response.payload != null) {
4481 s = IccUtils.bytesToHexString(response.payload) + s;
4482 }
4483 return s;
4484 } finally {
4485 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004486 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004487 }
4488
4489 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004490 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004491 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4493 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004494
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004495 final long identity = Binder.clearCallingIdentity();
4496 try {
4497 if (DBG) {
4498 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4499 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4500 }
4501
4502 IccIoResult response =
4503 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4504 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4505 subId);
4506
4507 if (DBG) {
4508 log("Exchange SIM_IO [R]" + response);
4509 }
4510
4511 byte[] result = null;
4512 int length = 2;
4513 if (response.payload != null) {
4514 length = 2 + response.payload.length;
4515 result = new byte[length];
4516 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4517 } else {
4518 result = new byte[length];
4519 }
4520
4521 result[length - 1] = (byte) response.sw2;
4522 result[length - 2] = (byte) response.sw1;
4523 return result;
4524 } finally {
4525 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004526 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004527 }
4528
Nathan Haroldb3014052017-01-25 15:57:32 -08004529 /**
4530 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4531 * on a particular subscription
4532 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004533 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4534 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004535 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004536 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004537 return null;
4538 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004539
4540 final long identity = Binder.clearCallingIdentity();
4541 try {
4542 if (appType != TelephonyManager.APPTYPE_USIM
4543 && appType != TelephonyManager.APPTYPE_SIM) {
4544 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4545 return null;
4546 }
4547 Object response = sendRequest(
4548 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4549 if (response instanceof String[]) {
4550 return (String[]) response;
4551 }
yincheng zhao2737e882019-09-06 17:06:54 -07004552 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004553 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004554 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004555 } finally {
4556 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004557 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004558 }
4559
yincheng zhao2737e882019-09-06 17:06:54 -07004560 /**
4561 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4562 * subscription.
4563 *
4564 * @param subId the id of the subscription.
4565 * @param appType the uicc app type, must be USIM or SIM.
4566 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4567 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004568 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004569 * @return number of fplmns that is successfully written to the SIM.
4570 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004571 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4572 String callingFeatureId) {
4573 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4574 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004575 if (DBG) logv("no permissions for setForbiddenplmns");
4576 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4577 }
4578 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4579 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4580 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4581 }
4582 if (fplmns == null) {
4583 throw new IllegalArgumentException("Fplmn List provided is null");
4584 }
4585 for (String fplmn : fplmns) {
4586 if (!CellIdentity.isValidPlmn(fplmn)) {
4587 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4588 }
4589 }
4590 final long identity = Binder.clearCallingIdentity();
4591 try {
4592 Object response = sendRequest(
4593 CMD_SET_FORBIDDEN_PLMNS,
4594 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4595 subId);
4596 return (int) response;
4597 } finally {
4598 Binder.restoreCallingIdentity(identity);
4599 }
4600 }
4601
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004602 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004603 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004604 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4605 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004606
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004607 final long identity = Binder.clearCallingIdentity();
4608 try {
4609 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4610 if (response.payload == null) {
4611 return "";
4612 }
Evan Charltonc66da362014-05-16 14:06:40 -07004613
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004614 // Append the returned status code to the end of the response payload.
4615 String s = Integer.toHexString(
4616 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4617 s = IccUtils.bytesToHexString(response.payload) + s;
4618 return s;
4619 } finally {
4620 Binder.restoreCallingIdentity(identity);
4621 }
Evan Charltonc66da362014-05-16 14:06:40 -07004622 }
4623
Jake Hambye994d462014-02-03 13:10:13 -08004624 /**
4625 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4626 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4627 *
4628 * @param itemID the ID of the item to read
4629 * @return the NV item as a String, or null on error.
4630 */
4631 @Override
4632 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004633 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4635 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004636
4637 final long identity = Binder.clearCallingIdentity();
4638 try {
4639 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004640 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004641 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4642 return value;
4643 } finally {
4644 Binder.restoreCallingIdentity(identity);
4645 }
Jake Hambye994d462014-02-03 13:10:13 -08004646 }
4647
4648 /**
4649 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4650 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4651 *
4652 * @param itemID the ID of the item to read
4653 * @param itemValue the value to write, as a String
4654 * @return true on success; false on any failure
4655 */
4656 @Override
4657 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004658 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4660 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004661
4662 final long identity = Binder.clearCallingIdentity();
4663 try {
4664 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4665 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004666 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004667 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4668 return success;
4669 } finally {
4670 Binder.restoreCallingIdentity(identity);
4671 }
Jake Hambye994d462014-02-03 13:10:13 -08004672 }
4673
4674 /**
4675 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4676 * Used for device configuration by some CDMA operators.
4677 *
4678 * @param preferredRoamingList byte array containing the new PRL
4679 * @return true on success; false on any failure
4680 */
4681 @Override
4682 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004683 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4684 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004685
4686 final long identity = Binder.clearCallingIdentity();
4687 try {
4688 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4689 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4690 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4691 return success;
4692 } finally {
4693 Binder.restoreCallingIdentity(identity);
4694 }
Jake Hambye994d462014-02-03 13:10:13 -08004695 }
4696
4697 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004698 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004699 * Used for device configuration by some CDMA operators.
4700 *
chen xu6dac5ab2018-10-26 17:39:23 -07004701 * @param slotIndex - device slot.
4702 *
Jake Hambye994d462014-02-03 13:10:13 -08004703 * @return true on success; false on any failure
4704 */
4705 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004706 public boolean resetModemConfig(int slotIndex) {
4707 Phone phone = PhoneFactory.getPhone(slotIndex);
4708 if (phone != null) {
4709 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4710 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004711
chen xu6dac5ab2018-10-26 17:39:23 -07004712 final long identity = Binder.clearCallingIdentity();
4713 try {
4714 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4715 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4716 return success;
4717 } finally {
4718 Binder.restoreCallingIdentity(identity);
4719 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004720 }
chen xu6dac5ab2018-10-26 17:39:23 -07004721 return false;
4722 }
4723
4724 /**
4725 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4726 *
4727 * @param slotIndex - device slot.
4728 *
4729 * @return true on success; false on any failure
4730 */
4731 @Override
4732 public boolean rebootModem(int slotIndex) {
4733 Phone phone = PhoneFactory.getPhone(slotIndex);
4734 if (phone != null) {
4735 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4736 mApp, phone.getSubId(), "rebootModem");
4737
4738 final long identity = Binder.clearCallingIdentity();
4739 try {
4740 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4741 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4742 return success;
4743 } finally {
4744 Binder.restoreCallingIdentity(identity);
4745 }
4746 }
4747 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004748 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004749
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004750 public String[] getPcscfAddress(String apnType, String callingPackage,
4751 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004752 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004753 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4754 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004755 return new String[0];
4756 }
4757
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004758 final long identity = Binder.clearCallingIdentity();
4759 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004760 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004761 } finally {
4762 Binder.restoreCallingIdentity(identity);
4763 }
Wink Saville36469e72014-06-11 15:17:00 -07004764 }
4765
Brad Ebinger51f743a2017-01-23 13:50:20 -08004766 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004767 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4768 * {@link #disableIms(int)}.
4769 * @param slotIndex device slot.
4770 */
4771 public void resetIms(int slotIndex) {
4772 enforceModifyPermission();
4773
4774 final long identity = Binder.clearCallingIdentity();
4775 try {
4776 if (mImsResolver == null) {
4777 // may happen if the does not support IMS.
4778 return;
4779 }
4780 mImsResolver.disableIms(slotIndex);
4781 mImsResolver.enableIms(slotIndex);
4782 } finally {
4783 Binder.restoreCallingIdentity(identity);
4784 }
4785 }
4786
4787 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004788 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4789 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004790 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004791 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004792 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004793
4794 final long identity = Binder.clearCallingIdentity();
4795 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004796 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004797 // may happen if the device does not support IMS.
4798 return;
4799 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004800 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004801 } finally {
4802 Binder.restoreCallingIdentity(identity);
4803 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004804 }
4805
4806 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004807 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4808 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004809 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004810 public void disableIms(int slotId) {
4811 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004812
4813 final long identity = Binder.clearCallingIdentity();
4814 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004815 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004816 // may happen if the device does not support IMS.
4817 return;
4818 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004819 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004820 } finally {
4821 Binder.restoreCallingIdentity(identity);
4822 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004823 }
4824
4825 /**
4826 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4827 * feature or {@link null} if the service is not available. If the feature is available, the
4828 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4829 */
4830 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004831 IImsServiceFeatureCallback callback) {
4832 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004833
4834 final long identity = Binder.clearCallingIdentity();
4835 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004836 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004837 // may happen if the device does not support IMS.
4838 return null;
4839 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004840 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004841 } finally {
4842 Binder.restoreCallingIdentity(identity);
4843 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004844 }
4845
4846 /**
4847 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4848 * feature during emergency calling or {@link null} if the service is not available. If the
4849 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4850 * listener for feature updates.
4851 */
4852 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4853 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004854
4855 final long identity = Binder.clearCallingIdentity();
4856 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004857 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004858 // may happen if the device does not support IMS.
4859 return null;
4860 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004861 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004862 } finally {
4863 Binder.restoreCallingIdentity(identity);
4864 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004865 }
4866
Brad Ebinger5f64b052017-12-14 14:26:15 -08004867 /**
4868 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004869 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004870 */
4871 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4872 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004873
4874 final long identity = Binder.clearCallingIdentity();
4875 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004876 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004877 // may happen if the device does not support IMS.
4878 return null;
4879 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004880 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004881 } finally {
4882 Binder.restoreCallingIdentity(identity);
4883 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004884 }
4885
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004886 /**
4887 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004888 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004889 */
4890 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4891 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004892
4893 final long identity = Binder.clearCallingIdentity();
4894 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004895 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004896 // may happen if the device does not support IMS.
4897 return null;
4898 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004899 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004900 } finally {
4901 Binder.restoreCallingIdentity(identity);
4902 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004903 }
4904
Brad Ebinger884c07b2018-02-15 16:17:40 -08004905 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004906 * Sets the ImsService Package Name that Telephony will bind to.
4907 *
Brad Ebinger24c29992019-12-05 13:03:21 -08004908 * @param slotIndex the slot ID that the ImsService should bind for.
4909 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004910 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08004911 * @param featureTypes An integer array of feature types associated with a packageName.
4912 * @param packageName The name of the package that the current configuration will be replaced
4913 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004914 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004915 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004916 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4917 int[] featureTypes, String packageName) {
4918 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4919 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004920 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4921 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08004922 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004923
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004924 final long identity = Binder.clearCallingIdentity();
4925 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004926 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004927 // may happen if the device does not support IMS.
4928 return false;
4929 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004930 Map<Integer, String> featureConfig = new HashMap<>();
4931 for (int featureType : featureTypes) {
4932 featureConfig.put(featureType, packageName);
4933 }
4934 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4935 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004936 } finally {
4937 Binder.restoreCallingIdentity(identity);
4938 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004939 }
4940
4941 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08004942 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004943 *
4944 * @param slotId The slot that the ImsService is associated with.
4945 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4946 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08004947 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004948 * @return the package name of the ImsService configuration.
4949 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004950 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4951 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004952 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08004953 TelephonyPermissions
4954 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4955 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4956 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004957
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004958 final long identity = Binder.clearCallingIdentity();
4959 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004960 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004961 // may happen if the device does not support IMS.
4962 return "";
4963 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004964 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08004965 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4966 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004967 } finally {
4968 Binder.restoreCallingIdentity(identity);
4969 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004970 }
4971
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004972 /**
4973 * Get the MmTelFeature state associated with the requested subscription id.
4974 * @param subId The subscription that the MmTelFeature is associated with.
4975 * @param callback A callback with an integer containing the
4976 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4977 */
4978 @Override
4979 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4980 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4981 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4982 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4983 "IMS not available on device.");
4984 }
4985 final long token = Binder.clearCallingIdentity();
4986 try {
4987 int slotId = getSlotIndex(subId);
4988 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4989 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4990 + subId + "'");
4991 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4992 }
4993 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4994 try {
4995 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4996 } catch (RemoteException e) {
4997 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4998 + "Ignore");
4999 }
5000 });
5001 } finally {
5002 Binder.restoreCallingIdentity(token);
5003 }
5004 }
5005
Wink Saville36469e72014-06-11 15:17:00 -07005006 public void setImsRegistrationState(boolean registered) {
5007 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005008
5009 final long identity = Binder.clearCallingIdentity();
5010 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005011 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005012 } finally {
5013 Binder.restoreCallingIdentity(identity);
5014 }
Wink Saville36469e72014-06-11 15:17:00 -07005015 }
5016
5017 /**
Stuart Scott54788802015-03-30 13:18:01 -07005018 * Set the network selection mode to automatic.
5019 *
5020 */
5021 @Override
5022 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005023 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5024 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005025
5026 final long identity = Binder.clearCallingIdentity();
5027 try {
shilufc958392020-01-20 11:36:01 -08005028 if (!isActiveSubscription(subId)) {
5029 return;
5030 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005031 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5032 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5033 } finally {
5034 Binder.restoreCallingIdentity(identity);
5035 }
Stuart Scott54788802015-03-30 13:18:01 -07005036 }
5037
Pengquan Mengea84e042018-09-20 14:57:26 -07005038 /**
5039 * Ask the radio to connect to the input network and change selection mode to manual.
5040 *
5041 * @param subId the id of the subscription.
5042 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5043 * the operator to attach to.
5044 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5045 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5046 * normal network selection next time.
5047 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005048 */
5049 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005050 public boolean setNetworkSelectionModeManual(
5051 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005052 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5053 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005054
5055 if (!isActiveSubscription(subId)) {
5056 return false;
5057 }
5058
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005059 final long identity = Binder.clearCallingIdentity();
5060 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005061 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005062 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005063 if (DBG) {
5064 log("setNetworkSelectionModeManual: subId: " + subId
5065 + " operator: " + operatorInfo);
5066 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005067 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5068 } finally {
5069 Binder.restoreCallingIdentity(identity);
5070 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005071 }
shilu84f6e8b2019-12-19 13:58:01 -08005072 /**
5073 * Get the manual network selection
5074 *
5075 * @param subId the id of the subscription.
5076 *
5077 * @return the previously saved user selected PLMN
5078 */
5079 @Override
5080 public String getManualNetworkSelectionPlmn(int subId) {
5081 TelephonyPermissions
5082 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5083 mApp, subId, "getManualNetworkSelectionPlmn");
5084
5085 final long identity = Binder.clearCallingIdentity();
5086 try {
5087 if (!isActiveSubscription(subId)) {
5088 return "";
5089 }
5090
5091 final Phone phone = getPhone(subId);
5092 if (phone == null) {
5093 return "";
5094 }
5095 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5096 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5097 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5098 } finally {
5099 Binder.restoreCallingIdentity(identity);
5100 }
5101 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005102
5103 /**
5104 * Scans for available networks.
5105 */
5106 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005107 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5108 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005109 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5110 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005111 LocationAccessPolicy.LocationPermissionResult locationResult =
5112 LocationAccessPolicy.checkLocationPermission(mApp,
5113 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5114 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005115 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005116 .setCallingPid(Binder.getCallingPid())
5117 .setCallingUid(Binder.getCallingUid())
5118 .setMethod("getCellNetworkScanResults")
5119 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5120 .build());
5121 switch (locationResult) {
5122 case DENIED_HARD:
5123 throw new SecurityException("Not allowed to access scan results -- location");
5124 case DENIED_SOFT:
5125 return null;
5126 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005127
Pengquan Menga1bb6272018-09-06 09:59:22 -07005128 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005129 try {
5130 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005131 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005132 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005133 } finally {
5134 Binder.restoreCallingIdentity(identity);
5135 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005136 }
5137
5138 /**
yinxub1bed742017-04-17 11:45:04 -07005139 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005140 *
yinxub1bed742017-04-17 11:45:04 -07005141 * @param subId id of the subscription
5142 * @param request contains the radio access networks with bands/channels to scan
5143 * @param messenger callback messenger for scan results or errors
5144 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005145 * @return the id of the requested scan which can be used to stop the scan.
5146 */
5147 @Override
5148 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005149 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5151 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005152 LocationAccessPolicy.LocationPermissionResult locationResult =
5153 LocationAccessPolicy.checkLocationPermission(mApp,
5154 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5155 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005156 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005157 .setCallingPid(Binder.getCallingPid())
5158 .setCallingUid(Binder.getCallingUid())
5159 .setMethod("requestNetworkScan")
5160 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5161 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005162 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005163 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005164 if (e != null) {
5165 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5166 throw e;
5167 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005168 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005169 return TelephonyScanManager.INVALID_SCAN_ID;
5170 }
5171 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005172 }
Hall Liu912dfd32019-04-25 14:02:26 -07005173 int callingUid = Binder.getCallingUid();
5174 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005175 final long identity = Binder.clearCallingIdentity();
5176 try {
5177 return mNetworkScanRequestTracker.startNetworkScan(
5178 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005179 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005180 } finally {
5181 Binder.restoreCallingIdentity(identity);
5182 }
yinxu504e1392017-04-12 16:03:22 -07005183 }
5184
Hall Liub2ac8ef2019-02-28 15:56:23 -08005185 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005186 NetworkScanRequest request, int subId) {
5187 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5188 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5189 boolean hasNetworkScanPermission =
5190 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5191 == PERMISSION_GRANTED;
5192
5193 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5194 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5195 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005196 }
5197
5198 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5199 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005200 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5201 return new SecurityException("Specific channels must not be"
5202 + " scanned without location access.");
5203 }
5204 }
5205 }
5206
Hall Liub2ac8ef2019-02-28 15:56:23 -08005207 return null;
5208 }
5209
yinxu504e1392017-04-12 16:03:22 -07005210 /**
5211 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005212 *
5213 * @param subId id of the subscription
5214 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005215 */
5216 @Override
5217 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005218 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5219 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005220
Hall Liu912dfd32019-04-25 14:02:26 -07005221 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005222 final long identity = Binder.clearCallingIdentity();
5223 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005224 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005225 } finally {
5226 Binder.restoreCallingIdentity(identity);
5227 }
yinxu504e1392017-04-12 16:03:22 -07005228 }
5229
5230 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005231 * Get the calculated preferred network type.
5232 * Used for debugging incorrect network type.
5233 *
5234 * @return the preferred network type, defined in RILConstants.java.
5235 */
5236 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005237 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005238 final Phone defaultPhone = getDefaultPhone();
5239 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005240 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005241 return RILConstants.PREFERRED_NETWORK_MODE;
5242 }
5243
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005244 final long identity = Binder.clearCallingIdentity();
5245 try {
5246 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005247 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005248 } finally {
5249 Binder.restoreCallingIdentity(identity);
5250 }
Junda Liu84d15a22014-07-02 11:21:04 -07005251 }
5252
5253 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005254 * Get the preferred network type.
5255 * Used for device configuration by some CDMA operators.
5256 *
5257 * @return the preferred network type, defined in RILConstants.java.
5258 */
5259 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005260 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005261 TelephonyPermissions
5262 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5263 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005264
5265 final long identity = Binder.clearCallingIdentity();
5266 try {
5267 if (DBG) log("getPreferredNetworkType");
5268 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5269 int networkType = (result != null ? result[0] : -1);
5270 if (DBG) log("getPreferredNetworkType: " + networkType);
5271 return networkType;
5272 } finally {
5273 Binder.restoreCallingIdentity(identity);
5274 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005275 }
5276
5277 /**
5278 * Set the preferred network type.
5279 * Used for device configuration by some CDMA operators.
5280 *
5281 * @param networkType the preferred network type, defined in RILConstants.java.
5282 * @return true on success; false on any failure.
5283 */
5284 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005285 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005286 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5287 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005288
5289 final long identity = Binder.clearCallingIdentity();
5290 try {
calvinpan0ac9c1a2020-01-14 20:42:55 +08005291 Settings.Global.putInt(mApp.getContentResolver(),
5292 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5293 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005294 } finally {
5295 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005296 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005297 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005298
5299 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005300 * Get the allowed network types that store in the telephony provider.
5301 *
5302 * @param subId the id of the subscription.
5303 * @return allowedNetworkTypes the allowed network types.
5304 */
5305 @Override
5306 public long getAllowedNetworkTypes(int subId) {
5307 TelephonyPermissions
5308 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5309 mApp, subId, "getAllowedNetworkTypes");
5310
5311 final long identity = Binder.clearCallingIdentity();
5312 try {
5313 return SubscriptionManager.getLongSubscriptionProperty(
5314 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5315 } finally {
5316 Binder.restoreCallingIdentity(identity);
5317 }
5318 }
5319
5320 /**
5321 * Set the allowed network types.
5322 *
5323 * @param subId the id of the subscription.
5324 * @param allowedNetworkTypes the allowed network types.
5325 * @return true on success; false on any failure.
5326 */
5327 @Override
5328 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5330 mApp, subId, "setAllowedNetworkTypes");
5331 final long identity = Binder.clearCallingIdentity();
5332 try {
5333 SubscriptionManager.setSubscriptionProperty(subId,
5334 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5335 String.valueOf(allowedNetworkTypes));
5336 return setPreferredNetworkTypesInternal(subId);
5337 } finally {
5338 Binder.restoreCallingIdentity(identity);
5339 }
5340 }
5341
5342 private boolean setPreferredNetworkTypesInternal(int subId) {
5343 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5344 Settings.Global.getInt(mApp.getContentResolver(),
5345 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5346 RILConstants.PREFERRED_NETWORK_MODE));
5347 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5348 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5349 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5350 (int) (networkTypeBitMask & allowedNetworkTypes));
5351
5352 if (DBG) {
5353 log("setPreferredNetworkTypesInternal: subId " + subId
5354 + " networkTypes " + networkTypeBitMask
5355 + " allowedNetworkTypes " + allowedNetworkTypes
5356 + " networkMode " + networkMode);
5357 }
5358
5359 Boolean success = (Boolean) sendRequest(
5360 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5361 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5362 return success;
5363 }
5364
5365 /**
Miaoa84611c2019-03-15 09:21:10 +08005366 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005367 *
Miaoa84611c2019-03-15 09:21:10 +08005368 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005369 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005370 * @hide
5371 */
5372 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005373 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005374 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005375 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005376 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005377 try {
Miaoa84611c2019-03-15 09:21:10 +08005378 if (phone != null) {
5379 return phone.hasMatchedTetherApnSetting();
5380 } else {
5381 return false;
5382 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005383 } finally {
5384 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005385 }
Junda Liu475951f2014-11-07 16:45:03 -08005386 }
5387
5388 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005389 * Set mobile data enabled
5390 * Used by the user through settings etc to turn on/off mobile data
5391 *
5392 * @param enable {@code true} turn turn data on, else {@code false}
5393 */
5394 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005395 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005396 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5397 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005398
5399 final long identity = Binder.clearCallingIdentity();
5400 try {
5401 int phoneId = mSubscriptionController.getPhoneId(subId);
5402 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5403 Phone phone = PhoneFactory.getPhone(phoneId);
5404 if (phone != null) {
5405 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005406 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005407 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005408 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005409 }
5410 } finally {
5411 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005412 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005413 }
5414
5415 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005416 * Enable or disable always reporting signal strength changes from radio.
5417 *
5418 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5419 */
5420 @Override
5421 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5422 enforceModifyPermission();
5423 enforceSystemCaller();
5424
5425 final long identity = Binder.clearCallingIdentity();
5426 final Phone phone = getPhone(subId);
5427 try {
5428 if (phone != null) {
5429 if (DBG) {
5430 log("setAlwaysReportSignalStrength: subId=" + subId
5431 + " isEnable=" + isEnable);
5432 }
5433 phone.setAlwaysReportSignalStrength(isEnable);
5434 } else {
5435 loge("setAlwaysReportSignalStrength: no phone found for subId="
5436 + subId);
5437 }
5438 } finally {
5439 Binder.restoreCallingIdentity(identity);
5440 }
5441 }
5442
5443 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005444 * Get the user enabled state of Mobile Data.
5445 *
5446 * TODO: remove and use isUserDataEnabled.
5447 * This can't be removed now because some vendor codes
5448 * calls through ITelephony directly while they should
5449 * use TelephonyManager.
5450 *
5451 * @return true on enabled
5452 */
5453 @Override
5454 public boolean getDataEnabled(int subId) {
5455 return isUserDataEnabled(subId);
5456 }
5457
5458 /**
5459 * Get whether mobile data is enabled per user setting.
5460 *
5461 * There are other factors deciding whether mobile data is actually enabled, but they are
5462 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005463 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005464 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005465 *
5466 * @return {@code true} if data is enabled else {@code false}
5467 */
5468 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005469 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005470 try {
5471 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5472 null);
5473 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5475 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005476 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005477
5478 final long identity = Binder.clearCallingIdentity();
5479 try {
5480 int phoneId = mSubscriptionController.getPhoneId(subId);
5481 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5482 Phone phone = PhoneFactory.getPhone(phoneId);
5483 if (phone != null) {
5484 boolean retVal = phone.isUserDataEnabled();
5485 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5486 return retVal;
5487 } else {
5488 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5489 return false;
5490 }
5491 } finally {
5492 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005493 }
5494 }
5495
5496 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005497 * Checks if the device is capable of mobile data by considering whether whether the
5498 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5499 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005500 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005501 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005502 */
5503 @Override
5504 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005505 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506
5507 final long identity = Binder.clearCallingIdentity();
5508 try {
5509 int phoneId = mSubscriptionController.getPhoneId(subId);
5510 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5511 Phone phone = PhoneFactory.getPhone(phoneId);
5512 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005513 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005514 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5515 return retVal;
5516 } else {
5517 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5518 return false;
5519 }
5520 } finally {
5521 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005522 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005523 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005524
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005525 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5526 Phone phone) {
5527 //load access rules from carrier configs, and check those as well: b/139133814
5528 SubscriptionController subController = SubscriptionController.getInstance();
5529 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5530 || subController == null) return privilegeFromSim;
5531
5532 int uid = Binder.getCallingUid();
5533 PackageManager pkgMgr = phone.getContext().getPackageManager();
5534 String[] packages = pkgMgr.getPackagesForUid(uid);
5535
5536 final long identity = Binder.clearCallingIdentity();
5537 try {
5538 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5539 SubscriptionManager subManager = (SubscriptionManager)
5540 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5541 for (String pkg : packages) {
5542 if (subManager.canManageSubscription(subInfo, pkg)) {
5543 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5544 }
5545 }
5546 return privilegeFromSim;
5547 } finally {
5548 Binder.restoreCallingIdentity(identity);
5549 }
5550 }
5551
5552 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5553 String pkgName) {
5554 //load access rules from carrier configs, and check those as well: b/139133814
5555 SubscriptionController subController = SubscriptionController.getInstance();
5556 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5557 || subController == null) return privilegeFromSim;
5558
5559 final long identity = Binder.clearCallingIdentity();
5560 try {
5561 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5562 SubscriptionManager subManager = (SubscriptionManager)
5563 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5564 return subManager.canManageSubscription(subInfo, pkgName)
5565 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5566 } finally {
5567 Binder.restoreCallingIdentity(identity);
5568 }
5569 }
5570
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005571 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005572 public int getCarrierPrivilegeStatus(int subId) {
5573 final Phone phone = getPhone(subId);
5574 if (phone == null) {
5575 loge("getCarrierPrivilegeStatus: Invalid subId");
5576 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5577 }
5578 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005579 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005580 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005581 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5582 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005583
5584 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5585 card.getCarrierPrivilegeStatusForCurrentTransaction(
5586 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005587 }
Junda Liu29340342014-07-10 15:23:27 -07005588
5589 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005590 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005591 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005592 final Phone phone = getPhone(subId);
5593 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005594 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005595 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5596 }
5597 UiccProfile profile =
5598 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5599 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005600 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005601 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5602 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005603 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005604 profile.getCarrierPrivilegeStatusForUid(
5605 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005606 }
5607
5608 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005609 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5610 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005611 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005612 }
5613
5614 int phoneId = SubscriptionManager.getPhoneId(subId);
5615 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005616 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005617 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005618 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5619 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005620 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5621 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5622 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005623 }
5624
5625 @Override
5626 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005627 if (TextUtils.isEmpty(pkgName))
5628 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005629 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5630 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5631 UiccCard card = UiccController.getInstance().getUiccCard(i);
5632 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005633 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005634 continue;
5635 }
5636
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005637 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5638 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5639 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005640 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5641 break;
5642 }
5643 }
5644
5645 return result;
Junda Liu29340342014-07-10 15:23:27 -07005646 }
Derek Tan89e89d42014-07-08 17:00:10 -07005647
5648 @Override
Junda Liue64de782015-04-16 17:19:16 -07005649 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5650 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5651 loge("phoneId " + phoneId + " is not valid.");
5652 return null;
5653 }
5654 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005655 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005656 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005657 return null ;
5658 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005659 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005660 }
5661
Amith Yamasani6e118872016-02-19 12:53:51 -08005662 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005663 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005664 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005665 List<String> privilegedPackages = new ArrayList<>();
5666 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005667 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5668 // has UICC in that slot.
5669 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005670 if (card.hasCarrierPrivilegeRules()) {
5671 if (packages == null) {
5672 // Only check packages in user 0 for now
5673 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005674 PackageManager.MATCH_DISABLED_COMPONENTS
5675 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005676 | PackageManager.GET_SIGNING_CERTIFICATES,
5677 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005678 }
5679 for (int p = packages.size() - 1; p >= 0; p--) {
5680 PackageInfo pkgInfo = packages.get(p);
5681 if (pkgInfo != null && pkgInfo.packageName != null
5682 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005683 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005684 privilegedPackages.add(pkgInfo.packageName);
5685 }
5686 }
5687 }
5688 }
5689 return privilegedPackages;
5690 }
5691
chen xuf7e9fe82019-05-09 19:31:02 -07005692 @Override
5693 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005694 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5695
5696 final long identity = Binder.clearCallingIdentity();
5697
chen xuf7e9fe82019-05-09 19:31:02 -07005698 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005699 try {
5700 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5701 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5702 }
5703 } finally {
5704 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005705 }
5706 return privilegedPackages;
5707 }
5708
Wink Savilleb564aae2014-10-23 10:18:09 -07005709 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005710 final Phone phone = getPhone(subId);
5711 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005712 if (card == null) {
5713 loge("getIccId: No UICC");
5714 return null;
5715 }
5716 String iccId = card.getIccId();
5717 if (TextUtils.isEmpty(iccId)) {
5718 loge("getIccId: ICC ID is null or empty.");
5719 return null;
5720 }
5721 return iccId;
5722 }
5723
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005724 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005725 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5726 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005727 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005728 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005729
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005730 final long identity = Binder.clearCallingIdentity();
5731 try {
5732 final String iccId = getIccId(subId);
5733 final Phone phone = getPhone(subId);
5734 if (phone == null) {
5735 return false;
5736 }
5737 final String subscriberId = phone.getSubscriberId();
5738
5739 if (DBG_MERGE) {
5740 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5741 + subscriberId + " to " + number);
5742 }
5743
5744 if (TextUtils.isEmpty(iccId)) {
5745 return false;
5746 }
5747
5748 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5749
5750 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5751 if (alphaTag == null) {
5752 editor.remove(alphaTagPrefKey);
5753 } else {
5754 editor.putString(alphaTagPrefKey, alphaTag);
5755 }
5756
5757 // Record both the line number and IMSI for this ICCID, since we need to
5758 // track all merged IMSIs based on line number
5759 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5760 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5761 if (number == null) {
5762 editor.remove(numberPrefKey);
5763 editor.remove(subscriberPrefKey);
5764 } else {
5765 editor.putString(numberPrefKey, number);
5766 editor.putString(subscriberPrefKey, subscriberId);
5767 }
5768
5769 editor.commit();
5770 return true;
5771 } finally {
5772 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005773 }
Derek Tan7226c842014-07-02 17:42:23 -07005774 }
5775
5776 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005777 public String getLine1NumberForDisplay(int subId, String callingPackage,
5778 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005779 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005780 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005781 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005782 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005783 return null;
5784 }
Derek Tan97ebb422014-09-05 16:55:38 -07005785
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005786 final long identity = Binder.clearCallingIdentity();
5787 try {
5788 String iccId = getIccId(subId);
5789 if (iccId != null) {
5790 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5791 if (DBG_MERGE) {
5792 log("getLine1NumberForDisplay returning "
5793 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5794 }
5795 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005796 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005797 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5798 return null;
5799 } finally {
5800 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005801 }
Derek Tan7226c842014-07-02 17:42:23 -07005802 }
5803
5804 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005805 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5806 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005807 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005808 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005809 return null;
5810 }
Derek Tan97ebb422014-09-05 16:55:38 -07005811
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005812 final long identity = Binder.clearCallingIdentity();
5813 try {
5814 String iccId = getIccId(subId);
5815 if (iccId != null) {
5816 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5817 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5818 }
5819 return null;
5820 } finally {
5821 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005822 }
Derek Tan7226c842014-07-02 17:42:23 -07005823 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005824
5825 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005826 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5827 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005828 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5829 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005830 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005831 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005832 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005833 return null;
5834 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005835
Jordan Liub49b04b2019-05-06 14:45:15 -07005836 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5837 // the process, where TelephonyManager was instantiated.
5838 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005839 final long identity = Binder.clearCallingIdentity();
5840 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005841 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005842 final TelephonyManager tele = TelephonyManager.from(context);
5843 final SubscriptionManager sub = SubscriptionManager.from(context);
5844
5845 // Figure out what subscribers are currently active
5846 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005847
Jordan Liub49b04b2019-05-06 14:45:15 -07005848 // Only consider subs which match the current subId
5849 // This logic can be simplified. See b/131189269 for progress.
5850 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005851 activeSubscriberIds.add(tele.getSubscriberId(subId));
5852 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005853
5854 // First pass, find a number override for an active subscriber
5855 String mergeNumber = null;
5856 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5857 for (String key : prefs.keySet()) {
5858 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5859 final String subscriberId = (String) prefs.get(key);
5860 if (activeSubscriberIds.contains(subscriberId)) {
5861 final String iccId = key.substring(
5862 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5863 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5864 mergeNumber = (String) prefs.get(numberKey);
5865 if (DBG_MERGE) {
5866 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5867 + " for active subscriber " + subscriberId);
5868 }
5869 if (!TextUtils.isEmpty(mergeNumber)) {
5870 break;
5871 }
5872 }
5873 }
5874 }
5875
5876 // Shortcut when no active merged subscribers
5877 if (TextUtils.isEmpty(mergeNumber)) {
5878 return null;
5879 }
5880
5881 // Second pass, find all subscribers under that line override
5882 final ArraySet<String> result = new ArraySet<>();
5883 for (String key : prefs.keySet()) {
5884 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5885 final String number = (String) prefs.get(key);
5886 if (mergeNumber.equals(number)) {
5887 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5888 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5889 final String subscriberId = (String) prefs.get(subscriberKey);
5890 if (!TextUtils.isEmpty(subscriberId)) {
5891 result.add(subscriberId);
5892 }
5893 }
5894 }
5895 }
5896
5897 final String[] resultArray = result.toArray(new String[result.size()]);
5898 Arrays.sort(resultArray);
5899 if (DBG_MERGE) {
5900 Slog.d(LOG_TAG,
5901 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5902 }
5903 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005904 } finally {
5905 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005906 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005907 }
5908
5909 @Override
zoey chen38003472019-12-13 17:16:31 +08005910 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
5911 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07005912
5913 final long identity = Binder.clearCallingIdentity();
5914 try {
5915 final TelephonyManager telephonyManager = mApp.getSystemService(
5916 TelephonyManager.class);
5917 String subscriberId = telephonyManager.getSubscriberId(subId);
5918 if (subscriberId == null) {
5919 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08005920 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07005921 + subId);
5922 }
5923 return null;
5924 }
5925
5926 final SubscriptionInfo info = SubscriptionController.getInstance()
5927 .getSubscriptionInfo(subId);
5928 final ParcelUuid groupUuid = info.getGroupUuid();
5929 // If it doesn't belong to any group, return just subscriberId of itself.
5930 if (groupUuid == null) {
5931 return new String[]{subscriberId};
5932 }
5933
5934 // Get all subscriberIds from the group.
5935 final List<String> mergedSubscriberIds = new ArrayList<>();
5936 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005937 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5938 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005939 for (SubscriptionInfo subInfo : groupInfos) {
5940 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5941 if (subscriberId != null) {
5942 mergedSubscriberIds.add(subscriberId);
5943 }
5944 }
5945
5946 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5947 } finally {
5948 Binder.restoreCallingIdentity(identity);
5949
5950 }
5951 }
5952
5953 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005954 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005955 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005956 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005957
5958 final long identity = Binder.clearCallingIdentity();
5959 try {
5960 final Phone phone = getPhone(subId);
5961 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5962 } finally {
5963 Binder.restoreCallingIdentity(identity);
5964 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005965 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005966
5967 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005968 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005969 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5970 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005971 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5972 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005973
5974 final long identity = Binder.clearCallingIdentity();
5975 try {
5976 final Phone phone = getPhone(subId);
5977 if (phone == null) {
5978 return false;
5979 }
5980 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5981 cdmaNonRoamingList);
5982 } finally {
5983 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005984 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005985 }
5986
5987 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005988 @Deprecated
5989 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5990 enforceModifyPermission();
5991
5992 int returnValue = 0;
5993 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005994 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005995 if(result.exception == null) {
5996 if (result.result != null) {
5997 byte[] responseData = (byte[])(result.result);
5998 if(responseData.length > oemResp.length) {
5999 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6000 responseData.length + "bytes. Buffer Size is " +
6001 oemResp.length + "bytes.");
6002 }
6003 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6004 returnValue = responseData.length;
6005 }
6006 } else {
6007 CommandException ex = (CommandException) result.exception;
6008 returnValue = ex.getCommandError().ordinal();
6009 if(returnValue > 0) returnValue *= -1;
6010 }
6011 } catch (RuntimeException e) {
6012 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6013 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6014 if(returnValue > 0) returnValue *= -1;
6015 }
6016
6017 return returnValue;
6018 }
6019
6020 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006021 public void setRadioCapability(RadioAccessFamily[] rafs) {
6022 try {
6023 ProxyController.getInstance().setRadioCapability(rafs);
6024 } catch (RuntimeException e) {
6025 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6026 }
6027 }
6028
6029 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006030 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006031 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006032 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006033 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006034 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006035 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006036 final long identity = Binder.clearCallingIdentity();
6037 try {
chen xub97461a2018-10-26 14:17:57 -07006038 TelephonyPermissions
6039 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6040 mApp, phone.getSubId(), "getRadioAccessFamily");
6041 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006042 } finally {
6043 Binder.restoreCallingIdentity(identity);
6044 }
chen xub97461a2018-10-26 14:17:57 -07006045 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006046 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006047
6048 @Override
6049 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006050 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006051 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006052
6053 final long identity = Binder.clearCallingIdentity();
6054 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006055 ImsManager.getInstance(defaultPhone.getContext(),
6056 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006057 } finally {
6058 Binder.restoreCallingIdentity(identity);
6059 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006060 }
6061
6062 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006063 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006064 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006065 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6066 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006067 return false;
6068 }
Svet Ganovb320e182015-04-16 12:30:10 -07006069
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006070 final long identity = Binder.clearCallingIdentity();
6071 try {
6072 // Check the user preference and the system-level IMS setting. Even if the user has
6073 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6074 // In the long run, we may instead need to check if there exists a connection service
6075 // which can support video calling.
6076 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006077 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006078 return imsManager.isVtEnabledByPlatform()
6079 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6080 && imsManager.isVtEnabledByUser();
6081 } finally {
6082 Binder.restoreCallingIdentity(identity);
6083 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006084 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006085
Andrew Leea1239f22015-03-02 17:44:07 -08006086 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006087 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6088 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006089 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006090 mApp, subId, callingPackage, callingFeatureId,
6091 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006092 return false;
6093 }
6094
6095 final long identity = Binder.clearCallingIdentity();
6096 try {
6097 CarrierConfigManager configManager =
6098 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006099 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006100 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6101 } finally {
6102 Binder.restoreCallingIdentity(identity);
6103 }
Andrew Leea1239f22015-03-02 17:44:07 -08006104 }
6105
6106 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006107 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006108 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006109 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006110 return false;
6111 }
6112
6113 final long identity = Binder.clearCallingIdentity();
6114 try {
6115 CarrierConfigManager configManager =
6116 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006117 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006118 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6119 } finally {
6120 Binder.restoreCallingIdentity(identity);
6121 }
Andrew Leea1239f22015-03-02 17:44:07 -08006122 }
6123
Andrew Lee9431b832015-03-09 18:46:45 -07006124 @Override
6125 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006126 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006127 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006128 }
6129
6130 @Override
6131 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006132 final long identity = Binder.clearCallingIdentity();
6133 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006134 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135 } finally {
6136 Binder.restoreCallingIdentity(identity);
6137 }
Andrew Lee9431b832015-03-09 18:46:45 -07006138 }
6139
Hall Liuf6668912018-10-31 17:05:23 -07006140 /**
6141 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6142 * support for the feature and device firmware support.
6143 *
6144 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6145 */
6146 @Override
6147 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006148 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006149 final Phone phone = getPhone(subscriptionId);
6150 if (phone == null) {
6151 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6152 return false;
6153 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006154 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006155 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006156 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6157 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006158 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006159 return isCarrierSupported && isDeviceSupported;
6160 } finally {
6161 Binder.restoreCallingIdentity(identity);
6162 }
Hall Liu98187582018-01-22 19:15:32 -08006163 }
6164
Hall Liuf6668912018-10-31 17:05:23 -07006165 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006166 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6167 * RTT setting, will return true if the device and carrier both support RTT.
6168 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006169 */
6170 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006171 final long identity = Binder.clearCallingIdentity();
6172 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006173 boolean isRttSupported = isRttSupported(subscriptionId);
6174 boolean isUserRttSettingOn = Settings.Secure.getInt(
6175 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6176 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6177 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6178 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006179 } finally {
6180 Binder.restoreCallingIdentity(identity);
6181 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006182 }
6183
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006184 @Deprecated
6185 @Override
6186 public String getDeviceId(String callingPackage) {
6187 return getDeviceIdWithFeature(callingPackage, null);
6188 }
6189
Sanket Padawe7310cc72015-01-14 09:53:20 -08006190 /**
6191 * Returns the unique device ID of phone, for example, the IMEI for
6192 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6193 *
6194 * <p>Requires Permission:
6195 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6196 */
6197 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006198 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006199 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006200 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006201 return null;
6202 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006203 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006204 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006205 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006206 return null;
6207 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006208
6209 final long identity = Binder.clearCallingIdentity();
6210 try {
6211 return phone.getDeviceId();
6212 } finally {
6213 Binder.restoreCallingIdentity(identity);
6214 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006215 }
6216
Ping Sunc67b7c22016-03-02 19:16:45 +08006217 /**
6218 * {@hide}
6219 * Returns the IMS Registration Status on a particular subid
6220 *
6221 * @param subId
6222 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006223 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006224 Phone phone = getPhone(subId);
6225 if (phone != null) {
6226 return phone.isImsRegistered();
6227 } else {
6228 return false;
6229 }
6230 }
6231
Santos Cordon7a1885b2015-02-03 11:15:19 -08006232 @Override
6233 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006234 final long identity = Binder.clearCallingIdentity();
6235 try {
6236 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6237 } finally {
6238 Binder.restoreCallingIdentity(identity);
6239 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006240 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006241
Tyler Gunnf70ed162019-04-03 15:28:53 -07006242 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006243 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006244 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006245 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006246 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006247 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6248 }
6249 final long identity = Binder.clearCallingIdentity();
6250 try {
6251 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6252 } finally {
6253 Binder.restoreCallingIdentity(identity);
6254 }
6255 }
6256
6257 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006258 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6259 final long identity = Binder.clearCallingIdentity();
6260 try {
6261 Phone phone = getPhone(subscriptionId);
6262 if (phone == null) {
6263 return null;
6264 }
6265 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6266 } finally {
6267 Binder.restoreCallingIdentity(identity);
6268 }
6269 }
6270
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006271 /**
6272 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006273 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006274 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006275 final long identity = Binder.clearCallingIdentity();
6276 try {
6277 Phone phone = getPhone(subId);
6278 if (phone != null) {
6279 return phone.isWifiCallingEnabled();
6280 } else {
6281 return false;
6282 }
6283 } finally {
6284 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006285 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006286 }
6287
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006288 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006289 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006290 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006291 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006292 final long identity = Binder.clearCallingIdentity();
6293 try {
6294 Phone phone = getPhone(subId);
6295 if (phone != null) {
6296 return phone.isVideoEnabled();
6297 } else {
6298 return false;
6299 }
6300 } finally {
6301 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006302 }
6303 }
6304
6305 /**
6306 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6307 * defined in {@link ImsRegistrationImplBase}.
6308 */
6309 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006310 final long identity = Binder.clearCallingIdentity();
6311 try {
6312 Phone phone = getPhone(subId);
6313 if (phone != null) {
6314 return phone.getImsRegistrationTech();
6315 } else {
6316 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6317 }
6318 } finally {
6319 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006320 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006321 }
6322
Stuart Scott8eef64f2015-04-08 15:13:54 -07006323 @Override
6324 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006325 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006326 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6327 return;
6328 }
6329
Svet Ganovcc087f82015-05-12 20:35:54 -07006330 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006331
Svet Ganovcc087f82015-05-12 20:35:54 -07006332 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006333 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6334 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006335 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006336 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006337 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006338 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6339 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006340 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006341 // There has been issues when Sms raw table somehow stores orphan
6342 // fragments. They lead to garbled message when new fragments come
6343 // in and combined with those stale ones. In case this happens again,
6344 // user can reset all network settings which will clean up this table.
6345 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006346 // Clean up IMS settings as well here.
6347 int slotId = getSlotIndex(subId);
6348 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6349 ImsManager.getInstance(mApp, slotId).factoryReset();
6350 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006351
6352 // Erase modem config if erase modem on network setting is enabled.
6353 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6354 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6355 if (configValue != null && Boolean.parseBoolean(configValue)) {
6356 sendEraseModemConfig(getDefaultPhone());
6357 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006358 } finally {
6359 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006360 }
6361 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006362
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006363 private void cleanUpSmsRawTable(Context context) {
6364 ContentResolver resolver = context.getContentResolver();
6365 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6366 resolver.delete(uri, null, null);
6367 }
6368
Narayan Kamath1c496c22015-04-16 14:40:19 +01006369 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006370 public String getSimLocaleForSubscriber(int subId) {
6371 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6372 final Phone phone = getPhone(subId);
6373 if (phone == null) {
6374 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006375 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006376 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006377 final long identity = Binder.clearCallingIdentity();
6378 try {
chen xu5d3637b2019-01-21 23:31:38 -08006379 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006380 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08006381 if (info == null) {
6382 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6383 return null;
6384 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006385 // Try and fetch the locale from the carrier properties or from the SIM language
6386 // preferences (EF-PL and EF-LI)...
6387 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006388 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006389 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6390 if (localeFromDefaultSim != null) {
6391 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6392 if (DBG) log("Using locale from subId: " + subId + " locale: "
6393 + localeFromDefaultSim);
6394 return localeFromDefaultSim.toLanguageTag();
6395 } else {
6396 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006397 }
6398 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006399
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006400 // The SIM language preferences only store a language (e.g. fr = French), not an
6401 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6402 // the SIM and carrier preferences does not include a country we add the country
6403 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006404 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006406 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006407 return mccLocale.toLanguageTag();
6408 }
6409
6410 if (DBG) log("No locale found - returning null");
6411 return null;
6412 } finally {
6413 Binder.restoreCallingIdentity(identity);
6414 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006415 }
6416
6417 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006418 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6419 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006420 }
6421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006422 /**
6423 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6424 */
6425 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006426 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6427 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006428 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006429
Chenjie Yu1ba97252018-01-11 18:16:20 -08006430 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006431 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006432
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006433 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006434 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6435 * representing the state of the modem.
6436 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006437 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6438 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006439 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006440 */
6441 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006442 public void requestModemActivityInfo(ResultReceiver result) {
6443 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006444 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006445
6446 final long identity = Binder.clearCallingIdentity();
6447 try {
6448 ModemActivityInfo ret = null;
6449 synchronized (mLastModemActivityInfo) {
6450 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6451 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006452 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006453 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006454 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006455 int[] txTimeMs = info.getTransmitTimeMillis();
6456 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006457 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006458 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006459 }
6460 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006461 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6462 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006463 mLastModemActivityInfo.setIdleTimeMillis(
6464 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006465 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6466 mLastModemActivityInfo.setReceiveTimeMillis(
6467 info.getReceiveTimeMillis() + mLastModemActivityInfo
6468 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006469 }
Chen Xud78231e2019-09-10 18:49:52 -07006470
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006471 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6472 mLastModemActivityInfo.getSleepTimeMillis(),
6473 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006474 mLastModemActivityInfo.getTransmitTimeMillis(),
6475 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006476 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006477 Bundle bundle = new Bundle();
6478 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6479 result.send(0, bundle);
6480 } finally {
6481 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006482 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006483 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006484
Siddharth Rayb8114062018-06-17 15:02:38 -07006485 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6486 // less than total activity duration.
6487 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6488 if (info == null) {
6489 return false;
6490 }
6491 int activityDurationMs =
6492 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6493 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006494 int[] txTimeMs = info.getTransmitTimeMillis();
6495 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6496 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006497 }
6498 return (info.isValid()
6499 && (info.getSleepTimeMillis() <= activityDurationMs)
6500 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006501 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006502 && (totalTxTimeMs <= activityDurationMs));
6503 }
6504
Jack Yu85bd38a2015-11-09 11:34:32 -08006505 /**
6506 * {@hide}
6507 * Returns the service state information on specified subscription.
6508 */
6509 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006510 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6511 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006512 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006513 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006514 return null;
6515 }
6516
Hall Liuf19c44f2018-11-27 14:38:17 -08006517 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6518 LocationAccessPolicy.checkLocationPermission(mApp,
6519 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6520 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006521 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006522 .setCallingPid(Binder.getCallingPid())
6523 .setCallingUid(Binder.getCallingUid())
6524 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006525 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006526 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6527 .build());
6528
6529 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6530 LocationAccessPolicy.checkLocationPermission(mApp,
6531 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6532 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006533 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006534 .setCallingPid(Binder.getCallingPid())
6535 .setCallingUid(Binder.getCallingUid())
6536 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006537 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006538 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6539 .build());
6540 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6541 boolean hasFinePermission =
6542 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6543 boolean hasCoarsePermission =
6544 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6545
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006546 final long identity = Binder.clearCallingIdentity();
6547 try {
6548 final Phone phone = getPhone(subId);
6549 if (phone == null) {
6550 return null;
6551 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006552
Hall Liuf19c44f2018-11-27 14:38:17 -08006553 ServiceState ss = phone.getServiceState();
6554
6555 // Scrub out the location info in ServiceState depending on what level of access
6556 // the caller has.
6557 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006558 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6559 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006560 } finally {
6561 Binder.restoreCallingIdentity(identity);
6562 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006563 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006564
6565 /**
6566 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6567 *
6568 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6569 * voicemail ringtone.
6570 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6571 * PhoneAccount.
6572 */
6573 @Override
6574 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006575 final long identity = Binder.clearCallingIdentity();
6576 try {
6577 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6578 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006579 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006580 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006581
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006582 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6583 } finally {
6584 Binder.restoreCallingIdentity(identity);
6585 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006586 }
6587
6588 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006589 * Sets the per-account voicemail ringtone.
6590 *
6591 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6592 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6593 *
6594 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6595 * voicemail ringtone.
6596 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6597 * PhoneAccount.
6598 */
6599 @Override
6600 public void setVoicemailRingtoneUri(String callingPackage,
6601 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006602 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006603 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006604 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6605 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006606 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6607 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6608 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006609 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006610
6611 final long identity = Binder.clearCallingIdentity();
6612 try {
6613 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6614 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006615 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006616 }
6617 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6618 } finally {
6619 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006620 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006621 }
6622
6623 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006624 * Returns whether vibration is set for voicemail notification in Phone settings.
6625 *
6626 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6627 * voicemail vibration setting.
6628 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6629 */
6630 @Override
6631 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006632 final long identity = Binder.clearCallingIdentity();
6633 try {
6634 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6635 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006636 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006637 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006638
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006639 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6640 } finally {
6641 Binder.restoreCallingIdentity(identity);
6642 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006643 }
6644
Youhan Wange64578a2016-05-02 15:32:42 -07006645 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006646 * Sets the per-account voicemail vibration.
6647 *
6648 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6649 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6650 *
6651 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6652 * voicemail vibration setting.
6653 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6654 * specific PhoneAccount.
6655 */
6656 @Override
6657 public void setVoicemailVibrationEnabled(String callingPackage,
6658 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006659 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006660 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006661 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6662 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6664 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6665 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006666 }
6667
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006668 final long identity = Binder.clearCallingIdentity();
6669 try {
6670 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6671 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006672 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006673 }
6674 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6675 } finally {
6676 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006677 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006678 }
6679
6680 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006681 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6682 *
6683 * @throws SecurityException if the caller does not have the required permission
6684 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006685 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006686 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006687 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006688 }
6689
6690 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006691 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6692 * permission.
6693 *
6694 * @throws SecurityException if the caller does not have the required permission
6695 */
6696 private void enforceSendSmsPermission() {
6697 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6698 }
6699
6700 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006701 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006702 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006703 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006704 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006705 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006706 final long identity = Binder.clearCallingIdentity();
6707 try {
6708 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006709 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006710 if (componentName == null) {
6711 throw new SecurityException(
6712 "Caller not current active visual voicemail package[null]");
6713 }
6714 String vvmPackage = componentName.getPackageName();
6715 if (!callingPackage.equals(vvmPackage)) {
6716 throw new SecurityException("Caller not current active visual voicemail package["
6717 + vvmPackage + "]");
6718 }
6719 } finally {
6720 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006721 }
6722 }
6723
6724 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006725 * Return the application ID for the app type.
6726 *
6727 * @param subId the subscription ID that this request applies to.
6728 * @param appType the uicc app type.
6729 * @return Application ID for specificied app type, or null if no uicc.
6730 */
6731 @Override
6732 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006733 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006734 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006735
6736 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006737 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006738 if (phone == null) {
6739 return null;
6740 }
6741 String aid = null;
6742 try {
6743 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6744 .getApplicationByType(appType).getAid();
6745 } catch (Exception e) {
6746 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6747 }
6748 return aid;
6749 } finally {
6750 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006751 }
Youhan Wange64578a2016-05-02 15:32:42 -07006752 }
6753
Youhan Wang4001d252016-05-11 10:29:41 -07006754 /**
6755 * Return the Electronic Serial Number.
6756 *
6757 * @param subId the subscription ID that this request applies to.
6758 * @return ESN or null if error.
6759 */
6760 @Override
6761 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006762 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006763 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006764
6765 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006766 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006767 if (phone == null) {
6768 return null;
6769 }
6770 String esn = null;
6771 try {
6772 esn = phone.getEsn();
6773 } catch (Exception e) {
6774 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6775 }
6776 return esn;
6777 } finally {
6778 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006779 }
Youhan Wang4001d252016-05-11 10:29:41 -07006780 }
6781
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006782 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006783 * Return the Preferred Roaming List Version.
6784 *
6785 * @param subId the subscription ID that this request applies to.
6786 * @return PRLVersion or null if error.
6787 */
6788 @Override
6789 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006790 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006791 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006792
6793 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006794 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006795 if (phone == null) {
6796 return null;
6797 }
6798 String cdmaPrlVersion = null;
6799 try {
6800 cdmaPrlVersion = phone.getCdmaPrlVersion();
6801 } catch (Exception e) {
6802 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6803 }
6804 return cdmaPrlVersion;
6805 } finally {
6806 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006807 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006808 }
6809
6810 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006811 * Get snapshot of Telephony histograms
6812 * @return List of Telephony histograms
6813 * @hide
6814 */
6815 @Override
6816 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6818 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006819
6820 final long identity = Binder.clearCallingIdentity();
6821 try {
6822 return RIL.getTelephonyRILTimingHistograms();
6823 } finally {
6824 Binder.restoreCallingIdentity(identity);
6825 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006826 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006827
6828 /**
6829 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006830 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6831 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006832 * Require system privileges. In the future we may add this to carrier APIs.
6833 *
Michele Berionne482f8202018-11-27 18:57:59 -08006834 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006835 */
6836 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006837 @TelephonyManager.SetCarrierRestrictionResult
6838 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006839 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006840 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006841
Michele Berionne482f8202018-11-27 18:57:59 -08006842 if (carrierRestrictionRules == null) {
6843 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006844 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006845
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006846 final long identity = Binder.clearCallingIdentity();
6847 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006848 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006849 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006850 } finally {
6851 Binder.restoreCallingIdentity(identity);
6852 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006853 }
6854
6855 /**
6856 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006857 * Get the allowed carrier list and the excluded carrier list, including the priority between
6858 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006859 * Require system privileges. In the future we may add this to carrier APIs.
6860 *
Michele Berionne482f8202018-11-27 18:57:59 -08006861 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006862 */
6863 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006864 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006865 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006866 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006867
6868 final long identity = Binder.clearCallingIdentity();
6869 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006870 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6871 if (response instanceof CarrierRestrictionRules) {
6872 return (CarrierRestrictionRules) response;
6873 }
6874 // Response is an Exception of some kind,
6875 // which is signalled to the user as a NULL retval
6876 return null;
6877 } catch (Exception e) {
6878 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6879 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006880 } finally {
6881 Binder.restoreCallingIdentity(identity);
6882 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006883 }
6884
fionaxu59545b42016-05-25 15:53:37 -07006885 /**
6886 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6887 * @param subId the subscription ID that this action applies to.
6888 * @param enabled control enable or disable metered apns.
6889 * {@hide}
6890 */
6891 @Override
6892 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6893 enforceModifyPermission();
6894 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006895
6896 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006897 if (phone == null) {
6898 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6899 return;
6900 }
6901 try {
6902 phone.carrierActionSetMeteredApnsEnabled(enabled);
6903 } catch (Exception e) {
6904 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006905 } finally {
6906 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006907 }
6908 }
6909
6910 /**
6911 * Action set from carrier signalling broadcast receivers to enable/disable radio
6912 * @param subId the subscription ID that this action applies to.
6913 * @param enabled control enable or disable radio.
6914 * {@hide}
6915 */
6916 @Override
6917 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6918 enforceModifyPermission();
6919 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006920
6921 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006922 if (phone == null) {
6923 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6924 return;
6925 }
6926 try {
6927 phone.carrierActionSetRadioEnabled(enabled);
6928 } catch (Exception e) {
6929 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006930 } finally {
6931 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006932 }
6933 }
6934
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006935 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006936 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6937 * network status based on which carrier apps could apply actions accordingly,
6938 * enable/disable default url handler for example.
6939 *
6940 * @param subId the subscription ID that this action applies to.
6941 * @param report control start/stop reporting the default network status.
6942 * {@hide}
6943 */
6944 @Override
6945 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6946 enforceModifyPermission();
6947 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006948
6949 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006950 if (phone == null) {
6951 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6952 return;
6953 }
6954 try {
6955 phone.carrierActionReportDefaultNetworkStatus(report);
6956 } catch (Exception e) {
6957 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006958 } finally {
6959 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006960 }
6961 }
6962
6963 /**
fionaxud9622282017-07-17 17:51:30 -07006964 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6965 * @param subId the subscription ID that this action applies to.
6966 * {@hide}
6967 */
6968 @Override
6969 public void carrierActionResetAll(int subId) {
6970 enforceModifyPermission();
6971 final Phone phone = getPhone(subId);
6972 if (phone == null) {
6973 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6974 return;
6975 }
6976 try {
6977 phone.carrierActionResetAll();
6978 } catch (Exception e) {
6979 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6980 }
6981 }
6982
6983 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006984 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6985 * bug report is being generated.
6986 */
6987 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006988 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006989 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6990 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006991 writer.println("Permission Denial: can't dump Phone from pid="
6992 + Binder.getCallingPid()
6993 + ", uid=" + Binder.getCallingUid()
6994 + "without permission "
6995 + android.Manifest.permission.DUMP);
6996 return;
6997 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006998 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006999 }
Jack Yueb89b242016-06-22 13:27:47 -07007000
Brad Ebingerdac2f002018-04-03 15:17:52 -07007001 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007002 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7003 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7004 @NonNull String[] args) {
7005 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7006 this, in.getFileDescriptor(), out.getFileDescriptor(),
7007 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007008 }
7009
Jack Yueb89b242016-06-22 13:27:47 -07007010 /**
Jack Yu84291ec2017-05-26 16:07:50 -07007011 * Get aggregated video call data usage since boot.
7012 *
7013 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
7014 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07007015 * {@hide}
7016 */
7017 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07007018 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07007019 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
7020 null);
7021
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007022 final long identity = Binder.clearCallingIdentity();
7023 try {
7024 // NetworkStatsService keeps tracking the active network interface and identity. It
7025 // records the delta with the corresponding network identity.
7026 // We just return the total video call data usage snapshot since boot.
7027 Phone phone = getPhone(subId);
7028 if (phone != null) {
7029 return phone.getVtDataUsage(perUidStats);
7030 }
7031 return null;
7032 } finally {
7033 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07007034 }
Jack Yueb89b242016-06-22 13:27:47 -07007035 }
Jack Yu75ab2952016-07-08 14:29:33 -07007036
7037 /**
7038 * Policy control of data connection. Usually used when data limit is passed.
7039 * @param enabled True if enabling the data, otherwise disabling.
7040 * @param subId Subscription index
7041 * {@hide}
7042 */
7043 @Override
7044 public void setPolicyDataEnabled(boolean enabled, int subId) {
7045 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007046
7047 final long identity = Binder.clearCallingIdentity();
7048 try {
7049 Phone phone = getPhone(subId);
7050 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007051 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007052 }
7053 } finally {
7054 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007055 }
7056 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007057
7058 /**
7059 * Get Client request stats
7060 * @return List of Client Request Stats
7061 * @hide
7062 */
7063 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007064 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7065 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007066 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007067 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007068 return null;
7069 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007070 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007071
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007072 final long identity = Binder.clearCallingIdentity();
7073 try {
7074 if (phone != null) {
7075 return phone.getClientRequestStats();
7076 }
7077
7078 return null;
7079 } finally {
7080 Binder.restoreCallingIdentity(identity);
7081 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007082 }
7083
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007084 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007085 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007086 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007087 }
Jack Yueb4124c2017-02-16 15:32:43 -08007088
7089 /**
Grace Chen70990072017-03-24 17:21:30 -07007090 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007091 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007092 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007093 * @param state State of SIM (power down, power up, pass through)
7094 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7095 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7096 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007097 *
7098 **/
7099 @Override
Grace Chen70990072017-03-24 17:21:30 -07007100 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007101 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007102 Phone phone = PhoneFactory.getPhone(slotIndex);
7103
vagdeviaf9a5b92018-08-15 16:01:53 -07007104 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7105
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007106 final long identity = Binder.clearCallingIdentity();
7107 try {
7108 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007109 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007110 }
7111 } finally {
7112 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007113 }
7114 }
Shuo Qiandd210312017-04-12 22:11:33 +00007115
Tyler Gunn65d45c22017-06-05 11:22:26 -07007116 private boolean isUssdApiAllowed(int subId) {
7117 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007118 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007119 if (configManager == null) {
7120 return false;
7121 }
7122 PersistableBundle pb = configManager.getConfigForSubId(subId);
7123 if (pb == null) {
7124 return false;
7125 }
7126 return pb.getBoolean(
7127 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7128 }
7129
Shuo Qiandd210312017-04-12 22:11:33 +00007130 /**
7131 * Check if phone is in emergency callback mode
7132 * @return true if phone is in emergency callback mode
7133 * @param subId sub id
7134 */
goneil9c5f4872017-12-05 14:07:56 -08007135 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007136 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007137 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007138 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007139
7140 final long identity = Binder.clearCallingIdentity();
7141 try {
7142 if (phone != null) {
7143 return phone.isInEcm();
7144 } else {
7145 return false;
7146 }
7147 } finally {
7148 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007149 }
7150 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007151
7152 /**
7153 * Get the current signal strength information for the given subscription.
7154 * Because this information is not updated when the device is in a low power state
7155 * it should not be relied-upon to be current.
7156 * @param subId Subscription index
7157 * @return the most recent cached signal strength info from the modem
7158 */
7159 @Override
7160 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007161 final long identity = Binder.clearCallingIdentity();
7162 try {
7163 Phone p = getPhone(subId);
7164 if (p == null) {
7165 return null;
7166 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007167
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007168 return p.getSignalStrength();
7169 } finally {
7170 Binder.restoreCallingIdentity(identity);
7171 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007172 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007173
Pengquan Meng77b7f132018-08-22 14:49:57 -07007174 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007175 * Get the current modem radio state for the given slot.
7176 * @param slotIndex slot index.
7177 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007178 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007179 * @return the current radio power state from the modem
7180 */
7181 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007182 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007183 Phone phone = PhoneFactory.getPhone(slotIndex);
7184 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007185 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7186 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007187 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7188 }
7189
7190 final long identity = Binder.clearCallingIdentity();
7191 try {
7192 return phone.getRadioPowerState();
7193 } finally {
7194 Binder.restoreCallingIdentity(identity);
7195 }
7196 }
7197 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7198 }
7199
7200 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007201 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7202 *
7203 * <p>Requires one of the following permissions:
7204 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7205 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7206 * privileges.
7207 *
7208 * @param subId subscription id
7209 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7210 * {@code false}.
7211 */
7212 @Override
7213 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007214 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7215 null /* message */);
7216
Pengquan Menga1bb6272018-09-06 09:59:22 -07007217 boolean isEnabled = false;
7218 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007219 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007220 Phone phone = getPhone(subId);
7221 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007222 } catch (Exception e) {
7223 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7224 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007225 } finally {
7226 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007227 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007228 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007229 }
7230
7231
7232 /**
7233 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7234 *
7235 * <p> Requires permission:
7236 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7237 * privileges.
7238 *
7239 * @param subId subscription id
7240 * @param isEnabled {@code true} means enable, {@code false} means disable.
7241 */
7242 @Override
7243 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007244 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7245 mApp, subId, "setDataRoamingEnabled");
7246
Pengquan Menga1bb6272018-09-06 09:59:22 -07007247 final long identity = Binder.clearCallingIdentity();
7248 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007249 Phone phone = getPhone(subId);
7250 if (phone != null) {
7251 phone.setDataRoamingEnabled(isEnabled);
7252 }
7253 } finally {
7254 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007255 }
7256 }
7257
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007258 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007259 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007260 TelephonyPermissions
7261 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007262 mApp, subId, "isManualNetworkSelectionAllowed");
7263
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007264 boolean isAllowed = true;
7265 final long identity = Binder.clearCallingIdentity();
7266 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007267 Phone phone = getPhone(subId);
7268 if (phone != null) {
7269 isAllowed = phone.isCspPlmnEnabled();
7270 }
7271 } finally {
7272 Binder.restoreCallingIdentity(identity);
7273 }
7274 return isAllowed;
7275 }
7276
7277 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007278 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007279 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007280 try {
7281 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007282 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007283 } catch (SecurityException e) {
7284 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7285 // has carrier privileges on an active UICC
7286 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7287 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007288 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007289 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007290 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007291
7292 final long identity = Binder.clearCallingIdentity();
7293 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007294 UiccController uiccController = UiccController.getInstance();
7295 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007296 if (hasReadPermission) {
7297 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007298 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007299
7300 // Remove private info if the caller doesn't have access
7301 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7302 for (UiccCardInfo cardInfo : cardInfos) {
7303 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7304 // is available
7305 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7306 if (card == null || card.getUiccProfile() == null) {
7307 // assume no access if the card or profile is unavailable
7308 filteredInfos.add(cardInfo.getUnprivileged());
7309 continue;
7310 }
7311 UiccProfile profile = card.getUiccProfile();
7312 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7313 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7314 filteredInfos.add(cardInfo);
7315 } else {
7316 filteredInfos.add(cardInfo.getUnprivileged());
7317 }
7318 }
7319 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007320 } finally {
7321 Binder.restoreCallingIdentity(identity);
7322 }
7323 }
7324
7325 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007326 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007327 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007328
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007329 final long identity = Binder.clearCallingIdentity();
7330 try {
7331 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7332 if (slots == null) {
7333 Rlog.i(LOG_TAG, "slots is null.");
7334 return null;
7335 }
7336
7337 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7338 for (int i = 0; i < slots.length; i++) {
7339 UiccSlot slot = slots[i];
7340 if (slot == null) {
7341 continue;
7342 }
7343
Jordan Liu7be7e652019-05-06 18:55:02 +00007344 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007345 UiccCard card = slot.getUiccCard();
7346 if (card != null) {
7347 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007348 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007349 cardId = slot.getEid();
7350 if (TextUtils.isEmpty(cardId)) {
7351 cardId = slot.getIccId();
7352 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007353 }
7354
Jordan Liu857451f2019-05-09 16:35:35 -07007355 if (cardId != null) {
7356 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7357 // if cardId is an EID, it's all digits so this is fine
7358 cardId = IccUtils.stripTrailingFs(cardId);
7359 }
7360
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007361 int cardState = 0;
7362 switch (slot.getCardState()) {
7363 case CARDSTATE_ABSENT:
7364 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7365 break;
7366 case CARDSTATE_PRESENT:
7367 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7368 break;
7369 case CARDSTATE_ERROR:
7370 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7371 break;
7372 case CARDSTATE_RESTRICTED:
7373 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7374 break;
7375 default:
7376 break;
7377
7378 }
7379
7380 infos[i] = new UiccSlotInfo(
7381 slot.isActive(),
7382 slot.isEuicc(),
7383 cardId,
7384 cardState,
7385 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007386 slot.isExtendedApduSupported(),
7387 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007388 }
7389 return infos;
7390 } finally {
7391 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007392 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007393 }
7394
7395 @Override
7396 public boolean switchSlots(int[] physicalSlots) {
7397 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007398
7399 final long identity = Binder.clearCallingIdentity();
7400 try {
7401 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7402 } finally {
7403 Binder.restoreCallingIdentity(identity);
7404 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007405 }
Jack Yu4c988042018-02-27 15:30:01 -08007406
7407 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007408 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007409 final long identity = Binder.clearCallingIdentity();
7410 try {
7411 return UiccController.getInstance().getCardIdForDefaultEuicc();
7412 } finally {
7413 Binder.restoreCallingIdentity(identity);
7414 }
7415 }
7416
7417 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007418 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7419 enforceModifyPermission();
7420 final Phone phone = getPhone(subId);
7421 if (phone == null) {
7422 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7423 return;
7424 }
7425
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007426 final long identity = Binder.clearCallingIdentity();
7427 try {
7428 phone.setRadioIndicationUpdateMode(filters, mode);
7429 } finally {
7430 Binder.restoreCallingIdentity(identity);
7431 }
Jack Yu4c988042018-02-27 15:30:01 -08007432 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007433
7434 /**
goneil47ffb6e2018-04-06 15:40:58 -07007435 * A test API to reload the UICC profile.
7436 *
7437 * <p>Requires that the calling app has permission
7438 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7439 * @hide
7440 */
7441 @Override
7442 public void refreshUiccProfile(int subId) {
7443 enforceModifyPermission();
7444
7445 final long identity = Binder.clearCallingIdentity();
7446 try {
7447 Phone phone = getPhone(subId);
7448 if (phone == null) {
7449 return;
7450 }
7451 UiccCard uiccCard = phone.getUiccCard();
7452 if (uiccCard == null) {
7453 return;
7454 }
7455 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7456 if (uiccProfile == null) {
7457 return;
7458 }
7459 uiccProfile.refresh();
7460 } finally {
7461 Binder.restoreCallingIdentity(identity);
7462 }
7463 }
7464
7465 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007466 * Returns false if the mobile data is disabled by default, otherwise return true.
7467 */
7468 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007469 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007470 }
7471
7472 /**
7473 * Returns true if the data roaming is enabled by default, i.e the system property
7474 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7475 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7476 */
7477 private boolean getDefaultDataRoamingEnabled(int subId) {
7478 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007479 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007480 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007481 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7482 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7483 return isDataRoamingEnabled;
7484 }
7485
7486 /**
7487 * Returns the default network type for the given {@code subId}, if the default network type is
7488 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7489 */
7490 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007491 List<Integer> list = TelephonyProperties.default_network();
7492 int phoneId = mSubscriptionController.getPhoneId(subId);
7493 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7494 return list.get(phoneId);
7495 }
7496 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007497 }
fionaxua13278b2018-03-21 00:08:13 -07007498
7499 @Override
7500 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007501 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007502 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007503
7504 final long identity = Binder.clearCallingIdentity();
7505 try {
7506 final Phone phone = getPhone(subId);
7507 if (phone == null) {
7508 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7509 return;
7510 }
chen xueaba88a2019-03-15 13:15:10 -07007511 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7512 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007513 } finally {
7514 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007515 }
fionaxua13278b2018-03-21 00:08:13 -07007516 }
7517
7518 @Override
7519 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007520 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007521
7522 final long identity = Binder.clearCallingIdentity();
7523 try {
7524 final Phone phone = getPhone(subId);
7525 if (phone == null) {
7526 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7527 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7528 }
7529 return phone.getCarrierIdListVersion();
7530 } finally {
7531 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007532 }
fionaxua13278b2018-03-21 00:08:13 -07007533 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007534
7535 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007536 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7537 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007538 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007539 mApp, subId, callingPackage, callingFeatureId,
7540 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007541 return -1;
7542 }
7543
7544 final long identity = Binder.clearCallingIdentity();
7545 try {
7546 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7547 } finally {
7548 Binder.restoreCallingIdentity(identity);
7549 }
7550 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007551
7552 @Override
7553 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007554 TelephonyPermissions
7555 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007556 mApp, subId, "getCdmaRoamingMode");
7557
7558 final long identity = Binder.clearCallingIdentity();
7559 try {
7560 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7561 } finally {
7562 Binder.restoreCallingIdentity(identity);
7563 }
7564 }
7565
7566 @Override
7567 public boolean setCdmaRoamingMode(int subId, int mode) {
7568 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7569 mApp, subId, "setCdmaRoamingMode");
7570
7571 final long identity = Binder.clearCallingIdentity();
7572 try {
7573 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7574 } finally {
7575 Binder.restoreCallingIdentity(identity);
7576 }
7577 }
7578
7579 @Override
7580 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7581 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7582 mApp, subId, "setCdmaSubscriptionMode");
7583
7584 final long identity = Binder.clearCallingIdentity();
7585 try {
7586 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7587 } finally {
7588 Binder.restoreCallingIdentity(identity);
7589 }
7590 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007591
sqianc5eccab2018-10-19 18:46:41 -07007592 @Override
sqian8c685422019-02-22 15:55:18 -08007593 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007594 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007595 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007596 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7597 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007598 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7599 }
7600 final long identity = Binder.clearCallingIdentity();
7601 try {
sqian854d44b2018-12-12 16:48:18 -08007602 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7603 for (Phone phone: PhoneFactory.getPhones()) {
7604 if (phone.getEmergencyNumberTracker() != null
7605 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7606 emergencyNumberListInternal.put(
7607 phone.getSubId(),
7608 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7609 }
sqian11b7a0e2018-12-05 18:48:28 -08007610 }
sqian854d44b2018-12-12 16:48:18 -08007611 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007612 } finally {
7613 Binder.restoreCallingIdentity(identity);
7614 }
sqianc5eccab2018-10-19 18:46:41 -07007615 }
7616
7617 @Override
sqian8c685422019-02-22 15:55:18 -08007618 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007619 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007620 if (!exactMatch) {
7621 TelephonyPermissions
7622 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007623 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007624 }
7625 final long identity = Binder.clearCallingIdentity();
7626 try {
sqian854d44b2018-12-12 16:48:18 -08007627 for (Phone phone: PhoneFactory.getPhones()) {
7628 if (phone.getEmergencyNumberTracker() != null
7629 && phone.getEmergencyNumberTracker() != null) {
7630 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7631 number, exactMatch)) {
7632 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007633 }
7634 }
sqian11b7a0e2018-12-05 18:48:28 -08007635 }
7636 return false;
7637 } finally {
7638 Binder.restoreCallingIdentity(identity);
7639 }
7640 }
7641
sqianf4ca7ed2019-01-15 18:32:07 -08007642 /**
7643 * Update emergency number list for test mode.
7644 */
7645 @Override
7646 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7647 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7648 "updateEmergencyNumberListTestMode");
7649
7650 final long identity = Binder.clearCallingIdentity();
7651 try {
7652 for (Phone phone: PhoneFactory.getPhones()) {
7653 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7654 if (tracker != null) {
7655 tracker.executeEmergencyNumberTestModeCommand(action, num);
7656 }
7657 }
7658 } finally {
7659 Binder.restoreCallingIdentity(identity);
7660 }
7661 }
7662
7663 /**
7664 * Get the full emergency number list for test mode.
7665 */
7666 @Override
7667 public List<String> getEmergencyNumberListTestMode() {
7668 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7669 "getEmergencyNumberListTestMode");
7670
7671 final long identity = Binder.clearCallingIdentity();
7672 try {
7673 Set<String> emergencyNumbers = new HashSet<>();
7674 for (Phone phone: PhoneFactory.getPhones()) {
7675 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7676 if (tracker != null) {
7677 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7678 emergencyNumbers.add(num.getNumber());
7679 }
7680 }
7681 }
7682 return new ArrayList<>(emergencyNumbers);
7683 } finally {
7684 Binder.restoreCallingIdentity(identity);
7685 }
7686 }
7687
chen xud6b45bd2018-10-30 22:27:10 -07007688 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007689 public int getEmergencyNumberDbVersion(int subId) {
7690 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7691
7692 final long identity = Binder.clearCallingIdentity();
7693 try {
7694 final Phone phone = getPhone(subId);
7695 if (phone == null) {
7696 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7697 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7698 }
7699 return phone.getEmergencyNumberDbVersion();
7700 } finally {
7701 Binder.restoreCallingIdentity(identity);
7702 }
7703 }
7704
7705 @Override
7706 public void notifyOtaEmergencyNumberDbInstalled() {
7707 enforceModifyPermission();
7708
7709 final long identity = Binder.clearCallingIdentity();
7710 try {
7711 for (Phone phone: PhoneFactory.getPhones()) {
7712 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7713 if (tracker != null) {
7714 tracker.updateOtaEmergencyNumberDatabase();
7715 }
7716 }
7717 } finally {
7718 Binder.restoreCallingIdentity(identity);
7719 }
7720 }
7721
7722 @Override
7723 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7724 enforceActiveEmergencySessionPermission();
7725
7726 final long identity = Binder.clearCallingIdentity();
7727 try {
7728 for (Phone phone: PhoneFactory.getPhones()) {
7729 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7730 if (tracker != null) {
7731 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7732 }
7733 }
7734 } finally {
7735 Binder.restoreCallingIdentity(identity);
7736 }
7737 }
7738
7739 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007740 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7741 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7742 Phone phone = getPhone(subId);
7743 if (phone == null) {
7744 return null;
7745 }
7746 final long identity = Binder.clearCallingIdentity();
7747 try {
7748 UiccProfile profile = UiccController.getInstance()
7749 .getUiccProfileForPhone(phone.getPhoneId());
7750 if (profile != null) {
7751 return profile.getCertsFromCarrierPrivilegeAccessRules();
7752 }
7753 } finally {
7754 Binder.restoreCallingIdentity(identity);
7755 }
7756 return null;
7757 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007758
7759 /**
7760 * Enable or disable a modem stack.
7761 */
7762 @Override
7763 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7764 enforceModifyPermission();
7765
7766 final long identity = Binder.clearCallingIdentity();
7767 try {
7768 Phone phone = PhoneFactory.getPhone(slotIndex);
7769 if (phone == null) {
7770 return false;
7771 } else {
7772 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7773 }
7774 } finally {
7775 Binder.restoreCallingIdentity(identity);
7776 }
7777 }
Michelecea4cf22018-12-21 15:00:11 -08007778
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007779 /**
7780 * Whether a modem stack is enabled or not.
7781 */
7782 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007783 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7784 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007785 Phone phone = PhoneFactory.getPhone(slotIndex);
7786 if (phone == null) return false;
7787
7788 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007789 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7790 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007791 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7792 }
7793
7794 final long identity = Binder.clearCallingIdentity();
7795 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007796 try {
7797 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7798 } catch (NoSuchElementException ex) {
7799 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7800 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007801 } finally {
7802 Binder.restoreCallingIdentity(identity);
7803 }
7804 }
7805
Michelecea4cf22018-12-21 15:00:11 -08007806 @Override
Michele0ea7d782019-03-19 14:58:42 -07007807 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007808 enforceModifyPermission();
7809
7810 final long identity = Binder.clearCallingIdentity();
7811 try {
7812 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007813 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007814 .commit();
7815 } finally {
7816 Binder.restoreCallingIdentity(identity);
7817 }
7818 }
7819
7820 @Override
Michele0ea7d782019-03-19 14:58:42 -07007821 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007822 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007823 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007824 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7825 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007826 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007827 }
Michelecea4cf22018-12-21 15:00:11 -08007828
7829 final long identity = Binder.clearCallingIdentity();
7830 try {
Michele0ea7d782019-03-19 14:58:42 -07007831 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007832 } finally {
7833 Binder.restoreCallingIdentity(identity);
7834 }
7835 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007836
Michele0ea7d782019-03-19 14:58:42 -07007837 @TelephonyManager.IsMultiSimSupportedResult
7838 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007839 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7840 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7841 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007842 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7843 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007844 }
7845 // Check if the hardware supports multisim functionality. If usage of multisim is not
7846 // supported by the modem, indicate that it is restricted.
7847 PhoneCapability staticCapability =
7848 mPhoneConfigurationManager.getStaticPhoneCapability();
7849 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007850 loge("isMultiSimSupportedInternal: no static configuration available");
7851 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007852 }
Sarah Chin0605abf2019-12-06 10:24:18 -08007853 if (staticCapability.getLogicalModemUuids().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007854 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7855 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007856 }
7857 // Check if support of multiple SIMs is restricted by carrier
7858 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007859 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007860 }
7861
Michele0ea7d782019-03-19 14:58:42 -07007862 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007863 }
7864
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007865 /**
7866 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007867 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7868 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7869 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007870 * @param numOfSims number of active sims we want to switch to
7871 */
7872 @Override
7873 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007874 if (numOfSims == 1) {
7875 enforceModifyPermission();
7876 } else {
7877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7878 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7879 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007880 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007881
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007882 try {
Michele30b57b22019-03-01 12:01:14 -08007883 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007884 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007885 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7886 return;
7887 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007888 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7889 } finally {
7890 Binder.restoreCallingIdentity(identity);
7891 }
7892 }
7893
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007894 @Override
7895 public boolean isApplicationOnUicc(int subId, int appType) {
7896 enforceReadPrivilegedPermission("isApplicationOnUicc");
7897 Phone phone = getPhone(subId);
7898 if (phone == null) {
7899 return false;
7900 }
7901 final long identity = Binder.clearCallingIdentity();
7902 try {
7903 UiccCard uiccCard = phone.getUiccCard();
7904 if (uiccCard == null) {
7905 return false;
7906 }
7907 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7908 if (uiccProfile == null) {
7909 return false;
7910 }
7911 if (TelephonyManager.APPTYPE_SIM <= appType
7912 && appType <= TelephonyManager.APPTYPE_ISIM) {
7913 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7914 }
7915 return false;
7916 } finally {
7917 Binder.restoreCallingIdentity(identity);
7918 }
7919 }
7920
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007921 /**
chen xub4baa772019-04-03 10:23:41 -07007922 * Get whether making changes to modem configurations will trigger reboot.
7923 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007924 */
7925 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007926 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7927 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007928 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007929 mApp, subId, callingPackage, callingFeatureId,
7930 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007931 return false;
7932 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007933 final long identity = Binder.clearCallingIdentity();
7934 try {
7935 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7936 } finally {
7937 Binder.restoreCallingIdentity(identity);
7938 }
7939 }
7940
Nathan Harold29f5f052019-02-15 13:41:57 -08007941 private void updateModemStateMetrics() {
7942 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7943 // TODO: check the state for each modem if the api is ready.
7944 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7945 }
7946
Pengquan Meng3889a572019-01-23 11:16:29 -08007947 @Override
7948 public int[] getSlotsMapping() {
7949 enforceReadPrivilegedPermission("getSlotsMapping");
7950
7951 final long identity = Binder.clearCallingIdentity();
7952 try {
7953 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7954 // All logical slots should have a mapping to a physical slot.
7955 int[] logicalSlotsMapping = new int[phoneCount];
7956 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7957 for (int i = 0; i < slotInfos.length; i++) {
7958 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7959 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7960 }
7961 }
7962 return logicalSlotsMapping;
7963 } finally {
7964 Binder.restoreCallingIdentity(identity);
7965 }
7966 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007967
7968 /**
7969 * Get the IRadio HAL Version
7970 */
7971 @Override
7972 public int getRadioHalVersion() {
7973 Phone phone = getDefaultPhone();
7974 if (phone == null) return -1;
7975 HalVersion hv = phone.getHalVersion();
7976 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7977 return hv.major * 100 + hv.minor;
7978 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007979
7980 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08007981 * Get the current calling package name.
7982 * @return the current calling package name
7983 */
7984 @Override
7985 public String getCurrentPackageName() {
7986 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
7987 }
7988
7989 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007990 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7991 * corresponding network requests on a subId.
7992 *
7993 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007994 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007995 * 2) APN is un-metered for this subscription, or
7996 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08007997 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07007998 *
7999 * @return whether data is allowed for a apn type.
8000 *
8001 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008002 */
8003 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008004 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008005 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8006 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008007
8008 // Now that all security checks passes, perform the operation as ourselves.
8009 final long identity = Binder.clearCallingIdentity();
8010 try {
8011 Phone phone = getPhone(subId);
8012 if (phone == null) return false;
8013
Jack Yu41407ee2019-05-13 16:54:09 -07008014 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008015 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8016 } finally {
8017 Binder.restoreCallingIdentity(identity);
8018 }
8019 }
8020
8021 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008022 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008023 enforceReadPrivilegedPermission("isApnMetered");
8024
8025 // Now that all security checks passes, perform the operation as ourselves.
8026 final long identity = Binder.clearCallingIdentity();
8027 try {
8028 Phone phone = getPhone(subId);
8029 if (phone == null) return true; // By default return true.
8030
Jack Yu41407ee2019-05-13 16:54:09 -07008031 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008032 } finally {
8033 Binder.restoreCallingIdentity(identity);
8034 }
8035 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008036
8037 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008038 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8039 int subscriptionId, IBooleanConsumer resultCallback) {
8040 enforceModifyPermission();
8041 long token = Binder.clearCallingIdentity();
8042 try {
8043 Phone phone = getPhone(subscriptionId);
8044 if (phone == null) {
8045 try {
8046 if (resultCallback != null) {
8047 resultCallback.accept(false);
8048 }
8049 } catch (RemoteException e) {
8050 // ignore
8051 }
8052 return;
8053 }
8054 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8055 Pair.create(specifiers, (x) -> {
8056 try {
8057 if (resultCallback != null) {
8058 resultCallback.accept(x);
8059 }
8060 } catch (RemoteException e) {
8061 // ignore
8062 }
8063 });
8064 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8065 } finally {
8066 Binder.restoreCallingIdentity(token);
8067 }
8068 }
8069
8070 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008071 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8072 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8073 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8074 if (iccRecords == null) {
8075 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8076 return false;
8077 }
8078 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8079 }
8080
8081 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07008082 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008083 if (callingPackage == null) {
8084 callingPackage = getCurrentPackageName();
8085 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008086 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8087 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
8088 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
8089 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8090 }
8091 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8092 Intent intent = new Intent();
8093 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8094 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8095 // Bring up choose default SMS subscription dialog right now
8096 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8097 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8098 mApp.startActivity(intent);
8099 }
chen xud5ca2d52019-05-28 15:20:57 -07008100
8101 @Override
8102 public String getMmsUAProfUrl(int subId) {
8103 //TODO investigate if this API should require proper permission check in R b/133791609
8104 final long identity = Binder.clearCallingIdentity();
8105 try {
8106 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8107 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8108 } finally {
8109 Binder.restoreCallingIdentity(identity);
8110 }
8111 }
8112
8113 @Override
8114 public String getMmsUserAgent(int subId) {
8115 //TODO investigate if this API should require proper permission check in R b/133791609
8116 final long identity = Binder.clearCallingIdentity();
8117 try {
8118 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8119 .getString(com.android.internal.R.string.config_mms_user_agent);
8120 } finally {
8121 Binder.restoreCallingIdentity(identity);
8122 }
8123 }
Jack Yub07d4972019-05-28 16:12:25 -07008124
8125 @Override
8126 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8127 enforceModifyPermission();
8128
8129 // Now that all security checks passes, perform the operation as ourselves.
8130 final long identity = Binder.clearCallingIdentity();
8131 try {
8132 Phone phone = getPhone(subId);
8133 if (phone == null) return false;
8134
8135 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8136 } finally {
8137 Binder.restoreCallingIdentity(identity);
8138 }
8139 }
8140
8141 @Override
8142 public boolean isDataAllowedInVoiceCall(int subId) {
8143 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8144
8145 // Now that all security checks passes, perform the operation as ourselves.
8146 final long identity = Binder.clearCallingIdentity();
8147 try {
8148 Phone phone = getPhone(subId);
8149 if (phone == null) return false;
8150
8151 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8152 } finally {
8153 Binder.restoreCallingIdentity(identity);
8154 }
8155 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008156
changbettyd5c246e2019-12-24 15:40:37 +08008157 @Override
8158 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8159 enforceModifyPermission();
8160
8161 // Now that all security checks passes, perform the operation as ourselves.
8162 final long identity = Binder.clearCallingIdentity();
8163 try {
8164 Phone phone = getPhone(subId);
8165 if (phone == null) return false;
8166
8167 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8168 } finally {
8169 Binder.restoreCallingIdentity(identity);
8170 }
8171 }
8172
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008173 /**
8174 * Updates whether conference event pacakge handling is enabled.
8175 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8176 * otherwise.
8177 */
8178 @Override
8179 public void setCepEnabled(boolean isCepEnabled) {
8180 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8181
8182 final long identity = Binder.clearCallingIdentity();
8183 try {
8184 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8185 for (Phone phone : PhoneFactory.getPhones()) {
8186 Phone defaultPhone = phone.getImsPhone();
8187 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8188 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8189 ImsPhoneCallTracker imsPhoneCallTracker =
8190 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8191 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8192 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8193 + imsPhone.getMsisdn());
8194 }
8195 }
8196 } finally {
8197 Binder.restoreCallingIdentity(identity);
8198 }
8199 }
allenwtsu46dcc572020-01-08 18:24:03 +08008200
8201 /**
8202 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8203 *
8204 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8205 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8206 * before being read.
8207 */
8208 @Override
8209 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8210 isCompressed) {
8211 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8212 mApp, subId, "notifyRcsAutoConfigurationReceived");
8213 try {
8214 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8215 if (configBinder == null) {
8216 Rlog.e(LOG_TAG, "null result for getImsConfig");
8217 } else {
8218 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8219 }
8220 } catch (RemoteException e) {
8221 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8222 }
8223 }
zoey chene02881a2019-12-30 16:11:23 +08008224
8225 @Override
8226 public boolean isIccLockEnabled(int subId) {
8227 enforceReadPrivilegedPermission("isIccLockEnabled");
8228
8229 // Now that all security checks passes, perform the operation as ourselves.
8230 final long identity = Binder.clearCallingIdentity();
8231 try {
8232 Phone phone = getPhone(subId);
8233 if (phone != null && phone.getIccCard() != null) {
8234 return phone.getIccCard().getIccLockEnabled();
8235 } else {
8236 return false;
8237 }
8238 } finally {
8239 Binder.restoreCallingIdentity(identity);
8240 }
8241 }
8242
8243 /**
8244 * Set the ICC pin lock enabled or disabled.
8245 *
8246 * @return an integer representing the status of IccLock enabled or disabled in the following
8247 * three cases:
8248 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8249 * successfully.
8250 * - Positive number and zero for remaining password attempts.
8251 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8252 *
8253 */
8254 @Override
8255 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8256 enforceModifyPermission();
8257
8258 Phone phone = getPhone(subId);
8259 if (phone == null) {
8260 return 0;
8261 }
8262 // Now that all security checks passes, perform the operation as ourselves.
8263 final long identity = Binder.clearCallingIdentity();
8264 try {
8265 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8266 new Pair<Boolean, String>(enabled, password), phone, null);
8267 return attemptsRemaining;
8268
8269 } catch (Exception e) {
8270 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8271 } finally {
8272 Binder.restoreCallingIdentity(identity);
8273 }
8274 return 0;
8275 }
8276
8277 /**
8278 * Change the ICC password used in ICC pin lock.
8279 *
8280 * @return an integer representing the status of IccLock changed in the following three cases:
8281 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8282 * - Positive number and zero for remaining password attempts.
8283 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8284 *
8285 */
8286 @Override
8287 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8288 enforceModifyPermission();
8289
8290 Phone phone = getPhone(subId);
8291 if (phone == null) {
8292 return 0;
8293 }
8294 // Now that all security checks passes, perform the operation as ourselves.
8295 final long identity = Binder.clearCallingIdentity();
8296 try {
8297 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8298 new Pair<String, String>(oldPassword, newPassword), phone, null);
8299 return attemptsRemaining;
8300
8301 } catch (Exception e) {
8302 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8303 } finally {
8304 Binder.restoreCallingIdentity(identity);
8305 }
8306 return 0;
8307 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008308
8309 /**
8310 * Request for receiving user activity notification
8311 */
8312 @Override
8313 public void requestUserActivityNotification() {
8314 if (!mNotifyUserActivity.get()
8315 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8316 mNotifyUserActivity.set(true);
8317 }
8318 }
8319
8320 /**
8321 * Called when userActivity is signalled in the power manager.
8322 * This is safe to call from any thread, with any window manager locks held or not.
8323 */
8324 @Override
8325 public void userActivity() {
8326 // ***************************************
8327 // * Inherited from PhoneWindowManager *
8328 // ***************************************
8329 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8330 // WITH ITS LOCKS HELD.
8331 //
8332 // This code must be VERY careful about the locks
8333 // it acquires.
8334 // In fact, the current code acquires way too many,
8335 // and probably has lurking deadlocks.
8336
8337 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8338 throw new SecurityException("Only the OS may call notifyUserActivity()");
8339 }
8340
8341 if (mNotifyUserActivity.getAndSet(false)) {
8342 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8343 USER_ACTIVITY_NOTIFICATION_DELAY);
8344 }
8345 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008346}