blob: 01113a0430eb13fcd697fa3f56b60e499cd98cea [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();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001482 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001483
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001484 publish();
1485 }
1486
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001487 private Phone getDefaultPhone() {
1488 Phone thePhone = getPhone(getDefaultSubscription());
1489 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1490 }
1491
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001492 private void publish() {
1493 if (DBG) log("publish: " + this);
1494
Peter Wangc035ce42020-01-08 21:00:22 -08001495 TelephonyFrameworkInitializer
1496 .getTelephonyServiceManager()
1497 .getTelephonyServiceRegisterer()
1498 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001499 }
1500
Stuart Scott584921c2015-01-15 17:10:34 -08001501 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001502 if (request.phone != null) {
1503 return request.phone;
1504 } else {
1505 return getPhoneFromSubId(request.subId);
1506 }
1507 }
1508
1509 private Phone getPhoneFromSubId(int subId) {
1510 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1511 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001512 }
1513
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001514 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1515 Phone phone = getPhoneFromRequest(request);
1516 return phone == null ? null :
1517 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1518 }
1519
Wink Saville36469e72014-06-11 15:17:00 -07001520 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001521 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001522 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001523 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001524
Naina Nallurid63128d2019-09-17 14:10:30 -07001525 private void sendEraseModemConfig(Phone phone) {
1526 if (phone != null) {
1527 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1528 mApp, phone.getSubId(), "eraseModemConfig");
1529 final long identity = Binder.clearCallingIdentity();
1530 try {
1531 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1532 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1533 } finally {
1534 Binder.restoreCallingIdentity(identity);
1535 }
1536 }
1537 }
1538
Peter Wang44b186e2020-01-13 23:33:09 -08001539 private boolean isImsAvailableOnDevice() {
1540 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1541 if (pm == null) {
1542 // For some reason package manger is not available.. This will fail internally anyway,
1543 // so do not throw error and allow.
1544 return true;
1545 }
1546 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1547 }
1548
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001549 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001550 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001551 }
1552
Wink Savilleb564aae2014-10-23 10:18:09 -07001553 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 if (DBG) log("dial: " + number);
1555 // No permission check needed here: This is just a wrapper around the
1556 // ACTION_DIAL intent, which is available to any app since it puts up
1557 // the UI before it does anything.
1558
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001559 final long identity = Binder.clearCallingIdentity();
1560 try {
1561 String url = createTelUrl(number);
1562 if (url == null) {
1563 return;
1564 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001565
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001566 // PENDING: should we just silently fail if phone is offhook or ringing?
1567 PhoneConstants.State state = mCM.getState(subId);
1568 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1569 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1570 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1571 mApp.startActivity(intent);
1572 }
1573 } finally {
1574 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001575 }
1576 }
1577
1578 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001579 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001580 }
1581
Wink Savilleb564aae2014-10-23 10:18:09 -07001582 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001583 if (DBG) log("call: " + number);
1584
1585 // This is just a wrapper around the ACTION_CALL intent, but we still
1586 // need to do a permission check since we're calling startActivity()
1587 // from the context of the phone app.
1588 enforceCallPermission();
1589
Jordan Liu1617b712019-07-10 15:06:26 -07001590 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001591 != AppOpsManager.MODE_ALLOWED) {
1592 return;
1593 }
1594
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001595 final long identity = Binder.clearCallingIdentity();
1596 try {
1597 String url = createTelUrl(number);
1598 if (url == null) {
1599 return;
1600 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001601
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001602 boolean isValid = false;
1603 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1604 if (slist != null) {
1605 for (SubscriptionInfo subInfoRecord : slist) {
1606 if (subInfoRecord.getSubscriptionId() == subId) {
1607 isValid = true;
1608 break;
1609 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001610 }
Wink Saville08874612014-08-31 19:19:58 -07001611 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001612 if (!isValid) {
1613 return;
1614 }
Wink Saville08874612014-08-31 19:19:58 -07001615
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001616 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1617 intent.putExtra(SUBSCRIPTION_KEY, subId);
1618 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1619 mApp.startActivity(intent);
1620 } finally {
1621 Binder.restoreCallingIdentity(identity);
1622 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001623 }
1624
Wink Savilleb564aae2014-10-23 10:18:09 -07001625 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001626 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001627 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1628 }
1629
Wink Savilleb564aae2014-10-23 10:18:09 -07001630 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001631 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001632 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1633 }
1634
Wink Savilleb564aae2014-10-23 10:18:09 -07001635 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001636 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001637
1638 final long identity = Binder.clearCallingIdentity();
1639 try {
1640 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1641 checkSimPin.start();
1642 return checkSimPin.unlockSim(null, pin);
1643 } finally {
1644 Binder.restoreCallingIdentity(identity);
1645 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001646 }
1647
Wink Savilleb564aae2014-10-23 10:18:09 -07001648 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001649 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001650
1651 final long identity = Binder.clearCallingIdentity();
1652 try {
1653 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1654 checkSimPuk.start();
1655 return checkSimPuk.unlockSim(puk, pin);
1656 } finally {
1657 Binder.restoreCallingIdentity(identity);
1658 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659 }
1660
1661 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001662 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001663 * a synchronous one.
1664 */
1665 private static class UnlockSim extends Thread {
1666
1667 private final IccCard mSimCard;
1668
1669 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001670 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1671 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001672
1673 // For replies from SimCard interface
1674 private Handler mHandler;
1675
1676 // For async handler to identify request type
1677 private static final int SUPPLY_PIN_COMPLETE = 100;
1678
1679 public UnlockSim(IccCard simCard) {
1680 mSimCard = simCard;
1681 }
1682
1683 @Override
1684 public void run() {
1685 Looper.prepare();
1686 synchronized (UnlockSim.this) {
1687 mHandler = new Handler() {
1688 @Override
1689 public void handleMessage(Message msg) {
1690 AsyncResult ar = (AsyncResult) msg.obj;
1691 switch (msg.what) {
1692 case SUPPLY_PIN_COMPLETE:
1693 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1694 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001695 mRetryCount = msg.arg1;
1696 if (ar.exception != null) {
1697 if (ar.exception instanceof CommandException &&
1698 ((CommandException)(ar.exception)).getCommandError()
1699 == CommandException.Error.PASSWORD_INCORRECT) {
1700 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1701 } else {
1702 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1703 }
1704 } else {
1705 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1706 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001707 mDone = true;
1708 UnlockSim.this.notifyAll();
1709 }
1710 break;
1711 }
1712 }
1713 };
1714 UnlockSim.this.notifyAll();
1715 }
1716 Looper.loop();
1717 }
1718
1719 /*
1720 * Use PIN or PUK to unlock SIM card
1721 *
1722 * If PUK is null, unlock SIM card with PIN
1723 *
1724 * If PUK is not null, unlock SIM card with PUK and set PIN code
1725 */
Wink Saville9de0f752013-10-22 19:04:03 -07001726 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001727
1728 while (mHandler == null) {
1729 try {
1730 wait();
1731 } catch (InterruptedException e) {
1732 Thread.currentThread().interrupt();
1733 }
1734 }
1735 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1736
1737 if (puk == null) {
1738 mSimCard.supplyPin(pin, callback);
1739 } else {
1740 mSimCard.supplyPuk(puk, pin, callback);
1741 }
1742
1743 while (!mDone) {
1744 try {
1745 Log.d(LOG_TAG, "wait for done");
1746 wait();
1747 } catch (InterruptedException e) {
1748 // Restore the interrupted status
1749 Thread.currentThread().interrupt();
1750 }
1751 }
1752 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001753 int[] resultArray = new int[2];
1754 resultArray[0] = mResult;
1755 resultArray[1] = mRetryCount;
1756 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001757 }
1758 }
1759
1760 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001761 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001762
1763 }
1764
Wink Savilleb564aae2014-10-23 10:18:09 -07001765 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001766 // No permission check needed here: this call is harmless, and it's
1767 // needed for the ServiceState.requestStateUpdate() call (which is
1768 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001769 final long identity = Binder.clearCallingIdentity();
1770 try {
1771 final Phone phone = getPhone(subId);
1772 if (phone != null) {
1773 phone.updateServiceLocation();
1774 }
1775 } finally {
1776 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001777 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001778 }
1779
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001780 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001781 @Override
1782 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001783 return isRadioOnWithFeature(callingPackage, null);
1784 }
1785
1786
1787 @Override
1788 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1789 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1790 callingFeatureId);
1791 }
1792
1793 @Deprecated
1794 @Override
1795 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1796 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001797 }
1798
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001799 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001800 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1801 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001802 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001803 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001804 return false;
1805 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001806
1807 final long identity = Binder.clearCallingIdentity();
1808 try {
1809 return isRadioOnForSubscriber(subId);
1810 } finally {
1811 Binder.restoreCallingIdentity(identity);
1812 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001813 }
1814
1815 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001816 final long identity = Binder.clearCallingIdentity();
1817 try {
1818 final Phone phone = getPhone(subId);
1819 if (phone != null) {
1820 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1821 } else {
1822 return false;
1823 }
1824 } finally {
1825 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001826 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001827 }
1828
1829 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001830 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001831 }
Wink Saville36469e72014-06-11 15:17:00 -07001832
Wink Savilleb564aae2014-10-23 10:18:09 -07001833 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001834 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001835
1836 final long identity = Binder.clearCallingIdentity();
1837 try {
1838 final Phone phone = getPhone(subId);
1839 if (phone != null) {
1840 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1841 }
1842 } finally {
1843 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001844 }
Wink Saville36469e72014-06-11 15:17:00 -07001845 }
1846
1847 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001848 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001849 }
1850
Wink Savilleb564aae2014-10-23 10:18:09 -07001851 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001852 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001853
1854 final long identity = Binder.clearCallingIdentity();
1855 try {
1856 final Phone phone = getPhone(subId);
1857 if (phone == null) {
1858 return false;
1859 }
1860 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1861 toggleRadioOnOffForSubscriber(subId);
1862 }
1863 return true;
1864 } finally {
1865 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001866 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001867 }
Wink Saville36469e72014-06-11 15:17:00 -07001868
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001869 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08001870 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001871 /*
1872 * If any of the Radios are available, it will need to be
1873 * shutdown. So return true if any Radio is available.
1874 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001875 final long identity = Binder.clearCallingIdentity();
1876 try {
1877 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1878 Phone phone = PhoneFactory.getPhone(i);
1879 if (phone != null && phone.isRadioAvailable()) return true;
1880 }
1881 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1882 return false;
1883 } finally {
1884 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001885 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001886 }
1887
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001888 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001889 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001890 enforceModifyPermission();
1891
1892 final long identity = Binder.clearCallingIdentity();
1893 try {
1894 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1895 logv("Shutting down Phone " + i);
1896 shutdownRadioUsingPhoneId(i);
1897 }
1898 } finally {
1899 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001900 }
1901 }
1902
1903 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001904 Phone phone = PhoneFactory.getPhone(phoneId);
1905 if (phone != null && phone.isRadioAvailable()) {
1906 phone.shutdownRadio();
1907 }
1908 }
1909
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001910 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001911 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001912
1913 final long identity = Binder.clearCallingIdentity();
1914 try {
1915 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1916 if (defaultPhone != null) {
1917 defaultPhone.setRadioPower(turnOn);
1918 return true;
1919 } else {
1920 loge("There's no default phone.");
1921 return false;
1922 }
1923 } finally {
1924 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001925 }
Wink Saville36469e72014-06-11 15:17:00 -07001926 }
1927
Wink Savilleb564aae2014-10-23 10:18:09 -07001928 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001930
1931 final long identity = Binder.clearCallingIdentity();
1932 try {
1933 final Phone phone = getPhone(subId);
1934 if (phone != null) {
1935 phone.setRadioPower(turnOn);
1936 return true;
1937 } else {
1938 return false;
1939 }
1940 } finally {
1941 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001942 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 }
1944
Wink Saville36469e72014-06-11 15:17:00 -07001945 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001946 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001947 public boolean enableDataConnectivity() {
1948 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001949
1950 final long identity = Binder.clearCallingIdentity();
1951 try {
1952 int subId = mSubscriptionController.getDefaultDataSubId();
1953 final Phone phone = getPhone(subId);
1954 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001955 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001956 return true;
1957 } else {
1958 return false;
1959 }
1960 } finally {
1961 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001962 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001963 }
1964
Wink Saville36469e72014-06-11 15:17:00 -07001965 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001966 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001967 public boolean disableDataConnectivity() {
1968 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001969
1970 final long identity = Binder.clearCallingIdentity();
1971 try {
1972 int subId = mSubscriptionController.getDefaultDataSubId();
1973 final Phone phone = getPhone(subId);
1974 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001975 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001976 return true;
1977 } else {
1978 return false;
1979 }
1980 } finally {
1981 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001982 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001983 }
1984
Sanket Padawe356d7632015-06-22 14:03:32 -07001985 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001986 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001987 final long identity = Binder.clearCallingIdentity();
1988 try {
1989 final Phone phone = getPhone(subId);
1990 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001991 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001992 } else {
1993 return false;
1994 }
1995 } finally {
1996 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001997 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001998 }
1999
2000 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002001 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002002 }
2003
pkanwarae03a6b2016-11-06 20:37:09 -08002004 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002005 enforceCallPermission();
2006
2007 final long identity = Binder.clearCallingIdentity();
2008 try {
2009 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2010 return;
2011 }
2012 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2013 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2014 } finally {
2015 Binder.restoreCallingIdentity(identity);
2016 }
pkanwar32d516d2016-10-14 19:37:38 -07002017 };
2018
Wink Savilleb564aae2014-10-23 10:18:09 -07002019 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002020 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002021
2022 final long identity = Binder.clearCallingIdentity();
2023 try {
2024 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2025 return false;
2026 }
2027 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2028 } finally {
2029 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002030 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002031 }
2032
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002033 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002034 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002035 }
2036
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002037 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002038 final long identity = Binder.clearCallingIdentity();
2039 try {
2040 Phone phone = PhoneFactory.getPhone(slotIndex);
2041 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2042 PhoneConstantConversions.convertCallState(phone.getState());
2043 } finally {
2044 Binder.restoreCallingIdentity(identity);
2045 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002046 }
2047
Sanket Padawe356d7632015-06-22 14:03:32 -07002048 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002049 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002050 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2051 }
2052
2053 @Override
2054 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002055 final long identity = Binder.clearCallingIdentity();
2056 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002057 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002058 if (phone != null) {
2059 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2060 } else {
2061 return PhoneConstantConversions.convertDataState(
2062 PhoneConstants.DataState.DISCONNECTED);
2063 }
2064 } finally {
2065 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002066 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002067 }
2068
Sanket Padawe356d7632015-06-22 14:03:32 -07002069 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002070 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002071 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2072 }
2073
2074 @Override
2075 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002076 final long identity = Binder.clearCallingIdentity();
2077 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002078 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002079 if (phone != null) {
2080 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2081 } else {
2082 return TelephonyManager.DATA_ACTIVITY_NONE;
2083 }
2084 } finally {
2085 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002086 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002087 }
2088
2089 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002090 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002091 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002092 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002093
2094 LocationAccessPolicy.LocationPermissionResult locationResult =
2095 LocationAccessPolicy.checkLocationPermission(mApp,
2096 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2097 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002098 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002099 .setCallingPid(Binder.getCallingPid())
2100 .setCallingUid(Binder.getCallingUid())
2101 .setMethod("getCellLocation")
2102 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2103 .build());
2104 switch (locationResult) {
2105 case DENIED_HARD:
2106 throw new SecurityException("Not allowed to access cell location");
2107 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002108 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2109 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002110 }
2111
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002112 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002113 final long identity = Binder.clearCallingIdentity();
2114 try {
2115 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002116 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002117 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002118 } finally {
2119 Binder.restoreCallingIdentity(identity);
2120 }
Svetoslav64fad262015-04-14 14:35:21 -07002121 }
2122
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002123 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002124 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2125 String callingFeatureId) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002126 if (!TextUtils.isEmpty(callingPackage)) {
2127 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002128 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2129 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002130 return "";
2131 }
2132 }
2133
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002134 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2135 // registered cell info, so return a NULL country instead.
2136 final long identity = Binder.clearCallingIdentity();
2137 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002138 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2139 // Get default phone in this case.
2140 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2141 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002142 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002143 // Todo: fix this when we can get the actual cellular network info when the device
2144 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002145 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002146 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2147 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002148 return "";
2149 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002150 Phone phone = PhoneFactory.getPhone(phoneId);
2151 if (phone != null) {
2152 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002153 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002154 if (sst != null) {
2155 LocaleTracker lt = sst.getLocaleTracker();
2156 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002157 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2158 return lt.getCurrentCountry();
2159 } else if (emergencyNumberTracker != null) {
2160 return emergencyNumberTracker.getEmergencyCountryIso();
2161 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002162 }
2163 }
2164 }
2165 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002166 } finally {
2167 Binder.restoreCallingIdentity(identity);
2168 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002169 }
2170
2171 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002173 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002174 }
2175
Sanket Padawe356d7632015-06-22 14:03:32 -07002176 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002177 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002178 mApp.enforceCallingOrSelfPermission(
2179 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002180
2181 final long identity = Binder.clearCallingIdentity();
2182 try {
2183 final Phone phone = getPhone(subId);
2184 if (phone != null) {
2185 phone.enableLocationUpdates();
2186 }
2187 } finally {
2188 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002189 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002190 }
2191
2192 @Override
2193 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002194 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002195 }
2196
Sanket Padawe356d7632015-06-22 14:03:32 -07002197 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002198 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002199 mApp.enforceCallingOrSelfPermission(
2200 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002201
2202 final long identity = Binder.clearCallingIdentity();
2203 try {
2204 final Phone phone = getPhone(subId);
2205 if (phone != null) {
2206 phone.disableLocationUpdates();
2207 }
2208 } finally {
2209 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002210 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002211 }
2212
Nathan Harold31d7ff32018-10-15 20:20:30 -07002213 /**
2214 * Returns the target SDK version number for a given package name.
2215 *
Nathan Haroldec184742019-07-10 17:04:16 -07002216 * This call MUST be invoked before clearing the calling UID.
2217 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002218 * @return target SDK if the package is found or INT_MAX.
2219 */
2220 private int getTargetSdk(String packageName) {
2221 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002222 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002223 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002224 if (ai != null) return ai.targetSdkVersion;
2225 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002226 loge("Failed to get package info for pkg="
2227 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002228 }
2229 return Integer.MAX_VALUE;
2230 }
2231
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002232 @Override
2233 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002234 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2235 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002236 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002237 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2238 throw new SecurityException(
2239 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2240 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002241
Jordan Liu1617b712019-07-10 15:06:26 -07002242 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002243 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2244 return null;
2245 }
Svetoslav64fad262015-04-14 14:35:21 -07002246
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002247 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002248
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002249 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002250 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002251
Nathan Haroldf180aac2018-06-01 18:43:55 -07002252 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2253 for (CellInfo ci : info) {
2254 if (ci instanceof CellInfoGsm) {
2255 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2256 } else if (ci instanceof CellInfoWcdma) {
2257 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002260 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002261 }
2262
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002263 private List<CellInfo> getCachedCellInfo() {
2264 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2265 for (Phone phone : PhoneFactory.getPhones()) {
2266 List<CellInfo> info = phone.getAllCellInfo();
2267 if (info != null) cellInfos.addAll(info);
2268 }
2269 return cellInfos;
2270 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002271
2272 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002273 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002274 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002275 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002276
2277 LocationAccessPolicy.LocationPermissionResult locationResult =
2278 LocationAccessPolicy.checkLocationPermission(mApp,
2279 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2280 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002281 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002282 .setCallingPid(Binder.getCallingPid())
2283 .setCallingUid(Binder.getCallingUid())
2284 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002285 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002286 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2287 .build());
2288 switch (locationResult) {
2289 case DENIED_HARD:
2290 throw new SecurityException("Not allowed to access cell info");
2291 case DENIED_SOFT:
2292 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002293 }
2294
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002295 final int targetSdk = getTargetSdk(callingPackage);
2296 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2297 return getCachedCellInfo();
2298 }
2299
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002300 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002301 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002302 final long identity = Binder.clearCallingIdentity();
2303 try {
2304 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2305 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002306 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002307 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002308 if (info != null) cellInfos.addAll(info);
2309 }
2310 return cellInfos;
2311 } finally {
2312 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002313 }
2314 }
2315
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002316 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002317 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2318 String callingFeatureId) {
2319 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2320 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002321 }
2322
2323 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002324 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2325 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002326 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002327 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002328 }
2329
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002330 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2331 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002332 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002333 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002334
2335 LocationAccessPolicy.LocationPermissionResult locationResult =
2336 LocationAccessPolicy.checkLocationPermission(mApp,
2337 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2338 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002339 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002340 .setCallingPid(Binder.getCallingPid())
2341 .setCallingUid(Binder.getCallingUid())
2342 .setMethod("requestCellInfoUpdate")
2343 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2344 .build());
2345 switch (locationResult) {
2346 case DENIED_HARD:
2347 throw new SecurityException("Not allowed to access cell info");
2348 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002349 try {
2350 cb.onCellInfo(new ArrayList<CellInfo>());
2351 } catch (RemoteException re) {
2352 // Drop without consequences
2353 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002354 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002355 }
2356
Nathan Harolda939a962019-05-09 10:13:47 -07002357
2358 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002359 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2360
2361 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2362 }
2363
2364 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002365 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002366 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002367 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002368
2369 final long identity = Binder.clearCallingIdentity();
2370 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002371 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002372 } finally {
2373 Binder.restoreCallingIdentity(identity);
2374 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 }
2376
Shishir Agrawala9f32182016-04-12 12:00:16 -07002377 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002378 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002379 Phone phone = PhoneFactory.getPhone(slotIndex);
2380 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002381 return null;
2382 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002383 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002384 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002385 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002386 return null;
2387 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002388
2389 final long identity = Binder.clearCallingIdentity();
2390 try {
2391 return phone.getImei();
2392 } finally {
2393 Binder.restoreCallingIdentity(identity);
2394 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002395 }
2396
2397 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002398 public String getTypeAllocationCodeForSlot(int slotIndex) {
2399 Phone phone = PhoneFactory.getPhone(slotIndex);
2400 String tac = null;
2401 if (phone != null) {
2402 String imei = phone.getImei();
2403 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2404 }
2405 return tac;
2406 }
2407
2408 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002409 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002410 Phone phone = PhoneFactory.getPhone(slotIndex);
2411 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002412 return null;
2413 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002414
Jeff Davidson913390f2018-02-23 17:11:49 -08002415 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002416 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002417 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002418 return null;
2419 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002420
2421 final long identity = Binder.clearCallingIdentity();
2422 try {
2423 return phone.getMeid();
2424 } finally {
2425 Binder.restoreCallingIdentity(identity);
2426 }
Jack Yu2af8d712017-03-15 17:14:14 -07002427 }
2428
2429 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002430 public String getManufacturerCodeForSlot(int slotIndex) {
2431 Phone phone = PhoneFactory.getPhone(slotIndex);
2432 String manufacturerCode = null;
2433 if (phone != null) {
2434 String meid = phone.getMeid();
2435 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2436 }
2437 return manufacturerCode;
2438 }
2439
2440 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002441 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2442 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002443 Phone phone = PhoneFactory.getPhone(slotIndex);
2444 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002445 return null;
2446 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002447 int subId = phone.getSubId();
2448 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002449 mApp, subId, callingPackage, callingFeatureId,
2450 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002451 return null;
2452 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002453
2454 final long identity = Binder.clearCallingIdentity();
2455 try {
2456 return phone.getDeviceSvn();
2457 } finally {
2458 Binder.restoreCallingIdentity(identity);
2459 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002460 }
2461
fionaxu43304da2017-11-27 22:51:16 -08002462 @Override
2463 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002464 final long identity = Binder.clearCallingIdentity();
2465 try {
2466 final Phone phone = getPhone(subId);
2467 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2468 } finally {
2469 Binder.restoreCallingIdentity(identity);
2470 }
fionaxu43304da2017-11-27 22:51:16 -08002471 }
2472
2473 @Override
2474 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002475 final long identity = Binder.clearCallingIdentity();
2476 try {
2477 final Phone phone = getPhone(subId);
2478 return phone == null ? null : phone.getCarrierName();
2479 } finally {
2480 Binder.restoreCallingIdentity(identity);
2481 }
fionaxu43304da2017-11-27 22:51:16 -08002482 }
2483
calvinpanffe225e2018-11-01 19:43:06 +08002484 @Override
chen xu0026ca62019-03-06 15:28:50 -08002485 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002486 final long identity = Binder.clearCallingIdentity();
2487 try {
2488 final Phone phone = getPhone(subId);
2489 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002490 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002491 } finally {
2492 Binder.restoreCallingIdentity(identity);
2493 }
2494 }
2495
2496 @Override
chen xu0026ca62019-03-06 15:28:50 -08002497 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002498 final long identity = Binder.clearCallingIdentity();
2499 try {
2500 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002501 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002502 } finally {
2503 Binder.restoreCallingIdentity(identity);
2504 }
2505 }
2506
chen xu651eec72018-11-11 19:03:44 -08002507 @Override
chen xu864e11c2018-12-06 22:10:03 -08002508 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2509 if (!isSubscriptionMccMnc) {
2510 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2511 }
chen xu651eec72018-11-11 19:03:44 -08002512 final Phone phone = PhoneFactory.getPhone(slotIndex);
2513 if (phone == null) {
2514 return TelephonyManager.UNKNOWN_CARRIER_ID;
2515 }
2516 final long identity = Binder.clearCallingIdentity();
2517 try {
2518 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2519 } finally {
2520 Binder.restoreCallingIdentity(identity);
2521 }
2522 }
2523
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002524 //
2525 // Internal helper methods.
2526 //
2527
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002528 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002529 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2530 *
2531 * @throws SecurityException if the caller does not have the required permission
2532 */
2533 private void enforceModifyPermission() {
2534 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2535 }
2536
Shuo Qiancd19c462020-01-16 20:51:11 -08002537 /**
2538 * Make sure the caller is system.
2539 *
2540 * @throws SecurityException if the caller is not system.
2541 */
2542 private void enforceSystemCaller() {
2543 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2544 throw new SecurityException("Caller must be system");
2545 }
2546 }
2547
Shuo Qian3b6ee772019-11-13 17:43:31 -08002548 private void enforceActiveEmergencySessionPermission() {
2549 mApp.enforceCallingOrSelfPermission(
2550 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2551 }
2552
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002553 /**
2554 * Make sure the caller has the CALL_PHONE permission.
2555 *
2556 * @throws SecurityException if the caller does not have the required permission
2557 */
2558 private void enforceCallPermission() {
2559 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2560 }
2561
paulhu5a773602019-08-23 19:17:33 +08002562 private void enforceSettingsPermission() {
2563 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002564 }
2565
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002566 private String createTelUrl(String number) {
2567 if (TextUtils.isEmpty(number)) {
2568 return null;
2569 }
2570
Jake Hambye994d462014-02-03 13:10:13 -08002571 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002572 }
2573
Ihab Awadf9e92732013-12-05 18:02:52 -08002574 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002575 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2576 }
2577
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002578 private static void logv(String msg) {
2579 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2580 }
2581
Ihab Awadf9e92732013-12-05 18:02:52 -08002582 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002583 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2584 }
2585
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002586 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002587 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002588 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002589 }
2590
Sanket Padawe356d7632015-06-22 14:03:32 -07002591 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002592 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002593 final long identity = Binder.clearCallingIdentity();
2594 try {
2595 final Phone phone = PhoneFactory.getPhone(slotIndex);
2596 if (phone == null) {
2597 return PhoneConstants.PHONE_TYPE_NONE;
2598 } else {
2599 return phone.getPhoneType();
2600 }
2601 } finally {
2602 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002603 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002604 }
2605
2606 /**
2607 * Returns the CDMA ERI icon index to display
2608 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002609 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002610 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2611 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2612 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002613 }
2614
Sanket Padawe356d7632015-06-22 14:03:32 -07002615 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002616 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2617 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002618 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002619 mApp, subId, callingPackage, callingFeatureId,
2620 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002621 return -1;
2622 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623
2624 final long identity = Binder.clearCallingIdentity();
2625 try {
2626 final Phone phone = getPhone(subId);
2627 if (phone != null) {
2628 return phone.getCdmaEriIconIndex();
2629 } else {
2630 return -1;
2631 }
2632 } finally {
2633 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002634 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002635 }
2636
2637 /**
2638 * Returns the CDMA ERI icon mode,
2639 * 0 - ON
2640 * 1 - FLASHING
2641 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002642 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002643 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2644 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2645 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002646 }
2647
Sanket Padawe356d7632015-06-22 14:03:32 -07002648 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002649 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2650 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002651 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002652 mApp, subId, callingPackage, callingFeatureId,
2653 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002654 return -1;
2655 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002656
2657 final long identity = Binder.clearCallingIdentity();
2658 try {
2659 final Phone phone = getPhone(subId);
2660 if (phone != null) {
2661 return phone.getCdmaEriIconMode();
2662 } else {
2663 return -1;
2664 }
2665 } finally {
2666 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002667 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002668 }
2669
2670 /**
2671 * Returns the CDMA ERI text,
2672 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002673 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002674 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2675 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2676 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002677 }
2678
Sanket Padawe356d7632015-06-22 14:03:32 -07002679 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002680 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2681 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002682 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002683 mApp, subId, callingPackage, callingFeatureId,
2684 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002685 return null;
2686 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002687
2688 final long identity = Binder.clearCallingIdentity();
2689 try {
2690 final Phone phone = getPhone(subId);
2691 if (phone != null) {
2692 return phone.getCdmaEriText();
2693 } else {
2694 return null;
2695 }
2696 } finally {
2697 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002698 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002699 }
2700
2701 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002702 * Returns the CDMA MDN.
2703 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002704 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002705 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002706 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2707 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002708
2709 final long identity = Binder.clearCallingIdentity();
2710 try {
2711 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002712 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002713 return phone.getLine1Number();
2714 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002715 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002716 return null;
2717 }
2718 } finally {
2719 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002720 }
2721 }
2722
2723 /**
2724 * Returns the CDMA MIN.
2725 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002726 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002727 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002728 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2729 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002730
2731 final long identity = Binder.clearCallingIdentity();
2732 try {
2733 final Phone phone = getPhone(subId);
2734 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2735 return phone.getCdmaMin();
2736 } else {
2737 return null;
2738 }
2739 } finally {
2740 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002741 }
2742 }
2743
Hall Liud892bec2018-11-30 14:51:45 -08002744 @Override
2745 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2746 INumberVerificationCallback callback, String callingPackage) {
2747 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2748 != PERMISSION_GRANTED) {
2749 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2750 }
2751 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2752
2753 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2754 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2755 throw new SecurityException("Calling package must be configured in the device config");
2756 }
2757
2758 if (range == null) {
2759 throw new NullPointerException("Range must be non-null");
2760 }
2761
2762 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002763 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002764
2765 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2766 }
2767
Junda Liuca05d5d2014-08-14 22:36:34 -07002768 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002769 * Returns true if CDMA provisioning needs to run.
2770 */
2771 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002772 final long identity = Binder.clearCallingIdentity();
2773 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002774 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002775 } finally {
2776 Binder.restoreCallingIdentity(identity);
2777 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 }
2779
2780 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002781 * Sets the voice mail number of a given subId.
2782 */
2783 @Override
2784 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002785 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2786 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002787
2788 final long identity = Binder.clearCallingIdentity();
2789 try {
2790 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2791 new Pair<String, String>(alphaTag, number), new Integer(subId));
2792 return success;
2793 } finally {
2794 Binder.restoreCallingIdentity(identity);
2795 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002796 }
2797
Ta-wei Yen87c49842016-05-13 21:19:52 -07002798 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002799 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2800 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002801 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2802 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002803 if (!TextUtils.equals(callingPackage, systemDialer)) {
2804 throw new SecurityException("caller must be system dialer");
2805 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002806
2807 final long identity = Binder.clearCallingIdentity();
2808 try {
2809 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2810 if (phoneAccountHandle == null) {
2811 return null;
2812 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002813 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002814 } finally {
2815 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002816 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002817 }
2818
2819 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002820 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2821 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002822 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002823 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002824 mApp, subId, callingPackage, callingFeatureId,
2825 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002826 return null;
2827 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002828
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002829 final long identity = Binder.clearCallingIdentity();
2830 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002831 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002832 } finally {
2833 Binder.restoreCallingIdentity(identity);
2834 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002835 }
2836
2837 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002838 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2839 VisualVoicemailSmsFilterSettings settings) {
2840 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002841
2842 final long identity = Binder.clearCallingIdentity();
2843 try {
2844 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002845 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002846 } finally {
2847 Binder.restoreCallingIdentity(identity);
2848 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002849 }
2850
2851 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002852 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2853 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002854
2855 final long identity = Binder.clearCallingIdentity();
2856 try {
2857 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002858 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002859 } finally {
2860 Binder.restoreCallingIdentity(identity);
2861 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002862 }
2863
2864 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002865 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2866 String callingPackage, int subId) {
2867 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002868
2869 final long identity = Binder.clearCallingIdentity();
2870 try {
2871 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002872 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002873 } finally {
2874 Binder.restoreCallingIdentity(identity);
2875 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002876 }
2877
2878 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002879 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002880 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002881
2882 final long identity = Binder.clearCallingIdentity();
2883 try {
2884 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002885 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002886 } finally {
2887 Binder.restoreCallingIdentity(identity);
2888 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002889 }
2890
2891 @Override
2892 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2893 String number, int port, String text, PendingIntent sentIntent) {
2894 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002895 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002896 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002897 SmsController smsController = PhoneFactory.getSmsController();
2898 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2899 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002900 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002901
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002902 /**
fionaxu0152e512016-11-14 13:36:14 -08002903 * Sets the voice activation state of a given subId.
2904 */
2905 @Override
2906 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002907 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2908 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002909
2910 final long identity = Binder.clearCallingIdentity();
2911 try {
2912 final Phone phone = getPhone(subId);
2913 if (phone != null) {
2914 phone.setVoiceActivationState(activationState);
2915 } else {
2916 loge("setVoiceActivationState fails with invalid subId: " + subId);
2917 }
2918 } finally {
2919 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002920 }
2921 }
2922
2923 /**
2924 * Sets the data activation state of a given subId.
2925 */
2926 @Override
2927 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002928 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2929 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002930
2931 final long identity = Binder.clearCallingIdentity();
2932 try {
2933 final Phone phone = getPhone(subId);
2934 if (phone != null) {
2935 phone.setDataActivationState(activationState);
2936 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002937 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938 }
2939 } finally {
2940 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002941 }
2942 }
2943
2944 /**
2945 * Returns the voice activation state of a given subId.
2946 */
2947 @Override
2948 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002949 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002950
fionaxu0152e512016-11-14 13:36:14 -08002951 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002952 final long identity = Binder.clearCallingIdentity();
2953 try {
2954 if (phone != null) {
2955 return phone.getVoiceActivationState();
2956 } else {
2957 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2958 }
2959 } finally {
2960 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002961 }
2962 }
2963
2964 /**
2965 * Returns the data activation state of a given subId.
2966 */
2967 @Override
2968 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002969 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002970
fionaxu0152e512016-11-14 13:36:14 -08002971 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002972 final long identity = Binder.clearCallingIdentity();
2973 try {
2974 if (phone != null) {
2975 return phone.getDataActivationState();
2976 } else {
2977 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2978 }
2979 } finally {
2980 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002981 }
2982 }
2983
2984 /**
Wink Saville36469e72014-06-11 15:17:00 -07002985 * Returns the unread count of voicemails for a subId
2986 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002987 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002988 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2989 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002990 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002991 mApp, subId, callingPackage, callingFeatureId,
2992 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002993 return 0;
2994 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002995 final long identity = Binder.clearCallingIdentity();
2996 try {
2997 final Phone phone = getPhone(subId);
2998 if (phone != null) {
2999 return phone.getVoiceMessageCount();
3000 } else {
3001 return 0;
3002 }
3003 } finally {
3004 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003005 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003006 }
3007
3008 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003009 * returns true, if the device is in a state where both voice and data
3010 * are supported simultaneously. This can change based on location or network condition.
3011 */
3012 @Override
3013 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003014 final long identity = Binder.clearCallingIdentity();
3015 try {
3016 final Phone phone = getPhone(subId);
3017 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3018 } finally {
3019 Binder.restoreCallingIdentity(identity);
3020 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003021 }
3022
3023 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003024 * Send the dialer code if called from the current default dialer or the caller has
3025 * carrier privilege.
3026 * @param inputCode The dialer code to send
3027 */
3028 @Override
3029 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003030 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003031 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003032 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3033 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003034 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003035 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003036 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003037 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003038
3039 final long identity = Binder.clearCallingIdentity();
3040 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003041 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003042 } finally {
3043 Binder.restoreCallingIdentity(identity);
3044 }
fionaxu235cc5e2017-03-06 22:25:57 -08003045 }
3046
Pengquan Menga1bb6272018-09-06 09:59:22 -07003047 @Override
3048 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003049 TelephonyPermissions
3050 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3051 mApp, subId, "getNetworkSelectionMode");
3052 final long identity = Binder.clearCallingIdentity();
3053 try {
3054 if (!isActiveSubscription(subId)) {
3055 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3056 }
3057 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3058 } finally {
3059 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003060 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003061 }
3062
Brad Ebinger35c841c2018-10-01 10:40:55 -07003063 @Override
Sarah Chin0605abf2019-12-06 10:24:18 -08003064 public PhoneCapability getPhoneCapability(int subId, String callingPackage,
3065 String callingFeatureId) {
3066 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3067 mApp, subId, callingPackage, callingFeatureId, "getPhoneCapability")) {
3068 return null;
3069 }
3070 final long identity = Binder.clearCallingIdentity();
3071 try {
3072 return mPhoneConfigurationManager.getStaticPhoneCapability();
3073 } finally {
3074 Binder.restoreCallingIdentity(identity);
3075 }
3076 }
3077
3078 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003079 public boolean isInEmergencySmsMode() {
3080 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3081 final long identity = Binder.clearCallingIdentity();
3082 try {
3083 for (Phone phone : PhoneFactory.getPhones()) {
3084 if (phone.isInEmergencySmsMode()) {
3085 return true;
3086 }
3087 }
3088 } finally {
3089 Binder.restoreCallingIdentity(identity);
3090 }
3091 return false;
3092 }
3093
shilu366312e2019-12-17 09:28:10 -08003094 /**
3095 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3096 * @param subId The subscription to use to check the configuration.
3097 * @param c The callback that will be used to send the result.
3098 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003099 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003100 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3101 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003102 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003103 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003104
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003105 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3106 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3107 "IMS not available on device.");
3108 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003109 final long token = Binder.clearCallingIdentity();
3110 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003111 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003112 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003113 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003114 } catch (ImsException e) {
3115 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003116 } finally {
3117 Binder.restoreCallingIdentity(token);
3118 }
3119 }
3120
shilu366312e2019-12-17 09:28:10 -08003121 /**
3122 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3123 * @param subId The subscription to use to check the configuration.
3124 * @param c The callback that will be used to send the result.
3125 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003126 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003127 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
shilu366312e2019-12-17 09:28:10 -08003128 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003129 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003130 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3131 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3132 }
Meng Wangafbc5852019-09-19 17:37:13 -07003133 final long token = Binder.clearCallingIdentity();
3134 try {
3135 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3136 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3137 .removeRegistrationCallbackForSubscription(c, subId);
3138 } catch (ImsException e) {
3139 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3140 + "is inactive, ignoring unregister.");
3141 // If the subscription is no longer active, just return, since the callback
3142 // will already have been removed internally.
3143 } finally {
3144 Binder.restoreCallingIdentity(token);
3145 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003146 }
3147
Brad Ebingera34a6c22019-10-22 17:36:18 -07003148 /**
3149 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3150 */
3151 @Override
3152 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3153 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3154 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3155 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3156 "IMS not available on device.");
3157 }
3158 final long token = Binder.clearCallingIdentity();
3159 try {
3160 Phone phone = getPhone(subId);
3161 if (phone == null) {
3162 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3163 + subId + "'");
3164 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3165 }
3166 phone.getImsRegistrationState(regState -> {
3167 try {
3168 consumer.accept((regState == null)
3169 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3170 } catch (RemoteException e) {
3171 // Ignore if the remote process is no longer available to call back.
3172 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3173 }
3174 });
3175 } finally {
3176 Binder.restoreCallingIdentity(token);
3177 }
3178 }
3179
3180 /**
3181 * Get the transport type for the IMS service registration state.
3182 */
3183 @Override
3184 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
shilu366312e2019-12-17 09:28:10 -08003185 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebingera34a6c22019-10-22 17:36:18 -07003186 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3187 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3188 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3189 "IMS not available on device.");
3190 }
3191 final long token = Binder.clearCallingIdentity();
3192 try {
3193 Phone phone = getPhone(subId);
3194 if (phone == null) {
3195 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3196 + subId + "'");
3197 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3198 }
3199 phone.getImsRegistrationTech(regTech -> {
3200 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3201 int regTechConverted = (regTech == null)
3202 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3203 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3204 regTechConverted);
3205 try {
3206 consumer.accept(regTechConverted);
3207 } catch (RemoteException e) {
3208 // Ignore if the remote process is no longer available to call back.
3209 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3210 }
3211 });
3212 } finally {
3213 Binder.restoreCallingIdentity(token);
3214 }
3215 }
3216
shilu366312e2019-12-17 09:28:10 -08003217 /**
3218 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3219 * @param subId The subscription to use to check the configuration.
3220 * @param c The callback that will be used to send the result.
3221 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003222 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003223 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3224 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003225 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003226 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003227 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3228 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3229 "IMS not available on device.");
3230 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003231 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3232 final long token = Binder.clearCallingIdentity();
3233 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003234 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003235 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003236 } catch (ImsException e) {
3237 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003238 } finally {
3239 Binder.restoreCallingIdentity(token);
3240 }
3241 }
3242
shilu366312e2019-12-17 09:28:10 -08003243 /**
3244 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3245 * @param subId The subscription to use to check the configuration.
3246 * @param c The callback that will be used to send the result.
3247 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003248 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003249 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
shilu366312e2019-12-17 09:28:10 -08003250 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003251 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003252 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3253 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3254 }
Meng Wangafbc5852019-09-19 17:37:13 -07003255
3256 final long token = Binder.clearCallingIdentity();
3257 try {
3258 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3259 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003260 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003261 } catch (ImsException e) {
3262 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3263 + "is inactive, ignoring unregister.");
3264 // If the subscription is no longer active, just return, since the callback
3265 // will already have been removed internally.
3266 } finally {
3267 Binder.restoreCallingIdentity(token);
3268 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003269 }
3270
3271 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003272 public boolean isCapable(int subId, int capability, int regTech) {
3273 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003274 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3275 final long token = Binder.clearCallingIdentity();
3276 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003277 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003278 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003279 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003280 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3281 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003282 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003283 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3284 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003285 } finally {
3286 Binder.restoreCallingIdentity(token);
3287 }
3288 }
3289
3290 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003291 public boolean isAvailable(int subId, int capability, int regTech) {
3292 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003293 final long token = Binder.clearCallingIdentity();
3294 try {
3295 Phone phone = getPhone(subId);
3296 if (phone == null) return false;
3297 return phone.isImsCapabilityAvailable(capability, regTech);
3298 } finally {
3299 Binder.restoreCallingIdentity(token);
3300 }
3301 }
3302
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003303 /**
3304 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3305 * subscription.
3306 * @param subId The subscription to use to check the configuration.
3307 * @param callback The callback that will be used to send the result.
3308 * @param capability The MmTelFeature capability that will be used to send the result.
3309 * @param transportType The transport type of the MmTelFeature capability.
3310 */
3311 @Override
3312 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3313 int transportType) {
3314 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3315 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3316 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3317 "IMS not available on device.");
3318 }
3319 final long token = Binder.clearCallingIdentity();
3320 try {
3321 int slotId = getSlotIndex(subId);
3322 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3323 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3324 + subId + "'");
3325 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3326 }
3327 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3328 transportType, aBoolean -> {
3329 try {
3330 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3331 } catch (RemoteException e) {
3332 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3333 + "running. Ignore");
3334 }
3335 });
3336 } finally {
3337 Binder.restoreCallingIdentity(token);
3338 }
3339 }
3340
shilu366312e2019-12-17 09:28:10 -08003341 /**
3342 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3343 * @param subId The subscription to use to check the configuration.
3344 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003345 @Override
3346 public boolean isAdvancedCallingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003347 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
3348 enforceReadPrivilegedPermission("isAdvancedCallingSettingEnabled");
3349
Brad Ebinger35c841c2018-10-01 10:40:55 -07003350 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3351 final long token = Binder.clearCallingIdentity();
3352 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003353 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003354 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003355 } catch (ImsException e) {
3356 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003357 } finally {
3358 Binder.restoreCallingIdentity(token);
3359 }
3360 }
3361
3362 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003363 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003364 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003365 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003366 final long identity = Binder.clearCallingIdentity();
3367 try {
3368 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003369 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003370 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003371 } catch (ImsException e) {
3372 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003373 } finally {
3374 Binder.restoreCallingIdentity(identity);
3375 }
3376 }
3377
shilu366312e2019-12-17 09:28:10 -08003378 /**
3379 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3380 * @param subId The subscription to use to check the configuration.
3381 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003382 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003383 public boolean isVtSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003384 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003385 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003386 final long identity = Binder.clearCallingIdentity();
3387 try {
3388 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003389 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3390 } catch (ImsException e) {
3391 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003392 } finally {
3393 Binder.restoreCallingIdentity(identity);
3394 }
3395 }
3396
3397 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003398 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003400 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003401 final long identity = Binder.clearCallingIdentity();
3402 try {
3403 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003404 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003405 } catch (ImsException e) {
3406 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003407 } finally {
3408 Binder.restoreCallingIdentity(identity);
3409 }
3410 }
3411
shilu366312e2019-12-17 09:28:10 -08003412 /**
3413 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3414 * @param subId The subscription to use to check the configuration.
3415 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003416 @Override
3417 public boolean isVoWiFiSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003418 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003419 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3420 final long identity = Binder.clearCallingIdentity();
3421 try {
3422 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003423 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003424 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003425 } catch (ImsException e) {
3426 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003427 } finally {
3428 Binder.restoreCallingIdentity(identity);
3429 }
3430 }
3431
3432 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003433 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003434 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003435 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003436 final long identity = Binder.clearCallingIdentity();
3437 try {
3438 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003439 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003440 } catch (ImsException e) {
3441 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003442 } finally {
3443 Binder.restoreCallingIdentity(identity);
3444 }
3445 }
3446
shilu366312e2019-12-17 09:28:10 -08003447 /**
3448 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3449 * @param subId The subscription to use to check the configuration.
3450 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003451 @Override
3452 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003453 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003454 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3455 final long identity = Binder.clearCallingIdentity();
3456 try {
3457 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003458 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003459 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003460 } catch (ImsException e) {
3461 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003462 } finally {
3463 Binder.restoreCallingIdentity(identity);
3464 }
3465 }
3466
3467 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003468 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003469 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003470 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003471 final long identity = Binder.clearCallingIdentity();
3472 try {
3473 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003474 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003475 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003476 } catch (ImsException e) {
3477 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003478 } finally {
3479 Binder.restoreCallingIdentity(identity);
3480 }
3481 }
3482
3483 @Override
3484 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3485 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3486 "setVoWiFiNonPersistent");
3487 final long identity = Binder.clearCallingIdentity();
3488 try {
3489 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003490 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003491 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003492 } catch (ImsException e) {
3493 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003494 } finally {
3495 Binder.restoreCallingIdentity(identity);
3496 }
3497 }
3498
shilu366312e2019-12-17 09:28:10 -08003499 /**
3500 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3501 * @param subId The subscription to use to check the configuration.
3502 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003503 @Override
3504 public int getVoWiFiModeSetting(int subId) {
shilu366312e2019-12-17 09:28:10 -08003505 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003506 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3507 final long identity = Binder.clearCallingIdentity();
3508 try {
3509 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003510 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003511 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003512 } catch (ImsException e) {
3513 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003514 } finally {
3515 Binder.restoreCallingIdentity(identity);
3516 }
3517 }
3518
3519 @Override
3520 public void setVoWiFiModeSetting(int subId, int mode) {
3521 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3522 "setVoWiFiModeSetting");
3523 final long identity = Binder.clearCallingIdentity();
3524 try {
3525 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003526 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003527 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003528 } catch (ImsException e) {
3529 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003530 } finally {
3531 Binder.restoreCallingIdentity(identity);
3532 }
3533 }
3534
3535 @Override
3536 public int getVoWiFiRoamingModeSetting(int subId) {
3537 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3538 final long identity = Binder.clearCallingIdentity();
3539 try {
3540 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003541 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003542 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003543 } catch (ImsException e) {
3544 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003545 } finally {
3546 Binder.restoreCallingIdentity(identity);
3547 }
3548 }
3549
3550 @Override
3551 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3553 "setVoWiFiRoamingModeSetting");
3554 final long identity = Binder.clearCallingIdentity();
3555 try {
3556 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003557 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003558 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003559 } catch (ImsException e) {
3560 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003561 } finally {
3562 Binder.restoreCallingIdentity(identity);
3563 }
3564 }
3565
3566 @Override
3567 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3568 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3569 "setRttCapabilityEnabled");
3570 final long identity = Binder.clearCallingIdentity();
3571 try {
3572 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003573 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3574 } catch (ImsException e) {
3575 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003576 } finally {
3577 Binder.restoreCallingIdentity(identity);
3578 }
3579 }
3580
shilu366312e2019-12-17 09:28:10 -08003581 /**
3582 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3583 * @param subId The subscription to use to check the configuration.
3584 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003585 @Override
3586 public boolean isTtyOverVolteEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003587 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003588 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3589 final long identity = Binder.clearCallingIdentity();
3590 try {
3591 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003592 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003593 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003594 } catch (ImsException e) {
3595 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003596 } finally {
3597 Binder.restoreCallingIdentity(identity);
3598 }
3599 }
3600
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003601 @Override
3602 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3603 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3604 final long identity = Binder.clearCallingIdentity();
3605 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003606 if (!isImsAvailableOnDevice()) {
3607 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3608 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003609 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003610 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003611 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003612 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003613 } catch (ImsException e) {
3614 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003615 } finally {
3616 Binder.restoreCallingIdentity(identity);
3617 }
3618 }
3619
3620 @Override
3621 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3622 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3623 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003624 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3625 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3626 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003627 try {
3628 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003629 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003630 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003631 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003632 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3633 + "is inactive, ignoring unregister.");
3634 // If the subscription is no longer active, just return, since the callback will already
3635 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003636 } finally {
3637 Binder.restoreCallingIdentity(identity);
3638 }
3639 }
3640
allenwtsu99c623b2020-01-03 18:24:23 +08003641
3642 private void checkModifyPhoneStatePermission(int subId, String message) {
3643 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3644 message);
3645 }
3646
3647 private boolean isImsProvisioningRequired(int subId, int capability,
3648 boolean isMmtelCapability) {
3649 Phone phone = getPhone(subId);
3650 if (phone == null) {
3651 loge("phone instance null for subid " + subId);
3652 return false;
3653 }
3654 if (isMmtelCapability) {
3655 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3656 return false;
3657 }
3658 } else {
3659 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3660 return false;
3661 }
3662 }
3663 return true;
3664 }
3665
3666 @Override
3667 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3668 boolean isProvisioned) {
3669 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3670
3671 final long identity = Binder.clearCallingIdentity();
3672 try {
3673 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3674 if (!isImsProvisioningRequired(subId, capability, false)) {
3675 return;
3676 }
3677
3678 // this capability requires provisioning, route to the correct API.
3679 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3680 switch (capability) {
3681 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3682 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3683 ims.setEabProvisioned(isProvisioned);
3684 break;
3685 default: {
3686 throw new IllegalArgumentException("Tried to set provisioning for "
3687 + "rcs capability '" + capability + "', which does not require "
3688 + "provisioning.");
3689 }
3690 }
3691 } finally {
3692 Binder.restoreCallingIdentity(identity);
3693 }
3694
3695 }
3696
3697
3698 @Override
3699 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3700 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3701 final long identity = Binder.clearCallingIdentity();
3702 try {
3703 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3704 if (!isImsProvisioningRequired(subId, capability, false)) {
3705 return true;
3706 }
3707
3708 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3709 switch (capability) {
3710 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3711 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3712 return ims.isEabProvisionedOnDevice();
3713
3714 default: {
3715 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3716 + "capability '" + capability + "', which does not require "
3717 + "provisioning.");
3718 }
3719 }
3720
3721 } finally {
3722 Binder.restoreCallingIdentity(identity);
3723 }
3724 }
3725
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003726 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003727 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3728 boolean isProvisioned) {
3729 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3730 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3731 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3732 }
allenwtsu99c623b2020-01-03 18:24:23 +08003733 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003734 final long identity = Binder.clearCallingIdentity();
3735 try {
3736 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003737 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003738 return;
3739 }
3740
3741 // this capability requires provisioning, route to the correct API.
3742 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3743 switch (capability) {
3744 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3745 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3746 ims.setVolteProvisioned(isProvisioned);
3747 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3748 ims.setWfcProvisioned(isProvisioned);
3749 }
3750 break;
3751 }
3752 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3753 // There is currently no difference in VT provisioning type.
3754 ims.setVtProvisioned(isProvisioned);
3755 break;
3756 }
3757 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3758 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3759 // change the capability of the feature instead if needed.
3760 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3761 == isProvisioned) {
3762 // No change in provisioning.
3763 return;
3764 }
3765 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3766 try {
3767 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003768 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003769 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3770 + ", Exception" + e.getMessage());
3771 }
3772 break;
3773 }
3774 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003775 throw new IllegalArgumentException("Tried to set provisioning for "
3776 + "MmTel capability '" + capability + "', which does not require "
3777 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003778 }
3779 }
3780
3781 } finally {
3782 Binder.restoreCallingIdentity(identity);
3783 }
3784 }
3785
3786 @Override
3787 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3788 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3789 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3790 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3791 }
3792 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3793 final long identity = Binder.clearCallingIdentity();
3794 try {
3795 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003796 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003797 return true;
3798 }
3799
3800 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3801 switch (capability) {
3802 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3803 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3804 return ims.isVolteProvisionedOnDevice();
3805 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3806 return ims.isWfcProvisionedOnDevice();
3807 }
3808 // This should never happen, since we are checking tech above to make sure it
3809 // is either LTE or IWLAN.
3810 throw new IllegalArgumentException("Invalid radio technology for voice "
3811 + "capability.");
3812 }
3813 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3814 // There is currently no difference in VT provisioning type.
3815 return ims.isVtProvisionedOnDevice();
3816 }
3817 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3818 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3819 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3820 }
3821 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003822 throw new IllegalArgumentException(
3823 "Tried to get provisioning for MmTel capability '" + capability
3824 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003825 }
3826 }
3827
3828 } finally {
3829 Binder.restoreCallingIdentity(identity);
3830 }
3831 }
3832
3833 @Override
3834 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3835 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3836 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3837 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3838 }
3839 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3840 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3841 return (provisionedBits & capability) > 0;
3842 }
3843
3844 @Override
3845 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3846 boolean isProvisioned) {
3847 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3848 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3849 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3850 }
3851 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3852 "setProvisioningStatusForCapability");
3853 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3854 // If the current provisioning status for capability already matches isProvisioned,
3855 // do nothing.
3856 if (((provisionedBits & capability) > 0) == isProvisioned) {
3857 return;
3858 }
3859 if (isProvisioned) {
3860 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3861 } else {
3862 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3863 }
3864 }
3865
3866 /**
3867 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3868 * technology. The bitfield should mirror the bitfield defined by
3869 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3870 */
3871 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3872 String key = getMmTelProvisioningKey(subId, tech);
3873 // Default is no capabilities are provisioned.
3874 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3875 }
3876
3877 /**
3878 * Sets the MmTel capability provisioning bitfield (defined by
3879 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3880 * technology specified.
3881 *
3882 * Note: This is a synchronous command and should not be called on UI thread.
3883 */
3884 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3885 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3886 String key = getMmTelProvisioningKey(subId, tech);
3887 editor.putInt(key, newField);
3888 editor.commit();
3889 }
3890
3891 private static String getMmTelProvisioningKey(int subId, int tech) {
3892 // resulting key is provision_ims_mmtel_{subId}_{tech}
3893 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3894 }
3895
3896 /**
3897 * Query CarrierConfig to see if the specified capability requires provisioning for the
3898 * carrier associated with the subscription id.
3899 */
3900 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3901 int capability) {
3902 CarrierConfigManager configManager = new CarrierConfigManager(context);
3903 PersistableBundle c = configManager.getConfigForSubId(subId);
3904 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003905 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003906 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3907 false);
3908 boolean requireVoiceVtProvisioning = c.getBoolean(
3909 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3910
3911 // First check to make sure that the capability requires provisioning.
3912 switch (capability) {
3913 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3914 // intentional fallthrough
3915 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3916 if (requireVoiceVtProvisioning) {
3917 // Voice and Video requires provisioning
3918 return true;
3919 }
3920 break;
3921 }
3922 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3923 if (requireUtProvisioning) {
3924 // UT requires provisioning
3925 return true;
3926 }
3927 break;
3928 }
3929 }
3930 return false;
3931 }
3932
allenwtsu99c623b2020-01-03 18:24:23 +08003933 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
3934 int capability) {
3935 CarrierConfigManager configManager = new CarrierConfigManager(context);
3936 PersistableBundle c = configManager.getConfigForSubId(subId);
3937
3938 boolean requireRcsProvisioning = c.getBoolean(
3939 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
3940
3941 // First check to make sure that the capability requires provisioning.
3942 switch (capability) {
3943 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3944 // intentional fallthrough
3945 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
3946 if (requireRcsProvisioning) {
3947 // OPTION or PRESENCE requires provisioning
3948 return true;
3949 }
3950 break;
3951 }
3952 }
3953 return false;
3954 }
3955
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003956 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003957 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003958 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3959 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3960 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003961 enforceReadPrivilegedPermission("getImsProvisioningInt");
3962 final long identity = Binder.clearCallingIdentity();
3963 try {
3964 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003965 int slotId = getSlotIndex(subId);
3966 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3967 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3968 + subId + "' for key:" + key);
3969 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3970 }
3971 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003972 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003973 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3974 + subId + "' for key:" + key);
3975 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003976 } finally {
3977 Binder.restoreCallingIdentity(identity);
3978 }
3979 }
3980
3981 @Override
3982 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003983 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3984 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3985 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003986 enforceReadPrivilegedPermission("getImsProvisioningString");
3987 final long identity = Binder.clearCallingIdentity();
3988 try {
3989 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003990 int slotId = getSlotIndex(subId);
3991 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3992 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3993 + subId + "' for key:" + key);
3994 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3995 }
3996 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003997 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003998 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3999 + subId + "' for key:" + key);
4000 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004001 } finally {
4002 Binder.restoreCallingIdentity(identity);
4003 }
4004 }
4005
4006 @Override
4007 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004008 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4009 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4010 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4012 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004013 final long identity = Binder.clearCallingIdentity();
4014 try {
4015 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004016 int slotId = getSlotIndex(subId);
4017 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4018 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4019 + subId + "' for key:" + key);
4020 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4021 }
4022 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004023 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004024 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4025 + "' for key:" + key);
4026 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004027 } finally {
4028 Binder.restoreCallingIdentity(identity);
4029 }
4030 }
4031
4032 @Override
4033 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004034 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4035 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4036 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004037 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4038 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004039 final long identity = Binder.clearCallingIdentity();
4040 try {
4041 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004042 int slotId = getSlotIndex(subId);
4043 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4044 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4045 + subId + "' for key:" + key);
4046 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4047 }
4048 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004049 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004050 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4051 + "' for key:" + key);
4052 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004053 } finally {
4054 Binder.restoreCallingIdentity(identity);
4055 }
4056 }
4057
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004058 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004059 int slotId = SubscriptionManager.getSlotIndex(subId);
4060 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004061 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4062 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004063 }
4064 return slotId;
4065 }
4066
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004067 private int getSlotIndex(int subId) {
4068 int slotId = SubscriptionManager.getSlotIndex(subId);
4069 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4070 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4071 }
4072 return slotId;
4073 }
4074
Wink Saville36469e72014-06-11 15:17:00 -07004075 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004076 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004077 */
4078 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004079 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4080 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004081 final int targetSdk = getTargetSdk(callingPackage);
4082 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004083 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004084 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004085 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004086 mApp, subId, callingPackage, callingFeatureId,
4087 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004088 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4089 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004090
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004091 final long identity = Binder.clearCallingIdentity();
4092 try {
4093 final Phone phone = getPhone(subId);
4094 if (phone != null) {
4095 return phone.getServiceState().getDataNetworkType();
4096 } else {
4097 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4098 }
4099 } finally {
4100 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004101 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004102 }
4103
4104 /**
4105 * Returns the data network type
4106 */
4107 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004108 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4109 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4110 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004111 }
4112
4113 /**
4114 * Returns the data network type for a subId
4115 */
4116 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004117 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4118 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004119 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004120 mApp, subId, callingPackage, callingFeatureId,
4121 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004122 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4123 }
4124
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004125 final long identity = Binder.clearCallingIdentity();
4126 try {
4127 final Phone phone = getPhone(subId);
4128 if (phone != null) {
4129 return phone.getServiceState().getDataNetworkType();
4130 } else {
4131 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4132 }
4133 } finally {
4134 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004135 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004136 }
4137
4138 /**
Wink Saville36469e72014-06-11 15:17:00 -07004139 * Returns the Voice network type for a subId
4140 */
4141 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004142 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4143 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004144 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004145 mApp, subId, callingPackage, callingFeatureId,
4146 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004147 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4148 }
4149
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004150 final long identity = Binder.clearCallingIdentity();
4151 try {
4152 final Phone phone = getPhone(subId);
4153 if (phone != null) {
4154 return phone.getServiceState().getVoiceNetworkType();
4155 } else {
4156 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4157 }
4158 } finally {
4159 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004160 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004161 }
4162
4163 /**
4164 * @return true if a ICC card is present
4165 */
4166 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004167 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004168 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4169 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004170 }
4171
4172 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004173 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004174 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004175 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004176 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004177 final long identity = Binder.clearCallingIdentity();
4178 try {
4179 final Phone phone = PhoneFactory.getPhone(slotIndex);
4180 if (phone != null) {
4181 return phone.getIccCard().hasIccCard();
4182 } else {
4183 return false;
4184 }
4185 } finally {
4186 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004187 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004188 }
4189
4190 /**
4191 * Return if the current radio is LTE on CDMA. This
4192 * is a tri-state return value as for a period of time
4193 * the mode may be unknown.
4194 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004195 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004196 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004197 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004198 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004199 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004200 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4201 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4202 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004203 }
4204
Sanket Padawe356d7632015-06-22 14:03:32 -07004205 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004206 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4207 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004208 try {
4209 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4210 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004211 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4212 }
4213
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004214 final long identity = Binder.clearCallingIdentity();
4215 try {
4216 final Phone phone = getPhone(subId);
4217 if (phone == null) {
4218 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4219 } else {
4220 return phone.getLteOnCdmaMode();
4221 }
4222 } finally {
4223 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004224 }
Wink Saville36469e72014-06-11 15:17:00 -07004225 }
4226
Wink Saville36469e72014-06-11 15:17:00 -07004227 /**
4228 * {@hide}
4229 * Returns Default subId, 0 in the case of single standby.
4230 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004231 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004232 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004233 }
4234
Shishir Agrawala9f32182016-04-12 12:00:16 -07004235 private int getSlotForDefaultSubscription() {
4236 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4237 }
4238
Wink Savilleb564aae2014-10-23 10:18:09 -07004239 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004240 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004241 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004242
Pengquan Menge92a50d2018-09-21 15:54:48 -07004243 private boolean isActiveSubscription(int subId) {
4244 return mSubscriptionController.isActiveSubId(subId);
4245 }
4246
Ihab Awadf2177b72013-11-25 13:33:23 -08004247 /**
4248 * @see android.telephony.TelephonyManager.WifiCallingChoices
4249 */
4250 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004251 final long identity = Binder.clearCallingIdentity();
4252 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004253 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004254 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4255 getWhenToMakeWifiCallsDefaultPreference());
4256 } finally {
4257 Binder.restoreCallingIdentity(identity);
4258 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004259 }
4260
4261 /**
4262 * @see android.telephony.TelephonyManager.WifiCallingChoices
4263 */
4264 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004265 final long identity = Binder.clearCallingIdentity();
4266 try {
4267 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004268 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004269 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4270 } finally {
4271 Binder.restoreCallingIdentity(identity);
4272 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004273 }
4274
Sailesh Nepald1e68152013-12-12 19:08:02 -08004275 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004276 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004277 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004278 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004279
Jordan Liu4c733742019-02-28 12:03:40 -08004280 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4281 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4282 if (phoneId == -1) {
4283 throw new IllegalArgumentException("Given slot index: " + slotIndex
4284 + " does not correspond to an active phone");
4285 }
4286 return PhoneFactory.getPhone(phoneId);
4287 }
4288
Shishir Agrawal566b7612013-10-28 14:41:00 -07004289 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004290 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4291 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004292 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4293 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004294 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004295 if (DBG) {
4296 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4297 }
4298 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4299 p2);
4300 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004301
Jordan Liu4c733742019-02-28 12:03:40 -08004302
4303 @Override
4304 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4305 int slotIndex, String callingPackage, String aid, int p2) {
4306 enforceModifyPermission();
4307 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4308 if (DBG) {
4309 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4310 }
4311 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4312 callingPackage, aid, p2);
4313 }
4314
4315 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4316 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004317 final long identity = Binder.clearCallingIdentity();
4318 try {
4319 if (TextUtils.equals(ISDR_AID, aid)) {
4320 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004321 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4322 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004323 if (bestComponent == null
4324 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4325 loge("The calling package is not allowed to access ISD-R.");
4326 throw new SecurityException(
4327 "The calling package is not allowed to access ISD-R.");
4328 }
Derek Tan740e1672017-06-27 14:56:27 -07004329 }
Derek Tan740e1672017-06-27 14:56:27 -07004330
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004331 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004332 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4333 null /* workSource */);
4334 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004335 return response;
4336 } finally {
4337 Binder.restoreCallingIdentity(identity);
4338 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004339 }
4340
4341 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004342 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4344 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004345 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4346 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4347 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004348
Jordan Liu4c733742019-02-28 12:03:40 -08004349 @Override
4350 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4351 enforceModifyPermission();
4352 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4353 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4354 channel);
4355 }
4356
4357 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004358 final long identity = Binder.clearCallingIdentity();
4359 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004360 if (channel < 0) {
4361 return false;
4362 }
Jordan Liu4c733742019-02-28 12:03:40 -08004363 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4364 null /* workSource */);
4365 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004366 return success;
4367 } finally {
4368 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004369 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004370 }
4371
4372 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004373 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004374 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004375 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4376 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004377 if (DBG) {
4378 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4379 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4380 + p3 + " data=" + data);
4381 }
4382 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4383 command, p1, p2, p3, data);
4384 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004385
Jordan Liu4c733742019-02-28 12:03:40 -08004386 @Override
4387 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4388 int command, int p1, int p2, int p3, String data) {
4389 enforceModifyPermission();
4390 if (DBG) {
4391 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4392 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4393 + p3 + " data=" + data);
4394 }
4395 return iccTransmitApduLogicalChannelWithPermission(
4396 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4397 data);
4398 }
4399
4400 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4401 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004402 final long identity = Binder.clearCallingIdentity();
4403 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004404 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004405 return "";
4406 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004407
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004408 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004409 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4410 null /* workSource */);
4411 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004412
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004413 // Append the returned status code to the end of the response payload.
4414 String s = Integer.toHexString(
4415 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4416 if (response.payload != null) {
4417 s = IccUtils.bytesToHexString(response.payload) + s;
4418 }
4419 return s;
4420 } finally {
4421 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004422 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004423 }
Jake Hambye994d462014-02-03 13:10:13 -08004424
Evan Charltonc66da362014-05-16 14:06:40 -07004425 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004426 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4427 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004428 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4429 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004430 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004431 if (DBG) {
4432 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4433 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4434 }
4435 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4436 cla, command, p1, p2, p3, data);
4437 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004438
Jordan Liu4c733742019-02-28 12:03:40 -08004439 @Override
4440 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4441 int command, int p1, int p2, int p3, String data) {
4442 enforceModifyPermission();
4443 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4444 if (DBG) {
4445 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4446 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4447 + " data=" + data);
4448 }
4449
4450 return iccTransmitApduBasicChannelWithPermission(
4451 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4452 p2, p3, data);
4453 }
4454
4455 // open APDU basic channel assuming the caller has sufficient permissions
4456 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4457 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004458 final long identity = Binder.clearCallingIdentity();
4459 try {
4460 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4461 && TextUtils.equals(ISDR_AID, data)) {
4462 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004463 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4464 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004465 if (bestComponent == null
4466 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4467 loge("The calling package is not allowed to select ISD-R.");
4468 throw new SecurityException(
4469 "The calling package is not allowed to select ISD-R.");
4470 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004471 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004472
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004473 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004474 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4475 null /* workSource */);
4476 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004477
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004478 // Append the returned status code to the end of the response payload.
4479 String s = Integer.toHexString(
4480 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4481 if (response.payload != null) {
4482 s = IccUtils.bytesToHexString(response.payload) + s;
4483 }
4484 return s;
4485 } finally {
4486 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004487 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004488 }
4489
4490 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004491 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004492 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4494 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004495
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004496 final long identity = Binder.clearCallingIdentity();
4497 try {
4498 if (DBG) {
4499 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4500 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4501 }
4502
4503 IccIoResult response =
4504 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4505 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4506 subId);
4507
4508 if (DBG) {
4509 log("Exchange SIM_IO [R]" + response);
4510 }
4511
4512 byte[] result = null;
4513 int length = 2;
4514 if (response.payload != null) {
4515 length = 2 + response.payload.length;
4516 result = new byte[length];
4517 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4518 } else {
4519 result = new byte[length];
4520 }
4521
4522 result[length - 1] = (byte) response.sw2;
4523 result[length - 2] = (byte) response.sw1;
4524 return result;
4525 } finally {
4526 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004527 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004528 }
4529
Nathan Haroldb3014052017-01-25 15:57:32 -08004530 /**
4531 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4532 * on a particular subscription
4533 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004534 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4535 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004536 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004537 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004538 return null;
4539 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004540
4541 final long identity = Binder.clearCallingIdentity();
4542 try {
4543 if (appType != TelephonyManager.APPTYPE_USIM
4544 && appType != TelephonyManager.APPTYPE_SIM) {
4545 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4546 return null;
4547 }
4548 Object response = sendRequest(
4549 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4550 if (response instanceof String[]) {
4551 return (String[]) response;
4552 }
yincheng zhao2737e882019-09-06 17:06:54 -07004553 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004554 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004555 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004556 } finally {
4557 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004558 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004559 }
4560
yincheng zhao2737e882019-09-06 17:06:54 -07004561 /**
4562 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4563 * subscription.
4564 *
4565 * @param subId the id of the subscription.
4566 * @param appType the uicc app type, must be USIM or SIM.
4567 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4568 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004569 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004570 * @return number of fplmns that is successfully written to the SIM.
4571 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004572 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4573 String callingFeatureId) {
4574 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4575 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004576 if (DBG) logv("no permissions for setForbiddenplmns");
4577 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4578 }
4579 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4580 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4581 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4582 }
4583 if (fplmns == null) {
4584 throw new IllegalArgumentException("Fplmn List provided is null");
4585 }
4586 for (String fplmn : fplmns) {
4587 if (!CellIdentity.isValidPlmn(fplmn)) {
4588 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4589 }
4590 }
4591 final long identity = Binder.clearCallingIdentity();
4592 try {
4593 Object response = sendRequest(
4594 CMD_SET_FORBIDDEN_PLMNS,
4595 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4596 subId);
4597 return (int) response;
4598 } finally {
4599 Binder.restoreCallingIdentity(identity);
4600 }
4601 }
4602
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004603 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004604 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4606 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004607
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004608 final long identity = Binder.clearCallingIdentity();
4609 try {
4610 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4611 if (response.payload == null) {
4612 return "";
4613 }
Evan Charltonc66da362014-05-16 14:06:40 -07004614
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004615 // Append the returned status code to the end of the response payload.
4616 String s = Integer.toHexString(
4617 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4618 s = IccUtils.bytesToHexString(response.payload) + s;
4619 return s;
4620 } finally {
4621 Binder.restoreCallingIdentity(identity);
4622 }
Evan Charltonc66da362014-05-16 14:06:40 -07004623 }
4624
Jake Hambye994d462014-02-03 13:10:13 -08004625 /**
4626 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4627 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4628 *
4629 * @param itemID the ID of the item to read
4630 * @return the NV item as a String, or null on error.
4631 */
4632 @Override
4633 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004634 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004635 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4636 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004637
4638 final long identity = Binder.clearCallingIdentity();
4639 try {
4640 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004641 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004642 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4643 return value;
4644 } finally {
4645 Binder.restoreCallingIdentity(identity);
4646 }
Jake Hambye994d462014-02-03 13:10:13 -08004647 }
4648
4649 /**
4650 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4651 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4652 *
4653 * @param itemID the ID of the item to read
4654 * @param itemValue the value to write, as a String
4655 * @return true on success; false on any failure
4656 */
4657 @Override
4658 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004659 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4661 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004662
4663 final long identity = Binder.clearCallingIdentity();
4664 try {
4665 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4666 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004667 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004668 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4669 return success;
4670 } finally {
4671 Binder.restoreCallingIdentity(identity);
4672 }
Jake Hambye994d462014-02-03 13:10:13 -08004673 }
4674
4675 /**
4676 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4677 * Used for device configuration by some CDMA operators.
4678 *
4679 * @param preferredRoamingList byte array containing the new PRL
4680 * @return true on success; false on any failure
4681 */
4682 @Override
4683 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004684 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4685 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004686
4687 final long identity = Binder.clearCallingIdentity();
4688 try {
4689 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4690 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4691 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4692 return success;
4693 } finally {
4694 Binder.restoreCallingIdentity(identity);
4695 }
Jake Hambye994d462014-02-03 13:10:13 -08004696 }
4697
4698 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004699 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004700 * Used for device configuration by some CDMA operators.
4701 *
chen xu6dac5ab2018-10-26 17:39:23 -07004702 * @param slotIndex - device slot.
4703 *
Jake Hambye994d462014-02-03 13:10:13 -08004704 * @return true on success; false on any failure
4705 */
4706 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004707 public boolean resetModemConfig(int slotIndex) {
4708 Phone phone = PhoneFactory.getPhone(slotIndex);
4709 if (phone != null) {
4710 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4711 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004712
chen xu6dac5ab2018-10-26 17:39:23 -07004713 final long identity = Binder.clearCallingIdentity();
4714 try {
4715 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4716 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4717 return success;
4718 } finally {
4719 Binder.restoreCallingIdentity(identity);
4720 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004721 }
chen xu6dac5ab2018-10-26 17:39:23 -07004722 return false;
4723 }
4724
4725 /**
4726 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4727 *
4728 * @param slotIndex - device slot.
4729 *
4730 * @return true on success; false on any failure
4731 */
4732 @Override
4733 public boolean rebootModem(int slotIndex) {
4734 Phone phone = PhoneFactory.getPhone(slotIndex);
4735 if (phone != null) {
4736 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4737 mApp, phone.getSubId(), "rebootModem");
4738
4739 final long identity = Binder.clearCallingIdentity();
4740 try {
4741 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4742 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4743 return success;
4744 } finally {
4745 Binder.restoreCallingIdentity(identity);
4746 }
4747 }
4748 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004749 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004750
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004751 public String[] getPcscfAddress(String apnType, String callingPackage,
4752 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004753 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004754 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4755 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004756 return new String[0];
4757 }
4758
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004759 final long identity = Binder.clearCallingIdentity();
4760 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004761 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004762 } finally {
4763 Binder.restoreCallingIdentity(identity);
4764 }
Wink Saville36469e72014-06-11 15:17:00 -07004765 }
4766
Brad Ebinger51f743a2017-01-23 13:50:20 -08004767 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004768 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4769 * {@link #disableIms(int)}.
4770 * @param slotIndex device slot.
4771 */
4772 public void resetIms(int slotIndex) {
4773 enforceModifyPermission();
4774
4775 final long identity = Binder.clearCallingIdentity();
4776 try {
4777 if (mImsResolver == null) {
4778 // may happen if the does not support IMS.
4779 return;
4780 }
4781 mImsResolver.disableIms(slotIndex);
4782 mImsResolver.enableIms(slotIndex);
4783 } finally {
4784 Binder.restoreCallingIdentity(identity);
4785 }
4786 }
4787
4788 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004789 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4790 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004791 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004792 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004793 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004794
4795 final long identity = Binder.clearCallingIdentity();
4796 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004797 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004798 // may happen if the device does not support IMS.
4799 return;
4800 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004801 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004802 } finally {
4803 Binder.restoreCallingIdentity(identity);
4804 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004805 }
4806
4807 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004808 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4809 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004810 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004811 public void disableIms(int slotId) {
4812 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004813
4814 final long identity = Binder.clearCallingIdentity();
4815 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004816 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004817 // may happen if the device does not support IMS.
4818 return;
4819 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004820 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004821 } finally {
4822 Binder.restoreCallingIdentity(identity);
4823 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004824 }
4825
4826 /**
4827 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4828 * feature or {@link null} if the service is not available. If the feature is available, the
4829 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4830 */
4831 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004832 IImsServiceFeatureCallback callback) {
4833 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004834
4835 final long identity = Binder.clearCallingIdentity();
4836 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004837 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004838 // may happen if the device does not support IMS.
4839 return null;
4840 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004841 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004842 } finally {
4843 Binder.restoreCallingIdentity(identity);
4844 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004845 }
4846
4847 /**
4848 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4849 * feature during emergency calling or {@link null} if the service is not available. If the
4850 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4851 * listener for feature updates.
4852 */
4853 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4854 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004855
4856 final long identity = Binder.clearCallingIdentity();
4857 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004858 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004859 // may happen if the device does not support IMS.
4860 return null;
4861 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004862 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004863 } finally {
4864 Binder.restoreCallingIdentity(identity);
4865 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004866 }
4867
Brad Ebinger5f64b052017-12-14 14:26:15 -08004868 /**
4869 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004870 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004871 */
4872 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4873 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004874
4875 final long identity = Binder.clearCallingIdentity();
4876 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004877 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004878 // may happen if the device does not support IMS.
4879 return null;
4880 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004881 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004882 } finally {
4883 Binder.restoreCallingIdentity(identity);
4884 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004885 }
4886
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004887 /**
4888 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004889 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004890 */
4891 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4892 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004893
4894 final long identity = Binder.clearCallingIdentity();
4895 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004896 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004897 // may happen if the device does not support IMS.
4898 return null;
4899 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004900 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004901 } finally {
4902 Binder.restoreCallingIdentity(identity);
4903 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004904 }
4905
Brad Ebinger884c07b2018-02-15 16:17:40 -08004906 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004907 * Sets the ImsService Package Name that Telephony will bind to.
4908 *
Brad Ebinger24c29992019-12-05 13:03:21 -08004909 * @param slotIndex the slot ID that the ImsService should bind for.
4910 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004911 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08004912 * @param featureTypes An integer array of feature types associated with a packageName.
4913 * @param packageName The name of the package that the current configuration will be replaced
4914 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004915 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004916 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004917 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4918 int[] featureTypes, String packageName) {
4919 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4920 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004921 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4922 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08004923 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004924
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004925 final long identity = Binder.clearCallingIdentity();
4926 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004927 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004928 // may happen if the device does not support IMS.
4929 return false;
4930 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004931 Map<Integer, String> featureConfig = new HashMap<>();
4932 for (int featureType : featureTypes) {
4933 featureConfig.put(featureType, packageName);
4934 }
4935 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4936 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004937 } finally {
4938 Binder.restoreCallingIdentity(identity);
4939 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004940 }
4941
4942 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08004943 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004944 *
4945 * @param slotId The slot that the ImsService is associated with.
4946 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4947 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08004948 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004949 * @return the package name of the ImsService configuration.
4950 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004951 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4952 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004953 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08004954 TelephonyPermissions
4955 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4956 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4957 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004958
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004959 final long identity = Binder.clearCallingIdentity();
4960 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004961 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004962 // may happen if the device does not support IMS.
4963 return "";
4964 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004965 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08004966 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4967 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004968 } finally {
4969 Binder.restoreCallingIdentity(identity);
4970 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004971 }
4972
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004973 /**
4974 * Get the MmTelFeature state associated with the requested subscription id.
4975 * @param subId The subscription that the MmTelFeature is associated with.
4976 * @param callback A callback with an integer containing the
4977 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4978 */
4979 @Override
4980 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4981 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4982 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4983 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4984 "IMS not available on device.");
4985 }
4986 final long token = Binder.clearCallingIdentity();
4987 try {
4988 int slotId = getSlotIndex(subId);
4989 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4990 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4991 + subId + "'");
4992 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4993 }
4994 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4995 try {
4996 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4997 } catch (RemoteException e) {
4998 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4999 + "Ignore");
5000 }
5001 });
5002 } finally {
5003 Binder.restoreCallingIdentity(token);
5004 }
5005 }
5006
Wink Saville36469e72014-06-11 15:17:00 -07005007 public void setImsRegistrationState(boolean registered) {
5008 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005009
5010 final long identity = Binder.clearCallingIdentity();
5011 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005012 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005013 } finally {
5014 Binder.restoreCallingIdentity(identity);
5015 }
Wink Saville36469e72014-06-11 15:17:00 -07005016 }
5017
5018 /**
Stuart Scott54788802015-03-30 13:18:01 -07005019 * Set the network selection mode to automatic.
5020 *
5021 */
5022 @Override
5023 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005024 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5025 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005026
5027 final long identity = Binder.clearCallingIdentity();
5028 try {
shilufc958392020-01-20 11:36:01 -08005029 if (!isActiveSubscription(subId)) {
5030 return;
5031 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005032 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5033 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5034 } finally {
5035 Binder.restoreCallingIdentity(identity);
5036 }
Stuart Scott54788802015-03-30 13:18:01 -07005037 }
5038
Pengquan Mengea84e042018-09-20 14:57:26 -07005039 /**
5040 * Ask the radio to connect to the input network and change selection mode to manual.
5041 *
5042 * @param subId the id of the subscription.
5043 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5044 * the operator to attach to.
5045 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5046 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5047 * normal network selection next time.
5048 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005049 */
5050 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005051 public boolean setNetworkSelectionModeManual(
5052 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005053 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5054 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005055
5056 if (!isActiveSubscription(subId)) {
5057 return false;
5058 }
5059
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005060 final long identity = Binder.clearCallingIdentity();
5061 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005062 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005063 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005064 if (DBG) {
5065 log("setNetworkSelectionModeManual: subId: " + subId
5066 + " operator: " + operatorInfo);
5067 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005068 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5069 } finally {
5070 Binder.restoreCallingIdentity(identity);
5071 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005072 }
shilu84f6e8b2019-12-19 13:58:01 -08005073 /**
5074 * Get the manual network selection
5075 *
5076 * @param subId the id of the subscription.
5077 *
5078 * @return the previously saved user selected PLMN
5079 */
5080 @Override
5081 public String getManualNetworkSelectionPlmn(int subId) {
5082 TelephonyPermissions
5083 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5084 mApp, subId, "getManualNetworkSelectionPlmn");
5085
5086 final long identity = Binder.clearCallingIdentity();
5087 try {
5088 if (!isActiveSubscription(subId)) {
5089 return "";
5090 }
5091
5092 final Phone phone = getPhone(subId);
5093 if (phone == null) {
5094 return "";
5095 }
5096 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5097 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5098 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5099 } finally {
5100 Binder.restoreCallingIdentity(identity);
5101 }
5102 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005103
5104 /**
5105 * Scans for available networks.
5106 */
5107 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005108 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5109 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5111 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005112 LocationAccessPolicy.LocationPermissionResult locationResult =
5113 LocationAccessPolicy.checkLocationPermission(mApp,
5114 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5115 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005116 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005117 .setCallingPid(Binder.getCallingPid())
5118 .setCallingUid(Binder.getCallingUid())
5119 .setMethod("getCellNetworkScanResults")
5120 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5121 .build());
5122 switch (locationResult) {
5123 case DENIED_HARD:
5124 throw new SecurityException("Not allowed to access scan results -- location");
5125 case DENIED_SOFT:
5126 return null;
5127 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005128
Pengquan Menga1bb6272018-09-06 09:59:22 -07005129 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005130 try {
5131 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005132 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005133 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005134 } finally {
5135 Binder.restoreCallingIdentity(identity);
5136 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005137 }
5138
5139 /**
yinxub1bed742017-04-17 11:45:04 -07005140 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005141 *
yinxub1bed742017-04-17 11:45:04 -07005142 * @param subId id of the subscription
5143 * @param request contains the radio access networks with bands/channels to scan
5144 * @param messenger callback messenger for scan results or errors
5145 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005146 * @return the id of the requested scan which can be used to stop the scan.
5147 */
5148 @Override
5149 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005150 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5152 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005153 LocationAccessPolicy.LocationPermissionResult locationResult =
5154 LocationAccessPolicy.checkLocationPermission(mApp,
5155 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5156 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005157 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005158 .setCallingPid(Binder.getCallingPid())
5159 .setCallingUid(Binder.getCallingUid())
5160 .setMethod("requestNetworkScan")
5161 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5162 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005163 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005164 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005165 if (e != null) {
5166 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5167 throw e;
5168 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005169 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005170 return TelephonyScanManager.INVALID_SCAN_ID;
5171 }
5172 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005173 }
Hall Liu912dfd32019-04-25 14:02:26 -07005174 int callingUid = Binder.getCallingUid();
5175 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005176 final long identity = Binder.clearCallingIdentity();
5177 try {
5178 return mNetworkScanRequestTracker.startNetworkScan(
5179 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005180 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005181 } finally {
5182 Binder.restoreCallingIdentity(identity);
5183 }
yinxu504e1392017-04-12 16:03:22 -07005184 }
5185
Hall Liub2ac8ef2019-02-28 15:56:23 -08005186 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005187 NetworkScanRequest request, int subId) {
5188 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5189 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5190 boolean hasNetworkScanPermission =
5191 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5192 == PERMISSION_GRANTED;
5193
5194 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5195 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5196 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005197 }
5198
5199 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5200 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005201 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5202 return new SecurityException("Specific channels must not be"
5203 + " scanned without location access.");
5204 }
5205 }
5206 }
5207
Hall Liub2ac8ef2019-02-28 15:56:23 -08005208 return null;
5209 }
5210
yinxu504e1392017-04-12 16:03:22 -07005211 /**
5212 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005213 *
5214 * @param subId id of the subscription
5215 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005216 */
5217 @Override
5218 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5220 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005221
Hall Liu912dfd32019-04-25 14:02:26 -07005222 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005223 final long identity = Binder.clearCallingIdentity();
5224 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005225 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005226 } finally {
5227 Binder.restoreCallingIdentity(identity);
5228 }
yinxu504e1392017-04-12 16:03:22 -07005229 }
5230
5231 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005232 * Get the calculated preferred network type.
5233 * Used for debugging incorrect network type.
5234 *
5235 * @return the preferred network type, defined in RILConstants.java.
5236 */
5237 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005238 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005239 final Phone defaultPhone = getDefaultPhone();
5240 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005241 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005242 return RILConstants.PREFERRED_NETWORK_MODE;
5243 }
5244
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005245 final long identity = Binder.clearCallingIdentity();
5246 try {
5247 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005248 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005249 } finally {
5250 Binder.restoreCallingIdentity(identity);
5251 }
Junda Liu84d15a22014-07-02 11:21:04 -07005252 }
5253
5254 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005255 * Get the preferred network type.
5256 * Used for device configuration by some CDMA operators.
5257 *
5258 * @return the preferred network type, defined in RILConstants.java.
5259 */
5260 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005261 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005262 TelephonyPermissions
5263 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5264 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005265
5266 final long identity = Binder.clearCallingIdentity();
5267 try {
5268 if (DBG) log("getPreferredNetworkType");
5269 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5270 int networkType = (result != null ? result[0] : -1);
5271 if (DBG) log("getPreferredNetworkType: " + networkType);
5272 return networkType;
5273 } finally {
5274 Binder.restoreCallingIdentity(identity);
5275 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005276 }
5277
5278 /**
5279 * Set the preferred network type.
5280 * Used for device configuration by some CDMA operators.
5281 *
5282 * @param networkType the preferred network type, defined in RILConstants.java.
5283 * @return true on success; false on any failure.
5284 */
5285 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005286 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005287 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5288 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005289
5290 final long identity = Binder.clearCallingIdentity();
5291 try {
calvinpan0ac9c1a2020-01-14 20:42:55 +08005292 Settings.Global.putInt(mApp.getContentResolver(),
5293 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5294 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005295 } finally {
5296 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005297 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005298 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005299
5300 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005301 * Get the allowed network types that store in the telephony provider.
5302 *
5303 * @param subId the id of the subscription.
5304 * @return allowedNetworkTypes the allowed network types.
5305 */
5306 @Override
5307 public long getAllowedNetworkTypes(int subId) {
5308 TelephonyPermissions
5309 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5310 mApp, subId, "getAllowedNetworkTypes");
5311
5312 final long identity = Binder.clearCallingIdentity();
5313 try {
5314 return SubscriptionManager.getLongSubscriptionProperty(
5315 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5316 } finally {
5317 Binder.restoreCallingIdentity(identity);
5318 }
5319 }
5320
5321 /**
5322 * Set the allowed network types.
5323 *
5324 * @param subId the id of the subscription.
5325 * @param allowedNetworkTypes the allowed network types.
5326 * @return true on success; false on any failure.
5327 */
5328 @Override
5329 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5330 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5331 mApp, subId, "setAllowedNetworkTypes");
5332 final long identity = Binder.clearCallingIdentity();
5333 try {
5334 SubscriptionManager.setSubscriptionProperty(subId,
5335 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5336 String.valueOf(allowedNetworkTypes));
5337 return setPreferredNetworkTypesInternal(subId);
5338 } finally {
5339 Binder.restoreCallingIdentity(identity);
5340 }
5341 }
5342
5343 private boolean setPreferredNetworkTypesInternal(int subId) {
5344 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5345 Settings.Global.getInt(mApp.getContentResolver(),
5346 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5347 RILConstants.PREFERRED_NETWORK_MODE));
5348 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5349 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5350 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5351 (int) (networkTypeBitMask & allowedNetworkTypes));
5352
5353 if (DBG) {
5354 log("setPreferredNetworkTypesInternal: subId " + subId
5355 + " networkTypes " + networkTypeBitMask
5356 + " allowedNetworkTypes " + allowedNetworkTypes
5357 + " networkMode " + networkMode);
5358 }
5359
5360 Boolean success = (Boolean) sendRequest(
5361 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5362 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5363 return success;
5364 }
5365
5366 /**
Miaoa84611c2019-03-15 09:21:10 +08005367 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005368 *
Miaoa84611c2019-03-15 09:21:10 +08005369 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005370 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005371 * @hide
5372 */
5373 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005374 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005375 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005376 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005377 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005378 try {
Miaoa84611c2019-03-15 09:21:10 +08005379 if (phone != null) {
5380 return phone.hasMatchedTetherApnSetting();
5381 } else {
5382 return false;
5383 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005384 } finally {
5385 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005386 }
Junda Liu475951f2014-11-07 16:45:03 -08005387 }
5388
5389 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005390 * Set mobile data enabled
5391 * Used by the user through settings etc to turn on/off mobile data
5392 *
5393 * @param enable {@code true} turn turn data on, else {@code false}
5394 */
5395 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005396 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005397 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5398 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005399
5400 final long identity = Binder.clearCallingIdentity();
5401 try {
5402 int phoneId = mSubscriptionController.getPhoneId(subId);
5403 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5404 Phone phone = PhoneFactory.getPhone(phoneId);
5405 if (phone != null) {
5406 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005407 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005408 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005409 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410 }
5411 } finally {
5412 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005413 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005414 }
5415
5416 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005417 * Enable or disable always reporting signal strength changes from radio.
5418 *
5419 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5420 */
5421 @Override
5422 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5423 enforceModifyPermission();
5424 enforceSystemCaller();
5425
5426 final long identity = Binder.clearCallingIdentity();
5427 final Phone phone = getPhone(subId);
5428 try {
5429 if (phone != null) {
5430 if (DBG) {
5431 log("setAlwaysReportSignalStrength: subId=" + subId
5432 + " isEnable=" + isEnable);
5433 }
5434 phone.setAlwaysReportSignalStrength(isEnable);
5435 } else {
5436 loge("setAlwaysReportSignalStrength: no phone found for subId="
5437 + subId);
5438 }
5439 } finally {
5440 Binder.restoreCallingIdentity(identity);
5441 }
5442 }
5443
5444 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005445 * Get the user enabled state of Mobile Data.
5446 *
5447 * TODO: remove and use isUserDataEnabled.
5448 * This can't be removed now because some vendor codes
5449 * calls through ITelephony directly while they should
5450 * use TelephonyManager.
5451 *
5452 * @return true on enabled
5453 */
5454 @Override
5455 public boolean getDataEnabled(int subId) {
5456 return isUserDataEnabled(subId);
5457 }
5458
5459 /**
5460 * Get whether mobile data is enabled per user setting.
5461 *
5462 * There are other factors deciding whether mobile data is actually enabled, but they are
5463 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005464 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005465 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005466 *
5467 * @return {@code true} if data is enabled else {@code false}
5468 */
5469 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005470 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005471 try {
5472 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5473 null);
5474 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5476 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005477 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005478
5479 final long identity = Binder.clearCallingIdentity();
5480 try {
5481 int phoneId = mSubscriptionController.getPhoneId(subId);
5482 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5483 Phone phone = PhoneFactory.getPhone(phoneId);
5484 if (phone != null) {
5485 boolean retVal = phone.isUserDataEnabled();
5486 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5487 return retVal;
5488 } else {
5489 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5490 return false;
5491 }
5492 } finally {
5493 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005494 }
5495 }
5496
5497 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005498 * Checks if the device is capable of mobile data by considering whether whether the
5499 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5500 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005501 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005502 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005503 */
5504 @Override
5505 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005506 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005507
5508 final long identity = Binder.clearCallingIdentity();
5509 try {
5510 int phoneId = mSubscriptionController.getPhoneId(subId);
5511 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5512 Phone phone = PhoneFactory.getPhone(phoneId);
5513 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005514 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005515 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5516 return retVal;
5517 } else {
5518 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5519 return false;
5520 }
5521 } finally {
5522 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005523 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005524 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005525
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005526 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5527 Phone phone) {
5528 //load access rules from carrier configs, and check those as well: b/139133814
5529 SubscriptionController subController = SubscriptionController.getInstance();
5530 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5531 || subController == null) return privilegeFromSim;
5532
5533 int uid = Binder.getCallingUid();
5534 PackageManager pkgMgr = phone.getContext().getPackageManager();
5535 String[] packages = pkgMgr.getPackagesForUid(uid);
5536
5537 final long identity = Binder.clearCallingIdentity();
5538 try {
5539 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5540 SubscriptionManager subManager = (SubscriptionManager)
5541 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5542 for (String pkg : packages) {
5543 if (subManager.canManageSubscription(subInfo, pkg)) {
5544 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5545 }
5546 }
5547 return privilegeFromSim;
5548 } finally {
5549 Binder.restoreCallingIdentity(identity);
5550 }
5551 }
5552
5553 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5554 String pkgName) {
5555 //load access rules from carrier configs, and check those as well: b/139133814
5556 SubscriptionController subController = SubscriptionController.getInstance();
5557 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5558 || subController == null) return privilegeFromSim;
5559
5560 final long identity = Binder.clearCallingIdentity();
5561 try {
5562 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5563 SubscriptionManager subManager = (SubscriptionManager)
5564 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5565 return subManager.canManageSubscription(subInfo, pkgName)
5566 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5567 } finally {
5568 Binder.restoreCallingIdentity(identity);
5569 }
5570 }
5571
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005572 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005573 public int getCarrierPrivilegeStatus(int subId) {
5574 final Phone phone = getPhone(subId);
5575 if (phone == null) {
5576 loge("getCarrierPrivilegeStatus: Invalid subId");
5577 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5578 }
5579 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005580 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005581 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005582 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5583 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005584
5585 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5586 card.getCarrierPrivilegeStatusForCurrentTransaction(
5587 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005588 }
Junda Liu29340342014-07-10 15:23:27 -07005589
5590 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005591 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005592 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005593 final Phone phone = getPhone(subId);
5594 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005595 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005596 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5597 }
5598 UiccProfile profile =
5599 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5600 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005601 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005602 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5603 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005604 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005605 profile.getCarrierPrivilegeStatusForUid(
5606 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005607 }
5608
5609 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005610 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5611 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005612 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005613 }
5614
5615 int phoneId = SubscriptionManager.getPhoneId(subId);
5616 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005617 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005618 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005619 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5620 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005621 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5622 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5623 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005624 }
5625
5626 @Override
5627 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005628 if (TextUtils.isEmpty(pkgName))
5629 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005630 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5631 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5632 UiccCard card = UiccController.getInstance().getUiccCard(i);
5633 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005634 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005635 continue;
5636 }
5637
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005638 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5639 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5640 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005641 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5642 break;
5643 }
5644 }
5645
5646 return result;
Junda Liu29340342014-07-10 15:23:27 -07005647 }
Derek Tan89e89d42014-07-08 17:00:10 -07005648
5649 @Override
Junda Liue64de782015-04-16 17:19:16 -07005650 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5651 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5652 loge("phoneId " + phoneId + " is not valid.");
5653 return null;
5654 }
5655 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005656 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005657 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005658 return null ;
5659 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005660 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005661 }
5662
Amith Yamasani6e118872016-02-19 12:53:51 -08005663 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005664 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005665 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005666 List<String> privilegedPackages = new ArrayList<>();
5667 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005668 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5669 // has UICC in that slot.
5670 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005671 if (card.hasCarrierPrivilegeRules()) {
5672 if (packages == null) {
5673 // Only check packages in user 0 for now
5674 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005675 PackageManager.MATCH_DISABLED_COMPONENTS
5676 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005677 | PackageManager.GET_SIGNING_CERTIFICATES,
5678 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005679 }
5680 for (int p = packages.size() - 1; p >= 0; p--) {
5681 PackageInfo pkgInfo = packages.get(p);
5682 if (pkgInfo != null && pkgInfo.packageName != null
5683 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005684 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005685 privilegedPackages.add(pkgInfo.packageName);
5686 }
5687 }
5688 }
5689 }
5690 return privilegedPackages;
5691 }
5692
chen xuf7e9fe82019-05-09 19:31:02 -07005693 @Override
5694 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005695 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5696
5697 final long identity = Binder.clearCallingIdentity();
5698
chen xuf7e9fe82019-05-09 19:31:02 -07005699 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005700 try {
5701 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5702 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5703 }
5704 } finally {
5705 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005706 }
5707 return privilegedPackages;
5708 }
5709
Wink Savilleb564aae2014-10-23 10:18:09 -07005710 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005711 final Phone phone = getPhone(subId);
5712 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005713 if (card == null) {
5714 loge("getIccId: No UICC");
5715 return null;
5716 }
5717 String iccId = card.getIccId();
5718 if (TextUtils.isEmpty(iccId)) {
5719 loge("getIccId: ICC ID is null or empty.");
5720 return null;
5721 }
5722 return iccId;
5723 }
5724
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005725 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005726 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5727 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005728 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005729 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005730
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005731 final long identity = Binder.clearCallingIdentity();
5732 try {
5733 final String iccId = getIccId(subId);
5734 final Phone phone = getPhone(subId);
5735 if (phone == null) {
5736 return false;
5737 }
5738 final String subscriberId = phone.getSubscriberId();
5739
5740 if (DBG_MERGE) {
5741 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5742 + subscriberId + " to " + number);
5743 }
5744
5745 if (TextUtils.isEmpty(iccId)) {
5746 return false;
5747 }
5748
5749 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5750
5751 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5752 if (alphaTag == null) {
5753 editor.remove(alphaTagPrefKey);
5754 } else {
5755 editor.putString(alphaTagPrefKey, alphaTag);
5756 }
5757
5758 // Record both the line number and IMSI for this ICCID, since we need to
5759 // track all merged IMSIs based on line number
5760 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5761 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5762 if (number == null) {
5763 editor.remove(numberPrefKey);
5764 editor.remove(subscriberPrefKey);
5765 } else {
5766 editor.putString(numberPrefKey, number);
5767 editor.putString(subscriberPrefKey, subscriberId);
5768 }
5769
5770 editor.commit();
5771 return true;
5772 } finally {
5773 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005774 }
Derek Tan7226c842014-07-02 17:42:23 -07005775 }
5776
5777 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005778 public String getLine1NumberForDisplay(int subId, String callingPackage,
5779 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005780 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005781 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005782 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005783 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005784 return null;
5785 }
Derek Tan97ebb422014-09-05 16:55:38 -07005786
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005787 final long identity = Binder.clearCallingIdentity();
5788 try {
5789 String iccId = getIccId(subId);
5790 if (iccId != null) {
5791 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5792 if (DBG_MERGE) {
5793 log("getLine1NumberForDisplay returning "
5794 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5795 }
5796 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005797 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005798 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5799 return null;
5800 } finally {
5801 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005802 }
Derek Tan7226c842014-07-02 17:42:23 -07005803 }
5804
5805 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005806 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5807 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005808 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005809 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005810 return null;
5811 }
Derek Tan97ebb422014-09-05 16:55:38 -07005812
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005813 final long identity = Binder.clearCallingIdentity();
5814 try {
5815 String iccId = getIccId(subId);
5816 if (iccId != null) {
5817 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5818 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5819 }
5820 return null;
5821 } finally {
5822 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005823 }
Derek Tan7226c842014-07-02 17:42:23 -07005824 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005825
5826 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005827 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5828 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005829 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5830 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005831 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005832 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005833 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005834 return null;
5835 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005836
Jordan Liub49b04b2019-05-06 14:45:15 -07005837 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5838 // the process, where TelephonyManager was instantiated.
5839 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005840 final long identity = Binder.clearCallingIdentity();
5841 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005842 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005843 final TelephonyManager tele = TelephonyManager.from(context);
5844 final SubscriptionManager sub = SubscriptionManager.from(context);
5845
5846 // Figure out what subscribers are currently active
5847 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005848
Jordan Liub49b04b2019-05-06 14:45:15 -07005849 // Only consider subs which match the current subId
5850 // This logic can be simplified. See b/131189269 for progress.
5851 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005852 activeSubscriberIds.add(tele.getSubscriberId(subId));
5853 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005854
5855 // First pass, find a number override for an active subscriber
5856 String mergeNumber = null;
5857 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5858 for (String key : prefs.keySet()) {
5859 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5860 final String subscriberId = (String) prefs.get(key);
5861 if (activeSubscriberIds.contains(subscriberId)) {
5862 final String iccId = key.substring(
5863 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5864 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5865 mergeNumber = (String) prefs.get(numberKey);
5866 if (DBG_MERGE) {
5867 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5868 + " for active subscriber " + subscriberId);
5869 }
5870 if (!TextUtils.isEmpty(mergeNumber)) {
5871 break;
5872 }
5873 }
5874 }
5875 }
5876
5877 // Shortcut when no active merged subscribers
5878 if (TextUtils.isEmpty(mergeNumber)) {
5879 return null;
5880 }
5881
5882 // Second pass, find all subscribers under that line override
5883 final ArraySet<String> result = new ArraySet<>();
5884 for (String key : prefs.keySet()) {
5885 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5886 final String number = (String) prefs.get(key);
5887 if (mergeNumber.equals(number)) {
5888 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5889 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5890 final String subscriberId = (String) prefs.get(subscriberKey);
5891 if (!TextUtils.isEmpty(subscriberId)) {
5892 result.add(subscriberId);
5893 }
5894 }
5895 }
5896 }
5897
5898 final String[] resultArray = result.toArray(new String[result.size()]);
5899 Arrays.sort(resultArray);
5900 if (DBG_MERGE) {
5901 Slog.d(LOG_TAG,
5902 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5903 }
5904 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005905 } finally {
5906 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005907 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005908 }
5909
5910 @Override
zoey chen38003472019-12-13 17:16:31 +08005911 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
5912 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07005913
5914 final long identity = Binder.clearCallingIdentity();
5915 try {
5916 final TelephonyManager telephonyManager = mApp.getSystemService(
5917 TelephonyManager.class);
5918 String subscriberId = telephonyManager.getSubscriberId(subId);
5919 if (subscriberId == null) {
5920 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08005921 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07005922 + subId);
5923 }
5924 return null;
5925 }
5926
5927 final SubscriptionInfo info = SubscriptionController.getInstance()
5928 .getSubscriptionInfo(subId);
5929 final ParcelUuid groupUuid = info.getGroupUuid();
5930 // If it doesn't belong to any group, return just subscriberId of itself.
5931 if (groupUuid == null) {
5932 return new String[]{subscriberId};
5933 }
5934
5935 // Get all subscriberIds from the group.
5936 final List<String> mergedSubscriberIds = new ArrayList<>();
5937 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005938 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5939 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005940 for (SubscriptionInfo subInfo : groupInfos) {
5941 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5942 if (subscriberId != null) {
5943 mergedSubscriberIds.add(subscriberId);
5944 }
5945 }
5946
5947 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5948 } finally {
5949 Binder.restoreCallingIdentity(identity);
5950
5951 }
5952 }
5953
5954 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005955 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005956 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005957 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005958
5959 final long identity = Binder.clearCallingIdentity();
5960 try {
5961 final Phone phone = getPhone(subId);
5962 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5963 } finally {
5964 Binder.restoreCallingIdentity(identity);
5965 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005966 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005967
5968 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005969 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005970 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5971 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005972 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5973 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005974
5975 final long identity = Binder.clearCallingIdentity();
5976 try {
5977 final Phone phone = getPhone(subId);
5978 if (phone == null) {
5979 return false;
5980 }
5981 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5982 cdmaNonRoamingList);
5983 } finally {
5984 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005985 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005986 }
5987
5988 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005989 @Deprecated
5990 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5991 enforceModifyPermission();
5992
5993 int returnValue = 0;
5994 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005995 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005996 if(result.exception == null) {
5997 if (result.result != null) {
5998 byte[] responseData = (byte[])(result.result);
5999 if(responseData.length > oemResp.length) {
6000 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6001 responseData.length + "bytes. Buffer Size is " +
6002 oemResp.length + "bytes.");
6003 }
6004 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6005 returnValue = responseData.length;
6006 }
6007 } else {
6008 CommandException ex = (CommandException) result.exception;
6009 returnValue = ex.getCommandError().ordinal();
6010 if(returnValue > 0) returnValue *= -1;
6011 }
6012 } catch (RuntimeException e) {
6013 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6014 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6015 if(returnValue > 0) returnValue *= -1;
6016 }
6017
6018 return returnValue;
6019 }
6020
6021 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006022 public void setRadioCapability(RadioAccessFamily[] rafs) {
6023 try {
6024 ProxyController.getInstance().setRadioCapability(rafs);
6025 } catch (RuntimeException e) {
6026 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6027 }
6028 }
6029
6030 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006031 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006032 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006033 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006034 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006035 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006036 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006037 final long identity = Binder.clearCallingIdentity();
6038 try {
chen xub97461a2018-10-26 14:17:57 -07006039 TelephonyPermissions
6040 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6041 mApp, phone.getSubId(), "getRadioAccessFamily");
6042 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006043 } finally {
6044 Binder.restoreCallingIdentity(identity);
6045 }
chen xub97461a2018-10-26 14:17:57 -07006046 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006047 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006048
6049 @Override
6050 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006051 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006052 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006053
6054 final long identity = Binder.clearCallingIdentity();
6055 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006056 ImsManager.getInstance(defaultPhone.getContext(),
6057 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006058 } finally {
6059 Binder.restoreCallingIdentity(identity);
6060 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006061 }
6062
6063 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006064 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006065 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006066 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6067 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006068 return false;
6069 }
Svet Ganovb320e182015-04-16 12:30:10 -07006070
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006071 final long identity = Binder.clearCallingIdentity();
6072 try {
6073 // Check the user preference and the system-level IMS setting. Even if the user has
6074 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6075 // In the long run, we may instead need to check if there exists a connection service
6076 // which can support video calling.
6077 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006078 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006079 return imsManager.isVtEnabledByPlatform()
6080 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6081 && imsManager.isVtEnabledByUser();
6082 } finally {
6083 Binder.restoreCallingIdentity(identity);
6084 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006085 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006086
Andrew Leea1239f22015-03-02 17:44:07 -08006087 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006088 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6089 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006090 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006091 mApp, subId, callingPackage, callingFeatureId,
6092 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006093 return false;
6094 }
6095
6096 final long identity = Binder.clearCallingIdentity();
6097 try {
6098 CarrierConfigManager configManager =
6099 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006100 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006101 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6102 } finally {
6103 Binder.restoreCallingIdentity(identity);
6104 }
Andrew Leea1239f22015-03-02 17:44:07 -08006105 }
6106
6107 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006108 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006109 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006110 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006111 return false;
6112 }
6113
6114 final long identity = Binder.clearCallingIdentity();
6115 try {
6116 CarrierConfigManager configManager =
6117 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006118 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006119 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6120 } finally {
6121 Binder.restoreCallingIdentity(identity);
6122 }
Andrew Leea1239f22015-03-02 17:44:07 -08006123 }
6124
Andrew Lee9431b832015-03-09 18:46:45 -07006125 @Override
6126 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006127 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006128 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006129 }
6130
6131 @Override
6132 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006133 final long identity = Binder.clearCallingIdentity();
6134 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006135 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006136 } finally {
6137 Binder.restoreCallingIdentity(identity);
6138 }
Andrew Lee9431b832015-03-09 18:46:45 -07006139 }
6140
Hall Liuf6668912018-10-31 17:05:23 -07006141 /**
6142 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6143 * support for the feature and device firmware support.
6144 *
6145 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6146 */
6147 @Override
6148 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006149 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006150 final Phone phone = getPhone(subscriptionId);
6151 if (phone == null) {
6152 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6153 return false;
6154 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006155 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006156 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006157 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6158 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006159 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006160 return isCarrierSupported && isDeviceSupported;
6161 } finally {
6162 Binder.restoreCallingIdentity(identity);
6163 }
Hall Liu98187582018-01-22 19:15:32 -08006164 }
6165
Hall Liuf6668912018-10-31 17:05:23 -07006166 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006167 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6168 * RTT setting, will return true if the device and carrier both support RTT.
6169 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006170 */
6171 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006172 final long identity = Binder.clearCallingIdentity();
6173 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006174 boolean isRttSupported = isRttSupported(subscriptionId);
6175 boolean isUserRttSettingOn = Settings.Secure.getInt(
6176 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6177 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6178 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6179 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006180 } finally {
6181 Binder.restoreCallingIdentity(identity);
6182 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006183 }
6184
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006185 @Deprecated
6186 @Override
6187 public String getDeviceId(String callingPackage) {
6188 return getDeviceIdWithFeature(callingPackage, null);
6189 }
6190
Sanket Padawe7310cc72015-01-14 09:53:20 -08006191 /**
6192 * Returns the unique device ID of phone, for example, the IMEI for
6193 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6194 *
6195 * <p>Requires Permission:
6196 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6197 */
6198 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006199 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006200 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006201 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006202 return null;
6203 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006204 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006205 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006206 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006207 return null;
6208 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006209
6210 final long identity = Binder.clearCallingIdentity();
6211 try {
6212 return phone.getDeviceId();
6213 } finally {
6214 Binder.restoreCallingIdentity(identity);
6215 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006216 }
6217
Ping Sunc67b7c22016-03-02 19:16:45 +08006218 /**
6219 * {@hide}
6220 * Returns the IMS Registration Status on a particular subid
6221 *
6222 * @param subId
6223 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006224 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006225 Phone phone = getPhone(subId);
6226 if (phone != null) {
6227 return phone.isImsRegistered();
6228 } else {
6229 return false;
6230 }
6231 }
6232
Santos Cordon7a1885b2015-02-03 11:15:19 -08006233 @Override
6234 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006235 final long identity = Binder.clearCallingIdentity();
6236 try {
6237 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6238 } finally {
6239 Binder.restoreCallingIdentity(identity);
6240 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006241 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006242
Tyler Gunnf70ed162019-04-03 15:28:53 -07006243 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006244 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006245 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006246 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006247 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006248 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6249 }
6250 final long identity = Binder.clearCallingIdentity();
6251 try {
6252 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6253 } finally {
6254 Binder.restoreCallingIdentity(identity);
6255 }
6256 }
6257
6258 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006259 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6260 final long identity = Binder.clearCallingIdentity();
6261 try {
6262 Phone phone = getPhone(subscriptionId);
6263 if (phone == null) {
6264 return null;
6265 }
6266 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6267 } finally {
6268 Binder.restoreCallingIdentity(identity);
6269 }
6270 }
6271
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006272 /**
6273 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006274 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006275 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006276 final long identity = Binder.clearCallingIdentity();
6277 try {
6278 Phone phone = getPhone(subId);
6279 if (phone != null) {
6280 return phone.isWifiCallingEnabled();
6281 } else {
6282 return false;
6283 }
6284 } finally {
6285 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006286 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006287 }
6288
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006289 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006290 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006291 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006292 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006293 final long identity = Binder.clearCallingIdentity();
6294 try {
6295 Phone phone = getPhone(subId);
6296 if (phone != null) {
6297 return phone.isVideoEnabled();
6298 } else {
6299 return false;
6300 }
6301 } finally {
6302 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006303 }
6304 }
6305
6306 /**
6307 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6308 * defined in {@link ImsRegistrationImplBase}.
6309 */
6310 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006311 final long identity = Binder.clearCallingIdentity();
6312 try {
6313 Phone phone = getPhone(subId);
6314 if (phone != null) {
6315 return phone.getImsRegistrationTech();
6316 } else {
6317 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6318 }
6319 } finally {
6320 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006321 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006322 }
6323
Stuart Scott8eef64f2015-04-08 15:13:54 -07006324 @Override
6325 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006326 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006327 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6328 return;
6329 }
6330
Svet Ganovcc087f82015-05-12 20:35:54 -07006331 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006332
Svet Ganovcc087f82015-05-12 20:35:54 -07006333 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006334 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6335 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006336 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006337 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006338 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006339 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6340 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006341 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006342 // There has been issues when Sms raw table somehow stores orphan
6343 // fragments. They lead to garbled message when new fragments come
6344 // in and combined with those stale ones. In case this happens again,
6345 // user can reset all network settings which will clean up this table.
6346 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006347 // Clean up IMS settings as well here.
6348 int slotId = getSlotIndex(subId);
6349 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6350 ImsManager.getInstance(mApp, slotId).factoryReset();
6351 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006352
6353 // Erase modem config if erase modem on network setting is enabled.
6354 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6355 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6356 if (configValue != null && Boolean.parseBoolean(configValue)) {
6357 sendEraseModemConfig(getDefaultPhone());
6358 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006359 } finally {
6360 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006361 }
6362 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006363
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006364 private void cleanUpSmsRawTable(Context context) {
6365 ContentResolver resolver = context.getContentResolver();
6366 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6367 resolver.delete(uri, null, null);
6368 }
6369
Narayan Kamath1c496c22015-04-16 14:40:19 +01006370 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006371 public String getSimLocaleForSubscriber(int subId) {
6372 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6373 final Phone phone = getPhone(subId);
6374 if (phone == null) {
6375 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006376 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006377 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006378 final long identity = Binder.clearCallingIdentity();
6379 try {
chen xu5d3637b2019-01-21 23:31:38 -08006380 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006381 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08006382 if (info == null) {
6383 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6384 return null;
6385 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006386 // Try and fetch the locale from the carrier properties or from the SIM language
6387 // preferences (EF-PL and EF-LI)...
6388 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006389 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006390 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6391 if (localeFromDefaultSim != null) {
6392 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6393 if (DBG) log("Using locale from subId: " + subId + " locale: "
6394 + localeFromDefaultSim);
6395 return localeFromDefaultSim.toLanguageTag();
6396 } else {
6397 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006398 }
6399 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006400
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006401 // The SIM language preferences only store a language (e.g. fr = French), not an
6402 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6403 // the SIM and carrier preferences does not include a country we add the country
6404 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006405 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006406 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006407 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006408 return mccLocale.toLanguageTag();
6409 }
6410
6411 if (DBG) log("No locale found - returning null");
6412 return null;
6413 } finally {
6414 Binder.restoreCallingIdentity(identity);
6415 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006416 }
6417
6418 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006419 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6420 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006421 }
6422
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006423 /**
6424 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6425 */
6426 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006427 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6428 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006429 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006430
Chenjie Yu1ba97252018-01-11 18:16:20 -08006431 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006432 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006433
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006434 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006435 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6436 * representing the state of the modem.
6437 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006438 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6439 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006440 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006441 */
6442 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006443 public void requestModemActivityInfo(ResultReceiver result) {
6444 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006445 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006446
6447 final long identity = Binder.clearCallingIdentity();
6448 try {
6449 ModemActivityInfo ret = null;
6450 synchronized (mLastModemActivityInfo) {
6451 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6452 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006453 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006454 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006455 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006456 int[] txTimeMs = info.getTransmitTimeMillis();
6457 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006458 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006459 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006460 }
6461 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006462 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6463 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006464 mLastModemActivityInfo.setIdleTimeMillis(
6465 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006466 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6467 mLastModemActivityInfo.setReceiveTimeMillis(
6468 info.getReceiveTimeMillis() + mLastModemActivityInfo
6469 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006470 }
Chen Xud78231e2019-09-10 18:49:52 -07006471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006472 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6473 mLastModemActivityInfo.getSleepTimeMillis(),
6474 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006475 mLastModemActivityInfo.getTransmitTimeMillis(),
6476 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006477 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006478 Bundle bundle = new Bundle();
6479 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6480 result.send(0, bundle);
6481 } finally {
6482 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006483 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006484 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006485
Siddharth Rayb8114062018-06-17 15:02:38 -07006486 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6487 // less than total activity duration.
6488 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6489 if (info == null) {
6490 return false;
6491 }
6492 int activityDurationMs =
6493 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6494 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006495 int[] txTimeMs = info.getTransmitTimeMillis();
6496 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6497 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006498 }
6499 return (info.isValid()
6500 && (info.getSleepTimeMillis() <= activityDurationMs)
6501 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006502 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006503 && (totalTxTimeMs <= activityDurationMs));
6504 }
6505
Jack Yu85bd38a2015-11-09 11:34:32 -08006506 /**
6507 * {@hide}
6508 * Returns the service state information on specified subscription.
6509 */
6510 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006511 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6512 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006513 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006514 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006515 return null;
6516 }
6517
Hall Liuf19c44f2018-11-27 14:38:17 -08006518 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6519 LocationAccessPolicy.checkLocationPermission(mApp,
6520 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6521 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006522 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006523 .setCallingPid(Binder.getCallingPid())
6524 .setCallingUid(Binder.getCallingUid())
6525 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006526 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006527 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6528 .build());
6529
6530 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6531 LocationAccessPolicy.checkLocationPermission(mApp,
6532 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6533 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006534 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006535 .setCallingPid(Binder.getCallingPid())
6536 .setCallingUid(Binder.getCallingUid())
6537 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006538 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006539 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6540 .build());
6541 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6542 boolean hasFinePermission =
6543 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6544 boolean hasCoarsePermission =
6545 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6546
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006547 final long identity = Binder.clearCallingIdentity();
6548 try {
6549 final Phone phone = getPhone(subId);
6550 if (phone == null) {
6551 return null;
6552 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006553
Hall Liuf19c44f2018-11-27 14:38:17 -08006554 ServiceState ss = phone.getServiceState();
6555
6556 // Scrub out the location info in ServiceState depending on what level of access
6557 // the caller has.
6558 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006559 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6560 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006561 } finally {
6562 Binder.restoreCallingIdentity(identity);
6563 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006564 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006565
6566 /**
6567 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6568 *
6569 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6570 * voicemail ringtone.
6571 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6572 * PhoneAccount.
6573 */
6574 @Override
6575 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006576 final long identity = Binder.clearCallingIdentity();
6577 try {
6578 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6579 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006580 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006581 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006582
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006583 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6584 } finally {
6585 Binder.restoreCallingIdentity(identity);
6586 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006587 }
6588
6589 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006590 * Sets the per-account voicemail ringtone.
6591 *
6592 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6593 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6594 *
6595 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6596 * voicemail ringtone.
6597 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6598 * PhoneAccount.
6599 */
6600 @Override
6601 public void setVoicemailRingtoneUri(String callingPackage,
6602 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006603 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006604 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006605 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6606 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006607 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6608 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6609 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006610 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006611
6612 final long identity = Binder.clearCallingIdentity();
6613 try {
6614 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6615 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006616 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006617 }
6618 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6619 } finally {
6620 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006621 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006622 }
6623
6624 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006625 * Returns whether vibration is set for voicemail notification in Phone settings.
6626 *
6627 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6628 * voicemail vibration setting.
6629 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6630 */
6631 @Override
6632 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006633 final long identity = Binder.clearCallingIdentity();
6634 try {
6635 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6636 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006637 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006638 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006639
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006640 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6641 } finally {
6642 Binder.restoreCallingIdentity(identity);
6643 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006644 }
6645
Youhan Wange64578a2016-05-02 15:32:42 -07006646 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006647 * Sets the per-account voicemail vibration.
6648 *
6649 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6650 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6651 *
6652 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6653 * voicemail vibration setting.
6654 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6655 * specific PhoneAccount.
6656 */
6657 @Override
6658 public void setVoicemailVibrationEnabled(String callingPackage,
6659 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006660 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006661 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006662 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6663 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006664 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6665 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6666 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006667 }
6668
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006669 final long identity = Binder.clearCallingIdentity();
6670 try {
6671 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6672 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006673 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006674 }
6675 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6676 } finally {
6677 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006678 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006679 }
6680
6681 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006682 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6683 *
6684 * @throws SecurityException if the caller does not have the required permission
6685 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006686 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006687 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006688 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006689 }
6690
6691 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006692 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6693 * permission.
6694 *
6695 * @throws SecurityException if the caller does not have the required permission
6696 */
6697 private void enforceSendSmsPermission() {
6698 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6699 }
6700
6701 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006702 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006703 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006704 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006705 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006706 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006707 final long identity = Binder.clearCallingIdentity();
6708 try {
6709 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006710 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006711 if (componentName == null) {
6712 throw new SecurityException(
6713 "Caller not current active visual voicemail package[null]");
6714 }
6715 String vvmPackage = componentName.getPackageName();
6716 if (!callingPackage.equals(vvmPackage)) {
6717 throw new SecurityException("Caller not current active visual voicemail package["
6718 + vvmPackage + "]");
6719 }
6720 } finally {
6721 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006722 }
6723 }
6724
6725 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006726 * Return the application ID for the app type.
6727 *
6728 * @param subId the subscription ID that this request applies to.
6729 * @param appType the uicc app type.
6730 * @return Application ID for specificied app type, or null if no uicc.
6731 */
6732 @Override
6733 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006734 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006735 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006736
6737 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006738 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006739 if (phone == null) {
6740 return null;
6741 }
6742 String aid = null;
6743 try {
6744 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6745 .getApplicationByType(appType).getAid();
6746 } catch (Exception e) {
6747 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6748 }
6749 return aid;
6750 } finally {
6751 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006752 }
Youhan Wange64578a2016-05-02 15:32:42 -07006753 }
6754
Youhan Wang4001d252016-05-11 10:29:41 -07006755 /**
6756 * Return the Electronic Serial Number.
6757 *
6758 * @param subId the subscription ID that this request applies to.
6759 * @return ESN or null if error.
6760 */
6761 @Override
6762 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006763 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006764 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006765
6766 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006767 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006768 if (phone == null) {
6769 return null;
6770 }
6771 String esn = null;
6772 try {
6773 esn = phone.getEsn();
6774 } catch (Exception e) {
6775 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6776 }
6777 return esn;
6778 } finally {
6779 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006780 }
Youhan Wang4001d252016-05-11 10:29:41 -07006781 }
6782
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006783 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006784 * Return the Preferred Roaming List Version.
6785 *
6786 * @param subId the subscription ID that this request applies to.
6787 * @return PRLVersion or null if error.
6788 */
6789 @Override
6790 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006791 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006792 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006793
6794 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006795 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006796 if (phone == null) {
6797 return null;
6798 }
6799 String cdmaPrlVersion = null;
6800 try {
6801 cdmaPrlVersion = phone.getCdmaPrlVersion();
6802 } catch (Exception e) {
6803 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6804 }
6805 return cdmaPrlVersion;
6806 } finally {
6807 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006808 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006809 }
6810
6811 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006812 * Get snapshot of Telephony histograms
6813 * @return List of Telephony histograms
6814 * @hide
6815 */
6816 @Override
6817 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006818 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6819 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006820
6821 final long identity = Binder.clearCallingIdentity();
6822 try {
6823 return RIL.getTelephonyRILTimingHistograms();
6824 } finally {
6825 Binder.restoreCallingIdentity(identity);
6826 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006827 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006828
6829 /**
6830 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006831 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6832 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006833 * Require system privileges. In the future we may add this to carrier APIs.
6834 *
Michele Berionne482f8202018-11-27 18:57:59 -08006835 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006836 */
6837 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006838 @TelephonyManager.SetCarrierRestrictionResult
6839 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006840 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006841 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006842
Michele Berionne482f8202018-11-27 18:57:59 -08006843 if (carrierRestrictionRules == null) {
6844 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006845 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006846
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006847 final long identity = Binder.clearCallingIdentity();
6848 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006849 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006850 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006851 } finally {
6852 Binder.restoreCallingIdentity(identity);
6853 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006854 }
6855
6856 /**
6857 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006858 * Get the allowed carrier list and the excluded carrier list, including the priority between
6859 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006860 * Require system privileges. In the future we may add this to carrier APIs.
6861 *
Michele Berionne482f8202018-11-27 18:57:59 -08006862 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006863 */
6864 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006865 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006866 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006867 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006868
6869 final long identity = Binder.clearCallingIdentity();
6870 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006871 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6872 if (response instanceof CarrierRestrictionRules) {
6873 return (CarrierRestrictionRules) response;
6874 }
6875 // Response is an Exception of some kind,
6876 // which is signalled to the user as a NULL retval
6877 return null;
6878 } catch (Exception e) {
6879 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6880 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006881 } finally {
6882 Binder.restoreCallingIdentity(identity);
6883 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006884 }
6885
fionaxu59545b42016-05-25 15:53:37 -07006886 /**
6887 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6888 * @param subId the subscription ID that this action applies to.
6889 * @param enabled control enable or disable metered apns.
6890 * {@hide}
6891 */
6892 @Override
6893 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6894 enforceModifyPermission();
6895 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006896
6897 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006898 if (phone == null) {
6899 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6900 return;
6901 }
6902 try {
6903 phone.carrierActionSetMeteredApnsEnabled(enabled);
6904 } catch (Exception e) {
6905 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006906 } finally {
6907 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006908 }
6909 }
6910
6911 /**
6912 * Action set from carrier signalling broadcast receivers to enable/disable radio
6913 * @param subId the subscription ID that this action applies to.
6914 * @param enabled control enable or disable radio.
6915 * {@hide}
6916 */
6917 @Override
6918 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6919 enforceModifyPermission();
6920 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006921
6922 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006923 if (phone == null) {
6924 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6925 return;
6926 }
6927 try {
6928 phone.carrierActionSetRadioEnabled(enabled);
6929 } catch (Exception e) {
6930 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006931 } finally {
6932 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006933 }
6934 }
6935
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006936 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006937 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6938 * network status based on which carrier apps could apply actions accordingly,
6939 * enable/disable default url handler for example.
6940 *
6941 * @param subId the subscription ID that this action applies to.
6942 * @param report control start/stop reporting the default network status.
6943 * {@hide}
6944 */
6945 @Override
6946 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6947 enforceModifyPermission();
6948 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006949
6950 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006951 if (phone == null) {
6952 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6953 return;
6954 }
6955 try {
6956 phone.carrierActionReportDefaultNetworkStatus(report);
6957 } catch (Exception e) {
6958 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006959 } finally {
6960 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006961 }
6962 }
6963
6964 /**
fionaxud9622282017-07-17 17:51:30 -07006965 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6966 * @param subId the subscription ID that this action applies to.
6967 * {@hide}
6968 */
6969 @Override
6970 public void carrierActionResetAll(int subId) {
6971 enforceModifyPermission();
6972 final Phone phone = getPhone(subId);
6973 if (phone == null) {
6974 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6975 return;
6976 }
6977 try {
6978 phone.carrierActionResetAll();
6979 } catch (Exception e) {
6980 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6981 }
6982 }
6983
6984 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006985 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6986 * bug report is being generated.
6987 */
6988 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006989 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006990 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6991 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006992 writer.println("Permission Denial: can't dump Phone from pid="
6993 + Binder.getCallingPid()
6994 + ", uid=" + Binder.getCallingUid()
6995 + "without permission "
6996 + android.Manifest.permission.DUMP);
6997 return;
6998 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006999 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007000 }
Jack Yueb89b242016-06-22 13:27:47 -07007001
Brad Ebingerdac2f002018-04-03 15:17:52 -07007002 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007003 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7004 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7005 @NonNull String[] args) {
7006 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7007 this, in.getFileDescriptor(), out.getFileDescriptor(),
7008 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007009 }
7010
Jack Yueb89b242016-06-22 13:27:47 -07007011 /**
Jack Yu84291ec2017-05-26 16:07:50 -07007012 * Get aggregated video call data usage since boot.
7013 *
7014 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
7015 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07007016 * {@hide}
7017 */
7018 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07007019 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07007020 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
7021 null);
7022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007023 final long identity = Binder.clearCallingIdentity();
7024 try {
7025 // NetworkStatsService keeps tracking the active network interface and identity. It
7026 // records the delta with the corresponding network identity.
7027 // We just return the total video call data usage snapshot since boot.
7028 Phone phone = getPhone(subId);
7029 if (phone != null) {
7030 return phone.getVtDataUsage(perUidStats);
7031 }
7032 return null;
7033 } finally {
7034 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07007035 }
Jack Yueb89b242016-06-22 13:27:47 -07007036 }
Jack Yu75ab2952016-07-08 14:29:33 -07007037
7038 /**
7039 * Policy control of data connection. Usually used when data limit is passed.
7040 * @param enabled True if enabling the data, otherwise disabling.
7041 * @param subId Subscription index
7042 * {@hide}
7043 */
7044 @Override
7045 public void setPolicyDataEnabled(boolean enabled, int subId) {
7046 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007047
7048 final long identity = Binder.clearCallingIdentity();
7049 try {
7050 Phone phone = getPhone(subId);
7051 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007052 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007053 }
7054 } finally {
7055 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007056 }
7057 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007058
7059 /**
7060 * Get Client request stats
7061 * @return List of Client Request Stats
7062 * @hide
7063 */
7064 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007065 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7066 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007068 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007069 return null;
7070 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007071 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007072
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007073 final long identity = Binder.clearCallingIdentity();
7074 try {
7075 if (phone != null) {
7076 return phone.getClientRequestStats();
7077 }
7078
7079 return null;
7080 } finally {
7081 Binder.restoreCallingIdentity(identity);
7082 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007083 }
7084
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007085 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007086 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007087 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007088 }
Jack Yueb4124c2017-02-16 15:32:43 -08007089
7090 /**
Grace Chen70990072017-03-24 17:21:30 -07007091 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007092 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007093 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007094 * @param state State of SIM (power down, power up, pass through)
7095 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7096 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7097 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007098 *
7099 **/
7100 @Override
Grace Chen70990072017-03-24 17:21:30 -07007101 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007102 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007103 Phone phone = PhoneFactory.getPhone(slotIndex);
7104
vagdeviaf9a5b92018-08-15 16:01:53 -07007105 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7106
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007107 final long identity = Binder.clearCallingIdentity();
7108 try {
7109 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007110 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007111 }
7112 } finally {
7113 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007114 }
7115 }
Shuo Qiandd210312017-04-12 22:11:33 +00007116
Tyler Gunn65d45c22017-06-05 11:22:26 -07007117 private boolean isUssdApiAllowed(int subId) {
7118 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007119 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007120 if (configManager == null) {
7121 return false;
7122 }
7123 PersistableBundle pb = configManager.getConfigForSubId(subId);
7124 if (pb == null) {
7125 return false;
7126 }
7127 return pb.getBoolean(
7128 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7129 }
7130
Shuo Qiandd210312017-04-12 22:11:33 +00007131 /**
7132 * Check if phone is in emergency callback mode
7133 * @return true if phone is in emergency callback mode
7134 * @param subId sub id
7135 */
goneil9c5f4872017-12-05 14:07:56 -08007136 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007137 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007138 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007139 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007140
7141 final long identity = Binder.clearCallingIdentity();
7142 try {
7143 if (phone != null) {
7144 return phone.isInEcm();
7145 } else {
7146 return false;
7147 }
7148 } finally {
7149 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007150 }
7151 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007152
7153 /**
7154 * Get the current signal strength information for the given subscription.
7155 * Because this information is not updated when the device is in a low power state
7156 * it should not be relied-upon to be current.
7157 * @param subId Subscription index
7158 * @return the most recent cached signal strength info from the modem
7159 */
7160 @Override
7161 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007162 final long identity = Binder.clearCallingIdentity();
7163 try {
7164 Phone p = getPhone(subId);
7165 if (p == null) {
7166 return null;
7167 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007168
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007169 return p.getSignalStrength();
7170 } finally {
7171 Binder.restoreCallingIdentity(identity);
7172 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007173 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007174
Pengquan Meng77b7f132018-08-22 14:49:57 -07007175 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007176 * Get the current modem radio state for the given slot.
7177 * @param slotIndex slot index.
7178 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007179 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007180 * @return the current radio power state from the modem
7181 */
7182 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007183 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007184 Phone phone = PhoneFactory.getPhone(slotIndex);
7185 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007186 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7187 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007188 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7189 }
7190
7191 final long identity = Binder.clearCallingIdentity();
7192 try {
7193 return phone.getRadioPowerState();
7194 } finally {
7195 Binder.restoreCallingIdentity(identity);
7196 }
7197 }
7198 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7199 }
7200
7201 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007202 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7203 *
7204 * <p>Requires one of the following permissions:
7205 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7206 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7207 * privileges.
7208 *
7209 * @param subId subscription id
7210 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7211 * {@code false}.
7212 */
7213 @Override
7214 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007215 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7216 null /* message */);
7217
Pengquan Menga1bb6272018-09-06 09:59:22 -07007218 boolean isEnabled = false;
7219 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007220 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007221 Phone phone = getPhone(subId);
7222 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007223 } catch (Exception e) {
7224 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7225 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007226 } finally {
7227 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007228 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007229 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007230 }
7231
7232
7233 /**
7234 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7235 *
7236 * <p> Requires permission:
7237 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7238 * privileges.
7239 *
7240 * @param subId subscription id
7241 * @param isEnabled {@code true} means enable, {@code false} means disable.
7242 */
7243 @Override
7244 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7246 mApp, subId, "setDataRoamingEnabled");
7247
Pengquan Menga1bb6272018-09-06 09:59:22 -07007248 final long identity = Binder.clearCallingIdentity();
7249 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007250 Phone phone = getPhone(subId);
7251 if (phone != null) {
7252 phone.setDataRoamingEnabled(isEnabled);
7253 }
7254 } finally {
7255 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007256 }
7257 }
7258
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007259 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007260 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007261 TelephonyPermissions
7262 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007263 mApp, subId, "isManualNetworkSelectionAllowed");
7264
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007265 boolean isAllowed = true;
7266 final long identity = Binder.clearCallingIdentity();
7267 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007268 Phone phone = getPhone(subId);
7269 if (phone != null) {
7270 isAllowed = phone.isCspPlmnEnabled();
7271 }
7272 } finally {
7273 Binder.restoreCallingIdentity(identity);
7274 }
7275 return isAllowed;
7276 }
7277
7278 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007279 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007280 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007281 try {
7282 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007283 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007284 } catch (SecurityException e) {
7285 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7286 // has carrier privileges on an active UICC
7287 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7288 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007289 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007290 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007291 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007292
7293 final long identity = Binder.clearCallingIdentity();
7294 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007295 UiccController uiccController = UiccController.getInstance();
7296 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007297 if (hasReadPermission) {
7298 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007299 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007300
7301 // Remove private info if the caller doesn't have access
7302 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7303 for (UiccCardInfo cardInfo : cardInfos) {
7304 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7305 // is available
7306 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7307 if (card == null || card.getUiccProfile() == null) {
7308 // assume no access if the card or profile is unavailable
7309 filteredInfos.add(cardInfo.getUnprivileged());
7310 continue;
7311 }
7312 UiccProfile profile = card.getUiccProfile();
7313 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7314 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7315 filteredInfos.add(cardInfo);
7316 } else {
7317 filteredInfos.add(cardInfo.getUnprivileged());
7318 }
7319 }
7320 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007321 } finally {
7322 Binder.restoreCallingIdentity(identity);
7323 }
7324 }
7325
7326 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007327 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007328 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007329
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007330 final long identity = Binder.clearCallingIdentity();
7331 try {
7332 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7333 if (slots == null) {
7334 Rlog.i(LOG_TAG, "slots is null.");
7335 return null;
7336 }
7337
7338 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7339 for (int i = 0; i < slots.length; i++) {
7340 UiccSlot slot = slots[i];
7341 if (slot == null) {
7342 continue;
7343 }
7344
Jordan Liu7be7e652019-05-06 18:55:02 +00007345 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007346 UiccCard card = slot.getUiccCard();
7347 if (card != null) {
7348 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007349 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007350 cardId = slot.getEid();
7351 if (TextUtils.isEmpty(cardId)) {
7352 cardId = slot.getIccId();
7353 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007354 }
7355
Jordan Liu857451f2019-05-09 16:35:35 -07007356 if (cardId != null) {
7357 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7358 // if cardId is an EID, it's all digits so this is fine
7359 cardId = IccUtils.stripTrailingFs(cardId);
7360 }
7361
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007362 int cardState = 0;
7363 switch (slot.getCardState()) {
7364 case CARDSTATE_ABSENT:
7365 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7366 break;
7367 case CARDSTATE_PRESENT:
7368 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7369 break;
7370 case CARDSTATE_ERROR:
7371 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7372 break;
7373 case CARDSTATE_RESTRICTED:
7374 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7375 break;
7376 default:
7377 break;
7378
7379 }
7380
7381 infos[i] = new UiccSlotInfo(
7382 slot.isActive(),
7383 slot.isEuicc(),
7384 cardId,
7385 cardState,
7386 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007387 slot.isExtendedApduSupported(),
7388 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007389 }
7390 return infos;
7391 } finally {
7392 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007393 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007394 }
7395
7396 @Override
7397 public boolean switchSlots(int[] physicalSlots) {
7398 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007399
7400 final long identity = Binder.clearCallingIdentity();
7401 try {
7402 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7403 } finally {
7404 Binder.restoreCallingIdentity(identity);
7405 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007406 }
Jack Yu4c988042018-02-27 15:30:01 -08007407
7408 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007409 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007410 final long identity = Binder.clearCallingIdentity();
7411 try {
7412 return UiccController.getInstance().getCardIdForDefaultEuicc();
7413 } finally {
7414 Binder.restoreCallingIdentity(identity);
7415 }
7416 }
7417
7418 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007419 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7420 enforceModifyPermission();
7421 final Phone phone = getPhone(subId);
7422 if (phone == null) {
7423 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7424 return;
7425 }
7426
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007427 final long identity = Binder.clearCallingIdentity();
7428 try {
7429 phone.setRadioIndicationUpdateMode(filters, mode);
7430 } finally {
7431 Binder.restoreCallingIdentity(identity);
7432 }
Jack Yu4c988042018-02-27 15:30:01 -08007433 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007434
7435 /**
goneil47ffb6e2018-04-06 15:40:58 -07007436 * A test API to reload the UICC profile.
7437 *
7438 * <p>Requires that the calling app has permission
7439 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7440 * @hide
7441 */
7442 @Override
7443 public void refreshUiccProfile(int subId) {
7444 enforceModifyPermission();
7445
7446 final long identity = Binder.clearCallingIdentity();
7447 try {
7448 Phone phone = getPhone(subId);
7449 if (phone == null) {
7450 return;
7451 }
7452 UiccCard uiccCard = phone.getUiccCard();
7453 if (uiccCard == null) {
7454 return;
7455 }
7456 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7457 if (uiccProfile == null) {
7458 return;
7459 }
7460 uiccProfile.refresh();
7461 } finally {
7462 Binder.restoreCallingIdentity(identity);
7463 }
7464 }
7465
7466 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007467 * Returns false if the mobile data is disabled by default, otherwise return true.
7468 */
7469 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007470 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007471 }
7472
7473 /**
7474 * Returns true if the data roaming is enabled by default, i.e the system property
7475 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7476 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7477 */
7478 private boolean getDefaultDataRoamingEnabled(int subId) {
7479 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007480 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007481 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007482 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7483 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7484 return isDataRoamingEnabled;
7485 }
7486
7487 /**
7488 * Returns the default network type for the given {@code subId}, if the default network type is
7489 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7490 */
7491 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007492 List<Integer> list = TelephonyProperties.default_network();
7493 int phoneId = mSubscriptionController.getPhoneId(subId);
7494 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7495 return list.get(phoneId);
7496 }
7497 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007498 }
fionaxua13278b2018-03-21 00:08:13 -07007499
7500 @Override
7501 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007502 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007503 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007504
7505 final long identity = Binder.clearCallingIdentity();
7506 try {
7507 final Phone phone = getPhone(subId);
7508 if (phone == null) {
7509 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7510 return;
7511 }
chen xueaba88a2019-03-15 13:15:10 -07007512 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7513 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007514 } finally {
7515 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007516 }
fionaxua13278b2018-03-21 00:08:13 -07007517 }
7518
7519 @Override
7520 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007521 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007522
7523 final long identity = Binder.clearCallingIdentity();
7524 try {
7525 final Phone phone = getPhone(subId);
7526 if (phone == null) {
7527 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7528 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7529 }
7530 return phone.getCarrierIdListVersion();
7531 } finally {
7532 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007533 }
fionaxua13278b2018-03-21 00:08:13 -07007534 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007535
7536 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007537 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7538 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007539 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007540 mApp, subId, callingPackage, callingFeatureId,
7541 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007542 return -1;
7543 }
7544
7545 final long identity = Binder.clearCallingIdentity();
7546 try {
7547 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7548 } finally {
7549 Binder.restoreCallingIdentity(identity);
7550 }
7551 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007552
7553 @Override
7554 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007555 TelephonyPermissions
7556 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007557 mApp, subId, "getCdmaRoamingMode");
7558
7559 final long identity = Binder.clearCallingIdentity();
7560 try {
7561 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7562 } finally {
7563 Binder.restoreCallingIdentity(identity);
7564 }
7565 }
7566
7567 @Override
7568 public boolean setCdmaRoamingMode(int subId, int mode) {
7569 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7570 mApp, subId, "setCdmaRoamingMode");
7571
7572 final long identity = Binder.clearCallingIdentity();
7573 try {
7574 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7575 } finally {
7576 Binder.restoreCallingIdentity(identity);
7577 }
7578 }
7579
7580 @Override
7581 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7582 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7583 mApp, subId, "setCdmaSubscriptionMode");
7584
7585 final long identity = Binder.clearCallingIdentity();
7586 try {
7587 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7588 } finally {
7589 Binder.restoreCallingIdentity(identity);
7590 }
7591 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007592
sqianc5eccab2018-10-19 18:46:41 -07007593 @Override
sqian8c685422019-02-22 15:55:18 -08007594 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007595 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007596 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007597 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7598 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007599 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7600 }
7601 final long identity = Binder.clearCallingIdentity();
7602 try {
sqian854d44b2018-12-12 16:48:18 -08007603 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7604 for (Phone phone: PhoneFactory.getPhones()) {
7605 if (phone.getEmergencyNumberTracker() != null
7606 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7607 emergencyNumberListInternal.put(
7608 phone.getSubId(),
7609 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7610 }
sqian11b7a0e2018-12-05 18:48:28 -08007611 }
sqian854d44b2018-12-12 16:48:18 -08007612 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007613 } finally {
7614 Binder.restoreCallingIdentity(identity);
7615 }
sqianc5eccab2018-10-19 18:46:41 -07007616 }
7617
7618 @Override
sqian8c685422019-02-22 15:55:18 -08007619 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007620 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007621 if (!exactMatch) {
7622 TelephonyPermissions
7623 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007624 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007625 }
7626 final long identity = Binder.clearCallingIdentity();
7627 try {
sqian854d44b2018-12-12 16:48:18 -08007628 for (Phone phone: PhoneFactory.getPhones()) {
7629 if (phone.getEmergencyNumberTracker() != null
7630 && phone.getEmergencyNumberTracker() != null) {
7631 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7632 number, exactMatch)) {
7633 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007634 }
7635 }
sqian11b7a0e2018-12-05 18:48:28 -08007636 }
7637 return false;
7638 } finally {
7639 Binder.restoreCallingIdentity(identity);
7640 }
7641 }
7642
sqianf4ca7ed2019-01-15 18:32:07 -08007643 /**
7644 * Update emergency number list for test mode.
7645 */
7646 @Override
7647 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7648 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7649 "updateEmergencyNumberListTestMode");
7650
7651 final long identity = Binder.clearCallingIdentity();
7652 try {
7653 for (Phone phone: PhoneFactory.getPhones()) {
7654 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7655 if (tracker != null) {
7656 tracker.executeEmergencyNumberTestModeCommand(action, num);
7657 }
7658 }
7659 } finally {
7660 Binder.restoreCallingIdentity(identity);
7661 }
7662 }
7663
7664 /**
7665 * Get the full emergency number list for test mode.
7666 */
7667 @Override
7668 public List<String> getEmergencyNumberListTestMode() {
7669 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7670 "getEmergencyNumberListTestMode");
7671
7672 final long identity = Binder.clearCallingIdentity();
7673 try {
7674 Set<String> emergencyNumbers = new HashSet<>();
7675 for (Phone phone: PhoneFactory.getPhones()) {
7676 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7677 if (tracker != null) {
7678 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7679 emergencyNumbers.add(num.getNumber());
7680 }
7681 }
7682 }
7683 return new ArrayList<>(emergencyNumbers);
7684 } finally {
7685 Binder.restoreCallingIdentity(identity);
7686 }
7687 }
7688
chen xud6b45bd2018-10-30 22:27:10 -07007689 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007690 public int getEmergencyNumberDbVersion(int subId) {
7691 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7692
7693 final long identity = Binder.clearCallingIdentity();
7694 try {
7695 final Phone phone = getPhone(subId);
7696 if (phone == null) {
7697 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7698 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7699 }
7700 return phone.getEmergencyNumberDbVersion();
7701 } finally {
7702 Binder.restoreCallingIdentity(identity);
7703 }
7704 }
7705
7706 @Override
7707 public void notifyOtaEmergencyNumberDbInstalled() {
7708 enforceModifyPermission();
7709
7710 final long identity = Binder.clearCallingIdentity();
7711 try {
7712 for (Phone phone: PhoneFactory.getPhones()) {
7713 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7714 if (tracker != null) {
7715 tracker.updateOtaEmergencyNumberDatabase();
7716 }
7717 }
7718 } finally {
7719 Binder.restoreCallingIdentity(identity);
7720 }
7721 }
7722
7723 @Override
7724 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7725 enforceActiveEmergencySessionPermission();
7726
7727 final long identity = Binder.clearCallingIdentity();
7728 try {
7729 for (Phone phone: PhoneFactory.getPhones()) {
7730 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7731 if (tracker != null) {
7732 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7733 }
7734 }
7735 } finally {
7736 Binder.restoreCallingIdentity(identity);
7737 }
7738 }
7739
7740 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007741 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7742 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7743 Phone phone = getPhone(subId);
7744 if (phone == null) {
7745 return null;
7746 }
7747 final long identity = Binder.clearCallingIdentity();
7748 try {
7749 UiccProfile profile = UiccController.getInstance()
7750 .getUiccProfileForPhone(phone.getPhoneId());
7751 if (profile != null) {
7752 return profile.getCertsFromCarrierPrivilegeAccessRules();
7753 }
7754 } finally {
7755 Binder.restoreCallingIdentity(identity);
7756 }
7757 return null;
7758 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007759
7760 /**
7761 * Enable or disable a modem stack.
7762 */
7763 @Override
7764 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7765 enforceModifyPermission();
7766
7767 final long identity = Binder.clearCallingIdentity();
7768 try {
7769 Phone phone = PhoneFactory.getPhone(slotIndex);
7770 if (phone == null) {
7771 return false;
7772 } else {
7773 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7774 }
7775 } finally {
7776 Binder.restoreCallingIdentity(identity);
7777 }
7778 }
Michelecea4cf22018-12-21 15:00:11 -08007779
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007780 /**
7781 * Whether a modem stack is enabled or not.
7782 */
7783 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007784 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7785 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007786 Phone phone = PhoneFactory.getPhone(slotIndex);
7787 if (phone == null) return false;
7788
7789 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007790 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7791 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007792 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7793 }
7794
7795 final long identity = Binder.clearCallingIdentity();
7796 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007797 try {
7798 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7799 } catch (NoSuchElementException ex) {
7800 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7801 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007802 } finally {
7803 Binder.restoreCallingIdentity(identity);
7804 }
7805 }
7806
Michelecea4cf22018-12-21 15:00:11 -08007807 @Override
Michele0ea7d782019-03-19 14:58:42 -07007808 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007809 enforceModifyPermission();
7810
7811 final long identity = Binder.clearCallingIdentity();
7812 try {
7813 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007814 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007815 .commit();
7816 } finally {
7817 Binder.restoreCallingIdentity(identity);
7818 }
7819 }
7820
7821 @Override
Michele0ea7d782019-03-19 14:58:42 -07007822 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007823 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007824 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007825 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7826 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007827 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007828 }
Michelecea4cf22018-12-21 15:00:11 -08007829
7830 final long identity = Binder.clearCallingIdentity();
7831 try {
Michele0ea7d782019-03-19 14:58:42 -07007832 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007833 } finally {
7834 Binder.restoreCallingIdentity(identity);
7835 }
7836 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007837
Michele0ea7d782019-03-19 14:58:42 -07007838 @TelephonyManager.IsMultiSimSupportedResult
7839 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007840 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7841 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7842 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007843 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7844 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007845 }
7846 // Check if the hardware supports multisim functionality. If usage of multisim is not
7847 // supported by the modem, indicate that it is restricted.
7848 PhoneCapability staticCapability =
7849 mPhoneConfigurationManager.getStaticPhoneCapability();
7850 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007851 loge("isMultiSimSupportedInternal: no static configuration available");
7852 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007853 }
Sarah Chin0605abf2019-12-06 10:24:18 -08007854 if (staticCapability.getLogicalModemUuids().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007855 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7856 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007857 }
7858 // Check if support of multiple SIMs is restricted by carrier
7859 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007860 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007861 }
7862
Michele0ea7d782019-03-19 14:58:42 -07007863 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007864 }
7865
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007866 /**
7867 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007868 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7869 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7870 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007871 * @param numOfSims number of active sims we want to switch to
7872 */
7873 @Override
7874 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007875 if (numOfSims == 1) {
7876 enforceModifyPermission();
7877 } else {
7878 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7879 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7880 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007881 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007882
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007883 try {
Michele30b57b22019-03-01 12:01:14 -08007884 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007885 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007886 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7887 return;
7888 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007889 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7890 } finally {
7891 Binder.restoreCallingIdentity(identity);
7892 }
7893 }
7894
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007895 @Override
7896 public boolean isApplicationOnUicc(int subId, int appType) {
7897 enforceReadPrivilegedPermission("isApplicationOnUicc");
7898 Phone phone = getPhone(subId);
7899 if (phone == null) {
7900 return false;
7901 }
7902 final long identity = Binder.clearCallingIdentity();
7903 try {
7904 UiccCard uiccCard = phone.getUiccCard();
7905 if (uiccCard == null) {
7906 return false;
7907 }
7908 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7909 if (uiccProfile == null) {
7910 return false;
7911 }
7912 if (TelephonyManager.APPTYPE_SIM <= appType
7913 && appType <= TelephonyManager.APPTYPE_ISIM) {
7914 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7915 }
7916 return false;
7917 } finally {
7918 Binder.restoreCallingIdentity(identity);
7919 }
7920 }
7921
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007922 /**
chen xub4baa772019-04-03 10:23:41 -07007923 * Get whether making changes to modem configurations will trigger reboot.
7924 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007925 */
7926 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007927 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7928 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007929 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007930 mApp, subId, callingPackage, callingFeatureId,
7931 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007932 return false;
7933 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007934 final long identity = Binder.clearCallingIdentity();
7935 try {
7936 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7937 } finally {
7938 Binder.restoreCallingIdentity(identity);
7939 }
7940 }
7941
Nathan Harold29f5f052019-02-15 13:41:57 -08007942 private void updateModemStateMetrics() {
7943 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7944 // TODO: check the state for each modem if the api is ready.
7945 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7946 }
7947
Pengquan Meng3889a572019-01-23 11:16:29 -08007948 @Override
7949 public int[] getSlotsMapping() {
7950 enforceReadPrivilegedPermission("getSlotsMapping");
7951
7952 final long identity = Binder.clearCallingIdentity();
7953 try {
7954 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7955 // All logical slots should have a mapping to a physical slot.
7956 int[] logicalSlotsMapping = new int[phoneCount];
7957 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7958 for (int i = 0; i < slotInfos.length; i++) {
7959 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7960 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7961 }
7962 }
7963 return logicalSlotsMapping;
7964 } finally {
7965 Binder.restoreCallingIdentity(identity);
7966 }
7967 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007968
7969 /**
7970 * Get the IRadio HAL Version
7971 */
7972 @Override
7973 public int getRadioHalVersion() {
7974 Phone phone = getDefaultPhone();
7975 if (phone == null) return -1;
7976 HalVersion hv = phone.getHalVersion();
7977 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7978 return hv.major * 100 + hv.minor;
7979 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007980
7981 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08007982 * Get the current calling package name.
7983 * @return the current calling package name
7984 */
7985 @Override
7986 public String getCurrentPackageName() {
7987 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
7988 }
7989
7990 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007991 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7992 * corresponding network requests on a subId.
7993 *
7994 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007995 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007996 * 2) APN is un-metered for this subscription, or
7997 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08007998 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07007999 *
8000 * @return whether data is allowed for a apn type.
8001 *
8002 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008003 */
8004 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008005 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008006 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8007 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008008
8009 // Now that all security checks passes, perform the operation as ourselves.
8010 final long identity = Binder.clearCallingIdentity();
8011 try {
8012 Phone phone = getPhone(subId);
8013 if (phone == null) return false;
8014
Jack Yu41407ee2019-05-13 16:54:09 -07008015 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008016 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8017 } finally {
8018 Binder.restoreCallingIdentity(identity);
8019 }
8020 }
8021
8022 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008023 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008024 enforceReadPrivilegedPermission("isApnMetered");
8025
8026 // Now that all security checks passes, perform the operation as ourselves.
8027 final long identity = Binder.clearCallingIdentity();
8028 try {
8029 Phone phone = getPhone(subId);
8030 if (phone == null) return true; // By default return true.
8031
Jack Yu41407ee2019-05-13 16:54:09 -07008032 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008033 } finally {
8034 Binder.restoreCallingIdentity(identity);
8035 }
8036 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008037
8038 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008039 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8040 int subscriptionId, IBooleanConsumer resultCallback) {
8041 enforceModifyPermission();
8042 long token = Binder.clearCallingIdentity();
8043 try {
8044 Phone phone = getPhone(subscriptionId);
8045 if (phone == null) {
8046 try {
8047 if (resultCallback != null) {
8048 resultCallback.accept(false);
8049 }
8050 } catch (RemoteException e) {
8051 // ignore
8052 }
8053 return;
8054 }
8055 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8056 Pair.create(specifiers, (x) -> {
8057 try {
8058 if (resultCallback != null) {
8059 resultCallback.accept(x);
8060 }
8061 } catch (RemoteException e) {
8062 // ignore
8063 }
8064 });
8065 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8066 } finally {
8067 Binder.restoreCallingIdentity(token);
8068 }
8069 }
8070
8071 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008072 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8073 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8074 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8075 if (iccRecords == null) {
8076 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8077 return false;
8078 }
8079 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8080 }
8081
8082 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07008083 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008084 if (callingPackage == null) {
8085 callingPackage = getCurrentPackageName();
8086 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008087 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8088 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
8089 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
8090 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8091 }
8092 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8093 Intent intent = new Intent();
8094 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8095 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8096 // Bring up choose default SMS subscription dialog right now
8097 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8098 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8099 mApp.startActivity(intent);
8100 }
chen xud5ca2d52019-05-28 15:20:57 -07008101
8102 @Override
8103 public String getMmsUAProfUrl(int subId) {
8104 //TODO investigate if this API should require proper permission check in R b/133791609
8105 final long identity = Binder.clearCallingIdentity();
8106 try {
8107 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8108 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8109 } finally {
8110 Binder.restoreCallingIdentity(identity);
8111 }
8112 }
8113
8114 @Override
8115 public String getMmsUserAgent(int subId) {
8116 //TODO investigate if this API should require proper permission check in R b/133791609
8117 final long identity = Binder.clearCallingIdentity();
8118 try {
8119 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8120 .getString(com.android.internal.R.string.config_mms_user_agent);
8121 } finally {
8122 Binder.restoreCallingIdentity(identity);
8123 }
8124 }
Jack Yub07d4972019-05-28 16:12:25 -07008125
8126 @Override
8127 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8128 enforceModifyPermission();
8129
8130 // Now that all security checks passes, perform the operation as ourselves.
8131 final long identity = Binder.clearCallingIdentity();
8132 try {
8133 Phone phone = getPhone(subId);
8134 if (phone == null) return false;
8135
8136 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8137 } finally {
8138 Binder.restoreCallingIdentity(identity);
8139 }
8140 }
8141
8142 @Override
8143 public boolean isDataAllowedInVoiceCall(int subId) {
8144 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8145
8146 // Now that all security checks passes, perform the operation as ourselves.
8147 final long identity = Binder.clearCallingIdentity();
8148 try {
8149 Phone phone = getPhone(subId);
8150 if (phone == null) return false;
8151
8152 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8153 } finally {
8154 Binder.restoreCallingIdentity(identity);
8155 }
8156 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008157
changbettyd5c246e2019-12-24 15:40:37 +08008158 @Override
8159 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8160 enforceModifyPermission();
8161
8162 // Now that all security checks passes, perform the operation as ourselves.
8163 final long identity = Binder.clearCallingIdentity();
8164 try {
8165 Phone phone = getPhone(subId);
8166 if (phone == null) return false;
8167
8168 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8169 } finally {
8170 Binder.restoreCallingIdentity(identity);
8171 }
8172 }
8173
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008174 /**
8175 * Updates whether conference event pacakge handling is enabled.
8176 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8177 * otherwise.
8178 */
8179 @Override
8180 public void setCepEnabled(boolean isCepEnabled) {
8181 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8182
8183 final long identity = Binder.clearCallingIdentity();
8184 try {
8185 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8186 for (Phone phone : PhoneFactory.getPhones()) {
8187 Phone defaultPhone = phone.getImsPhone();
8188 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8189 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8190 ImsPhoneCallTracker imsPhoneCallTracker =
8191 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8192 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8193 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8194 + imsPhone.getMsisdn());
8195 }
8196 }
8197 } finally {
8198 Binder.restoreCallingIdentity(identity);
8199 }
8200 }
allenwtsu46dcc572020-01-08 18:24:03 +08008201
8202 /**
8203 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8204 *
8205 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8206 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8207 * before being read.
8208 */
8209 @Override
8210 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8211 isCompressed) {
8212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8213 mApp, subId, "notifyRcsAutoConfigurationReceived");
8214 try {
8215 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8216 if (configBinder == null) {
8217 Rlog.e(LOG_TAG, "null result for getImsConfig");
8218 } else {
8219 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8220 }
8221 } catch (RemoteException e) {
8222 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8223 }
8224 }
zoey chene02881a2019-12-30 16:11:23 +08008225
8226 @Override
8227 public boolean isIccLockEnabled(int subId) {
8228 enforceReadPrivilegedPermission("isIccLockEnabled");
8229
8230 // Now that all security checks passes, perform the operation as ourselves.
8231 final long identity = Binder.clearCallingIdentity();
8232 try {
8233 Phone phone = getPhone(subId);
8234 if (phone != null && phone.getIccCard() != null) {
8235 return phone.getIccCard().getIccLockEnabled();
8236 } else {
8237 return false;
8238 }
8239 } finally {
8240 Binder.restoreCallingIdentity(identity);
8241 }
8242 }
8243
8244 /**
8245 * Set the ICC pin lock enabled or disabled.
8246 *
8247 * @return an integer representing the status of IccLock enabled or disabled in the following
8248 * three cases:
8249 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8250 * successfully.
8251 * - Positive number and zero for remaining password attempts.
8252 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8253 *
8254 */
8255 @Override
8256 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8257 enforceModifyPermission();
8258
8259 Phone phone = getPhone(subId);
8260 if (phone == null) {
8261 return 0;
8262 }
8263 // Now that all security checks passes, perform the operation as ourselves.
8264 final long identity = Binder.clearCallingIdentity();
8265 try {
8266 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8267 new Pair<Boolean, String>(enabled, password), phone, null);
8268 return attemptsRemaining;
8269
8270 } catch (Exception e) {
8271 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8272 } finally {
8273 Binder.restoreCallingIdentity(identity);
8274 }
8275 return 0;
8276 }
8277
8278 /**
8279 * Change the ICC password used in ICC pin lock.
8280 *
8281 * @return an integer representing the status of IccLock changed in the following three cases:
8282 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8283 * - Positive number and zero for remaining password attempts.
8284 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8285 *
8286 */
8287 @Override
8288 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8289 enforceModifyPermission();
8290
8291 Phone phone = getPhone(subId);
8292 if (phone == null) {
8293 return 0;
8294 }
8295 // Now that all security checks passes, perform the operation as ourselves.
8296 final long identity = Binder.clearCallingIdentity();
8297 try {
8298 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8299 new Pair<String, String>(oldPassword, newPassword), phone, null);
8300 return attemptsRemaining;
8301
8302 } catch (Exception e) {
8303 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8304 } finally {
8305 Binder.restoreCallingIdentity(identity);
8306 }
8307 return 0;
8308 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008309
8310 /**
8311 * Request for receiving user activity notification
8312 */
8313 @Override
8314 public void requestUserActivityNotification() {
8315 if (!mNotifyUserActivity.get()
8316 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8317 mNotifyUserActivity.set(true);
8318 }
8319 }
8320
8321 /**
8322 * Called when userActivity is signalled in the power manager.
8323 * This is safe to call from any thread, with any window manager locks held or not.
8324 */
8325 @Override
8326 public void userActivity() {
8327 // ***************************************
8328 // * Inherited from PhoneWindowManager *
8329 // ***************************************
8330 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8331 // WITH ITS LOCKS HELD.
8332 //
8333 // This code must be VERY careful about the locks
8334 // it acquires.
8335 // In fact, the current code acquires way too many,
8336 // and probably has lurking deadlocks.
8337
8338 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8339 throw new SecurityException("Only the OS may call notifyUserActivity()");
8340 }
8341
8342 if (mNotifyUserActivity.getAndSet(false)) {
8343 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8344 USER_ACTIVITY_NOTIFICATION_DELAY);
8345 }
8346 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008347}