blob: 472ecc58dc2566d5d77d1c46fdef86e7be1b68e3 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070038import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.net.Uri;
40import android.os.AsyncResult;
41import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080042import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.os.Bundle;
44import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070045import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.Looper;
47import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070048import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080049import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070050import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070051import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080052import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080053import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070054import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070055import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070060import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080061import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070062import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090063import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080064import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080065import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070066import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070067import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080071import android.telephony.CellIdentityCdma;
72import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070074import android.telephony.CellInfoGsm;
75import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070076import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070077import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070078import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080079import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070080import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070082import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080083import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080084import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080088import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080089import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080091import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070092import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080095import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000096import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070097import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsMmTelFeature;
108import android.telephony.ims.aidl.IImsRcsFeature;
109import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700110import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800113import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800114import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800115import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800119import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800120import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800121
Andrew Lee312e8172014-10-23 17:01:36 -0700122import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800123import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700124import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700125import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700126import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800127import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700128import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700129import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800131import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800132import com.android.internal.telephony.IBooleanConsumer;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700133import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800134import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700135import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800136import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700137import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700138import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700139import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700141import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800142import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700143import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700144import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700145import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700146import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700147import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700148import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700149import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700150import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800151import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800152import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700153import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800154import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700155import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800156import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700157import com.android.internal.telephony.imsphone.ImsPhone;
158import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800159import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700160import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700161import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800162import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800164import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700165import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800166import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700167import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800168import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000169import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800170import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700171import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800172import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700173import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700174import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800175import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700176import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700177import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang44b186e2020-01-13 23:33:09 -0800178import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800179
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700180import java.io.FileDescriptor;
181import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700182import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800183import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800184import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800185import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800186import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100187import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800188import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700189import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800190import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800191import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800192import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193
194/**
195 * Implementation of the ITelephony interface.
196 */
Santos Cordon117fee72014-05-16 17:56:12 -0700197public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198 private static final String LOG_TAG = "PhoneInterfaceManager";
199 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
200 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800201 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700202
203 // Message codes used with mMainThreadHandler
204 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700205 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
206 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700207 private static final int CMD_OPEN_CHANNEL = 9;
208 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
209 private static final int CMD_CLOSE_CHANNEL = 11;
210 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800211 private static final int CMD_NV_READ_ITEM = 13;
212 private static final int EVENT_NV_READ_ITEM_DONE = 14;
213 private static final int CMD_NV_WRITE_ITEM = 15;
214 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
215 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
216 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700217 private static final int CMD_RESET_MODEM_CONFIG = 19;
218 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800219 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
220 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
221 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
222 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800223 private static final int CMD_SEND_ENVELOPE = 25;
224 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000225 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
226 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700227 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
228 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
229 private static final int CMD_EXCHANGE_SIM_IO = 31;
230 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800231 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
232 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700233 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
234 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700235 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
236 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700237 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
238 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
239 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
240 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700241 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
242 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
243 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
244 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700245 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800246 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
247 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000248 private static final int CMD_SWITCH_SLOTS = 50;
249 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700250 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
251 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
252 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
253 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
254 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
255 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
256 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
257 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700258 private static final int CMD_GET_ALL_CELL_INFO = 60;
259 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
260 private static final int CMD_GET_CELL_LOCATION = 62;
261 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700262 private static final int CMD_MODEM_REBOOT = 64;
263 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700264 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
265 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800266 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
267 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700268 private static final int CMD_GET_MODEM_STATUS = 70;
269 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700270 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
271 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700272 private static final int CMD_ERASE_MODEM_CONFIG = 74;
273 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800274 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
275 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
276 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
277 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800278 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
279 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800280 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700281
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800282 // Parameters of select command.
283 private static final int SELECT_COMMAND = 0xA4;
284 private static final int SELECT_P1 = 0x04;
285 private static final int SELECT_P2 = 0;
286 private static final int SELECT_P3 = 0x10;
287
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700288 /** The singleton instance. */
289 private static PhoneInterfaceManager sInstance;
290
Wink Saville3ab207e2014-11-20 13:07:20 -0800291 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800292 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800293 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700294 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800295 private AppOpsManager mAppOps;
296 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800297 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800298 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700299 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700300
Peter Wangdafb9ac2020-01-15 14:13:38 -0800301 /** User Activity */
302 private AtomicBoolean mNotifyUserActivity;
303 private static final String ACTION_USER_ACTIVITY_NOTIFICATION =
304 "android.intent.action.USER_ACTIVITY_NOTIFICATION";
305 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
306
Derek Tan97ebb422014-09-05 16:55:38 -0700307 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
308 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800309 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800310 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700311
Michelecea4cf22018-12-21 15:00:11 -0800312 // String to store multi SIM allowed
313 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
314
Derek Tan740e1672017-06-27 14:56:27 -0700315 // The AID of ISD-R.
316 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
317
yinxub1bed742017-04-17 11:45:04 -0700318 private NetworkScanRequestTracker mNetworkScanRequestTracker;
319
David Kelly5e06a7f2018-03-12 14:10:59 +0000320 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
321 private static final int MANUFACTURER_CODE_LENGTH = 8;
322
Derek Tan89e89d42014-07-08 17:00:10 -0700323 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700324 * Experiment flag to enable erase modem config on reset network, default value is false
325 */
326 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
327 "reset_network_erase_modem_config_enabled";
328
329 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700330 * A request object to use for transmitting data to an ICC.
331 */
332 private static final class IccAPDUArgument {
333 public int channel, cla, command, p1, p2, p3;
334 public String data;
335
336 public IccAPDUArgument(int channel, int cla, int command,
337 int p1, int p2, int p3, String data) {
338 this.channel = channel;
339 this.cla = cla;
340 this.command = command;
341 this.p1 = p1;
342 this.p2 = p2;
343 this.p3 = p3;
344 this.data = data;
345 }
346 }
347
348 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700349 * A request object to use for transmitting data to an ICC.
350 */
351 private static final class ManualNetworkSelectionArgument {
352 public OperatorInfo operatorInfo;
353 public boolean persistSelection;
354
355 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
356 this.operatorInfo = operatorInfo;
357 this.persistSelection = persistSelection;
358 }
359 }
360
361 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
363 * request after sending. The main thread will notify the request when it is complete.
364 */
365 private static final class MainThreadRequest {
366 /** The argument to use for the request */
367 public Object argument;
368 /** The result of the request that is run on the main thread */
369 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800370 // The subscriber id that this request applies to. Defaults to
371 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
372 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373
Nathan Harold92bed182018-10-12 18:16:49 -0700374 // In cases where subId is unavailable, the caller needs to specify the phone.
375 public Phone phone;
376
vagdeviaf9a5b92018-08-15 16:01:53 -0700377 public WorkSource workSource;
378
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700379 public MainThreadRequest(Object argument) {
380 this.argument = argument;
381 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800382
Nathan Harold92bed182018-10-12 18:16:49 -0700383 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
384 this.argument = argument;
385 if (phone != null) {
386 this.phone = phone;
387 }
388 this.workSource = workSource;
389 }
390
vagdeviaf9a5b92018-08-15 16:01:53 -0700391 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800392 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800393 if (subId != null) {
394 this.subId = subId;
395 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700396 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800397 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398 }
399
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800400 private static final class IncomingThirdPartyCallArgs {
401 public final ComponentName component;
402 public final String callId;
403 public final String callerDisplayName;
404
405 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
406 String callerDisplayName) {
407 this.component = component;
408 this.callId = callId;
409 this.callerDisplayName = callerDisplayName;
410 }
411 }
412
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413 /**
414 * A handler that processes messages on the main thread in the phone process. Since many
415 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
416 * inbound binder threads to the main thread in the phone process. The Binder thread
417 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
418 * on, which will be notified when the operation completes and will contain the result of the
419 * request.
420 *
421 * <p>If a MainThreadRequest object is provided in the msg.obj field,
422 * note that request.result must be set to something non-null for the calling thread to
423 * unblock.
424 */
425 private final class MainThreadHandler extends Handler {
426 @Override
427 public void handleMessage(Message msg) {
428 MainThreadRequest request;
429 Message onCompleted;
430 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800431 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700432 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800433 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434
435 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700436 case CMD_HANDLE_USSD_REQUEST: {
437 request = (MainThreadRequest) msg.obj;
438 final Phone phone = getPhoneFromRequest(request);
439 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
440 String ussdRequest = ussdObject.first;
441 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700442
Pengquan Menga1bb6272018-09-06 09:59:22 -0700443 if (!isUssdApiAllowed(request.subId)) {
444 // Carrier does not support use of this API, return failure.
445 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
446 UssdResponse response = new UssdResponse(ussdRequest, null);
447 Bundle returnData = new Bundle();
448 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
449 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700450
Pengquan Menga1bb6272018-09-06 09:59:22 -0700451 request.result = true;
452 notifyRequester(request);
453 return;
454 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700455
Pengquan Menga1bb6272018-09-06 09:59:22 -0700456 try {
457 request.result = phone != null
458 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
459 } catch (CallStateException cse) {
460 request.result = false;
461 }
462 // Wake up the requesting thread
463 notifyRequester(request);
464 break;
pkanwar32d516d2016-10-14 19:37:38 -0700465 }
466
Yorke Lee716f67e2015-06-17 15:39:16 -0700467 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700468 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700469 final Phone phone = getPhoneFromRequest(request);
470 request.result = phone != null ?
471 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
472 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700473 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700474 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700475 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700476 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700477
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700478 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700479 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700480 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800481 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700482 if (uiccCard == null) {
483 loge("iccTransmitApduLogicalChannel: No UICC");
484 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700485 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700486 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
488 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700489 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 iccArgument.channel, iccArgument.cla, iccArgument.command,
491 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700492 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700493 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700494 break;
495
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700497 ar = (AsyncResult) msg.obj;
498 request = (MainThreadRequest) ar.userObj;
499 if (ar.exception == null && ar.result != null) {
500 request.result = ar.result;
501 } else {
502 request.result = new IccIoResult(0x6F, 0, (byte[])null);
503 if (ar.result == null) {
504 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800505 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700506 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800507 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700508 } else {
509 loge("iccTransmitApduLogicalChannel: Unknown exception");
510 }
511 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700512 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700513 break;
514
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700515 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
516 request = (MainThreadRequest) msg.obj;
517 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800518 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700519 if (uiccCard == null) {
520 loge("iccTransmitApduBasicChannel: No UICC");
521 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700522 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 } else {
524 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
525 request);
526 uiccCard.iccTransmitApduBasicChannel(
527 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
528 iccArgument.p3, iccArgument.data, onCompleted);
529 }
530 break;
531
532 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
533 ar = (AsyncResult) msg.obj;
534 request = (MainThreadRequest) ar.userObj;
535 if (ar.exception == null && ar.result != null) {
536 request.result = ar.result;
537 } else {
538 request.result = new IccIoResult(0x6F, 0, (byte[])null);
539 if (ar.result == null) {
540 loge("iccTransmitApduBasicChannel: Empty response");
541 } else if (ar.exception instanceof CommandException) {
542 loge("iccTransmitApduBasicChannel: CommandException: " +
543 ar.exception);
544 } else {
545 loge("iccTransmitApduBasicChannel: Unknown exception");
546 }
547 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700548 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700549 break;
550
551 case CMD_EXCHANGE_SIM_IO:
552 request = (MainThreadRequest) msg.obj;
553 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800554 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700555 if (uiccCard == null) {
556 loge("iccExchangeSimIO: No UICC");
557 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700558 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700559 } else {
560 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
561 request);
562 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
563 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
564 iccArgument.data, onCompleted);
565 }
566 break;
567
568 case EVENT_EXCHANGE_SIM_IO_DONE:
569 ar = (AsyncResult) msg.obj;
570 request = (MainThreadRequest) ar.userObj;
571 if (ar.exception == null && ar.result != null) {
572 request.result = ar.result;
573 } else {
574 request.result = new IccIoResult(0x6f, 0, (byte[])null);
575 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700576 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700577 break;
578
Derek Tan4d5e5c12014-02-04 11:54:58 -0800579 case CMD_SEND_ENVELOPE:
580 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800581 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700582 if (uiccCard == null) {
583 loge("sendEnvelopeWithStatus: No UICC");
584 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700585 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700586 } else {
587 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
588 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
589 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800590 break;
591
592 case EVENT_SEND_ENVELOPE_DONE:
593 ar = (AsyncResult) msg.obj;
594 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700595 if (ar.exception == null && ar.result != null) {
596 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800597 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700598 request.result = new IccIoResult(0x6F, 0, (byte[])null);
599 if (ar.result == null) {
600 loge("sendEnvelopeWithStatus: Empty response");
601 } else if (ar.exception instanceof CommandException) {
602 loge("sendEnvelopeWithStatus: CommandException: " +
603 ar.exception);
604 } else {
605 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
606 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800607 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700608 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800609 break;
610
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 case CMD_OPEN_CHANNEL:
612 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800613 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800614 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700615 if (uiccCard == null) {
616 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800617 request.result = new IccOpenLogicalChannelResponse(-1,
618 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700620 } else {
621 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800622 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
623 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700624 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 break;
626
627 case EVENT_OPEN_CHANNEL_DONE:
628 ar = (AsyncResult) msg.obj;
629 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700632 int[] result = (int[]) ar.result;
633 int channelId = result[0];
634 byte[] selectResponse = null;
635 if (result.length > 1) {
636 selectResponse = new byte[result.length - 1];
637 for (int i = 1; i < result.length; ++i) {
638 selectResponse[i - 1] = (byte) result[i];
639 }
640 }
641 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700642 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 if (ar.result == null) {
645 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700647 if (ar.exception != null) {
648 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
649 }
650
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700651 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700652 if (ar.exception instanceof CommandException) {
653 CommandException.Error error =
654 ((CommandException) (ar.exception)).getCommandError();
655 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700656 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700657 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700658 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700659 }
660 }
661 openChannelResp = new IccOpenLogicalChannelResponse(
662 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700664 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700665 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700666 break;
667
668 case CMD_CLOSE_CHANNEL:
669 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800670 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700671 if (uiccCard == null) {
672 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900673 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700674 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700675 } else {
676 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
677 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
678 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 break;
680
681 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800682 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
683 break;
684
685 case CMD_NV_READ_ITEM:
686 request = (MainThreadRequest) msg.obj;
687 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800688 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
689 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800690 break;
691
692 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700693 ar = (AsyncResult) msg.obj;
694 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800695 if (ar.exception == null && ar.result != null) {
696 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700697 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800698 request.result = "";
699 if (ar.result == null) {
700 loge("nvReadItem: Empty response");
701 } else if (ar.exception instanceof CommandException) {
702 loge("nvReadItem: CommandException: " +
703 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700704 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800705 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 }
707 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700708 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700709 break;
710
Jake Hambye994d462014-02-03 13:10:13 -0800711 case CMD_NV_WRITE_ITEM:
712 request = (MainThreadRequest) msg.obj;
713 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
714 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800715 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700716 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800717 break;
718
719 case EVENT_NV_WRITE_ITEM_DONE:
720 handleNullReturnEvent(msg, "nvWriteItem");
721 break;
722
723 case CMD_NV_WRITE_CDMA_PRL:
724 request = (MainThreadRequest) msg.obj;
725 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800726 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800727 break;
728
729 case EVENT_NV_WRITE_CDMA_PRL_DONE:
730 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
731 break;
732
chen xu6dac5ab2018-10-26 17:39:23 -0700733 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800734 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700735 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800736 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800737 break;
738
chen xu6dac5ab2018-10-26 17:39:23 -0700739 case EVENT_RESET_MODEM_CONFIG_DONE:
740 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800741 break;
742
Jake Hamby7c27be32014-03-03 13:25:59 -0800743 case CMD_GET_PREFERRED_NETWORK_TYPE:
744 request = (MainThreadRequest) msg.obj;
745 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700746 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800747 break;
748
749 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
750 ar = (AsyncResult) msg.obj;
751 request = (MainThreadRequest) ar.userObj;
752 if (ar.exception == null && ar.result != null) {
753 request.result = ar.result; // Integer
754 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800755 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800756 if (ar.result == null) {
757 loge("getPreferredNetworkType: Empty response");
758 } else if (ar.exception instanceof CommandException) {
759 loge("getPreferredNetworkType: CommandException: " +
760 ar.exception);
761 } else {
762 loge("getPreferredNetworkType: Unknown exception");
763 }
764 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700765 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800766 break;
767
768 case CMD_SET_PREFERRED_NETWORK_TYPE:
769 request = (MainThreadRequest) msg.obj;
770 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
771 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700772 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800773 break;
774
775 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
776 handleNullReturnEvent(msg, "setPreferredNetworkType");
777 break;
778
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000779 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
780 request = (MainThreadRequest)msg.obj;
781 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800782 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000783 break;
784
785 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
786 ar = (AsyncResult)msg.obj;
787 request = (MainThreadRequest)ar.userObj;
788 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700789 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000790 break;
791
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800792 case CMD_SET_VOICEMAIL_NUMBER:
793 request = (MainThreadRequest) msg.obj;
794 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
795 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800796 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
797 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800798 break;
799
800 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
801 handleNullReturnEvent(msg, "setVoicemailNumber");
802 break;
803
Stuart Scott54788802015-03-30 13:18:01 -0700804 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
805 request = (MainThreadRequest) msg.obj;
806 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
807 request);
808 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
809 break;
810
811 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
812 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
813 break;
814
Shishir Agrawal302c8692015-06-19 13:49:39 -0700815 case CMD_PERFORM_NETWORK_SCAN:
816 request = (MainThreadRequest) msg.obj;
817 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
818 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
819 break;
820
821 case EVENT_PERFORM_NETWORK_SCAN_DONE:
822 ar = (AsyncResult) msg.obj;
823 request = (MainThreadRequest) ar.userObj;
824 CellNetworkScanResult cellScanResult;
825 if (ar.exception == null && ar.result != null) {
826 cellScanResult = new CellNetworkScanResult(
827 CellNetworkScanResult.STATUS_SUCCESS,
828 (List<OperatorInfo>) ar.result);
829 } else {
830 if (ar.result == null) {
831 loge("getCellNetworkScanResults: Empty response");
832 }
833 if (ar.exception != null) {
834 loge("getCellNetworkScanResults: Exception: " + ar.exception);
835 }
836 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
837 if (ar.exception instanceof CommandException) {
838 CommandException.Error error =
839 ((CommandException) (ar.exception)).getCommandError();
840 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
841 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
842 } else if (error == CommandException.Error.GENERIC_FAILURE) {
843 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
844 }
845 }
846 cellScanResult = new CellNetworkScanResult(errorCode, null);
847 }
848 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700849 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700850 break;
851
852 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
853 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700854 ManualNetworkSelectionArgument selArg =
855 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700856 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
857 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700858 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
859 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700860 break;
861
862 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700863 ar = (AsyncResult) msg.obj;
864 request = (MainThreadRequest) ar.userObj;
865 if (ar.exception == null) {
866 request.result = true;
867 } else {
868 request.result = false;
869 loge("setNetworkSelectionModeManual " + ar.exception);
870 }
871 notifyRequester(request);
872 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700873 break;
874
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700875 case CMD_GET_MODEM_ACTIVITY_INFO:
876 request = (MainThreadRequest) msg.obj;
877 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700878 if (defaultPhone != null) {
879 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
880 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700881 break;
882
883 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
884 ar = (AsyncResult) msg.obj;
885 request = (MainThreadRequest) ar.userObj;
886 if (ar.exception == null && ar.result != null) {
887 request.result = ar.result;
888 } else {
889 if (ar.result == null) {
890 loge("queryModemActivityInfo: Empty response");
891 } else if (ar.exception instanceof CommandException) {
892 loge("queryModemActivityInfo: CommandException: " +
893 ar.exception);
894 } else {
895 loge("queryModemActivityInfo: Unknown exception");
896 }
897 }
Amit Mahajand4766222016-01-28 15:28:28 -0800898 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
899 if (request.result == null) {
Peter Collingbournec00e9022019-11-26 09:56:26 -0800900 request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800901 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700902 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700903 break;
904
Meng Wang1a7c35a2016-05-05 20:56:15 -0700905 case CMD_SET_ALLOWED_CARRIERS:
906 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800907 CarrierRestrictionRules argument =
908 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700909 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800910 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700911 break;
912
913 case EVENT_SET_ALLOWED_CARRIERS_DONE:
914 ar = (AsyncResult) msg.obj;
915 request = (MainThreadRequest) ar.userObj;
916 if (ar.exception == null && ar.result != null) {
917 request.result = ar.result;
918 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800919 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
920 if (ar.exception instanceof CommandException) {
921 loge("setAllowedCarriers: CommandException: " + ar.exception);
922 CommandException.Error error =
923 ((CommandException) (ar.exception)).getCommandError();
924 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
925 request.result =
926 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
927 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700928 } else {
929 loge("setAllowedCarriers: Unknown exception");
930 }
931 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700932 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700933 break;
934
935 case CMD_GET_ALLOWED_CARRIERS:
936 request = (MainThreadRequest) msg.obj;
937 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800938 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700939 break;
940
941 case EVENT_GET_ALLOWED_CARRIERS_DONE:
942 ar = (AsyncResult) msg.obj;
943 request = (MainThreadRequest) ar.userObj;
944 if (ar.exception == null && ar.result != null) {
945 request.result = ar.result;
946 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800947 request.result = new IllegalStateException(
948 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700949 if (ar.result == null) {
950 loge("getAllowedCarriers: Empty response");
951 } else if (ar.exception instanceof CommandException) {
952 loge("getAllowedCarriers: CommandException: " +
953 ar.exception);
954 } else {
955 loge("getAllowedCarriers: Unknown exception");
956 }
957 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700958 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700959 break;
960
Nathan Haroldb3014052017-01-25 15:57:32 -0800961 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
962 ar = (AsyncResult) msg.obj;
963 request = (MainThreadRequest) ar.userObj;
964 if (ar.exception == null && ar.result != null) {
965 request.result = ar.result;
966 } else {
967 request.result = new IllegalArgumentException(
968 "Failed to retrieve Forbidden Plmns");
969 if (ar.result == null) {
970 loge("getForbiddenPlmns: Empty response");
971 } else {
972 loge("getForbiddenPlmns: Unknown exception");
973 }
974 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700975 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800976 break;
977
978 case CMD_GET_FORBIDDEN_PLMNS:
979 request = (MainThreadRequest) msg.obj;
980 uiccCard = getUiccCardFromRequest(request);
981 if (uiccCard == null) {
982 loge("getForbiddenPlmns() UiccCard is null");
983 request.result = new IllegalArgumentException(
984 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700985 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800986 break;
987 }
988 Integer appType = (Integer) request.argument;
989 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
990 if (uiccApp == null) {
991 loge("getForbiddenPlmns() no app with specified type -- "
992 + appType);
993 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700994 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800995 break;
996 } else {
997 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
998 + " specified type -- " + appType);
999 }
1000 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1001 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1002 onCompleted);
1003 break;
1004
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001005 case CMD_SWITCH_SLOTS:
1006 request = (MainThreadRequest) msg.obj;
1007 int[] physicalSlots = (int[]) request.argument;
1008 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1009 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1010 break;
1011
1012 case EVENT_SWITCH_SLOTS_DONE:
1013 ar = (AsyncResult) msg.obj;
1014 request = (MainThreadRequest) ar.userObj;
1015 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001016 notifyRequester(request);
1017 break;
1018 case CMD_GET_NETWORK_SELECTION_MODE:
1019 request = (MainThreadRequest) msg.obj;
1020 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1021 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1022 break;
1023
1024 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1025 ar = (AsyncResult) msg.obj;
1026 request = (MainThreadRequest) ar.userObj;
1027 if (ar.exception != null) {
1028 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1029 } else {
1030 int mode = ((int[]) ar.result)[0];
1031 if (mode == 0) {
1032 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1033 } else {
1034 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1035 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001036 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001037 notifyRequester(request);
1038 break;
1039 case CMD_GET_CDMA_ROAMING_MODE:
1040 request = (MainThreadRequest) msg.obj;
1041 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1042 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1043 break;
1044 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1045 ar = (AsyncResult) msg.obj;
1046 request = (MainThreadRequest) ar.userObj;
1047 if (ar.exception != null) {
1048 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1049 } else {
1050 request.result = ((int[]) ar.result)[0];
1051 }
1052 notifyRequester(request);
1053 break;
1054 case CMD_SET_CDMA_ROAMING_MODE:
1055 request = (MainThreadRequest) msg.obj;
1056 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1057 int mode = (int) request.argument;
1058 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1059 break;
1060 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1061 ar = (AsyncResult) msg.obj;
1062 request = (MainThreadRequest) ar.userObj;
1063 request.result = ar.exception == null;
1064 notifyRequester(request);
1065 break;
1066 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1067 request = (MainThreadRequest) msg.obj;
1068 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1069 int subscriptionMode = (int) request.argument;
1070 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1071 break;
1072 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1073 ar = (AsyncResult) msg.obj;
1074 request = (MainThreadRequest) ar.userObj;
1075 request.result = ar.exception == null;
1076 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001077 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001078 case CMD_GET_ALL_CELL_INFO:
1079 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001080 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001081 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001082 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001083 case EVENT_GET_ALL_CELL_INFO_DONE:
1084 ar = (AsyncResult) msg.obj;
1085 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001086 // If a timeout occurs, the response will be null
1087 request.result = (ar.exception == null && ar.result != null)
1088 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001089 synchronized (request) {
1090 request.notifyAll();
1091 }
1092 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001093 case CMD_REQUEST_CELL_INFO_UPDATE:
1094 request = (MainThreadRequest) msg.obj;
1095 request.phone.requestCellInfoUpdate(request.workSource,
1096 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1097 break;
1098 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1099 ar = (AsyncResult) msg.obj;
1100 request = (MainThreadRequest) ar.userObj;
1101 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1102 try {
1103 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001104 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001105 cb.onError(
1106 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1107 ar.exception.getClass().getName(),
1108 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001109 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001110 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001111 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001112 } else {
1113 // use the result as returned
1114 cb.onCellInfo((List<CellInfo>) ar.result);
1115 }
1116 } catch (RemoteException re) {
1117 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1118 }
1119 break;
1120 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001121 request = (MainThreadRequest) msg.obj;
1122 WorkSource ws = (WorkSource) request.argument;
1123 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001124 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001125 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001126 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001127 ar = (AsyncResult) msg.obj;
1128 request = (MainThreadRequest) ar.userObj;
1129 if (ar.exception == null) {
1130 request.result = ar.result;
1131 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001132 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001133 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001134 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001135 }
1136
1137 synchronized (request) {
1138 request.notifyAll();
1139 }
1140 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001141 case CMD_MODEM_REBOOT:
1142 request = (MainThreadRequest) msg.obj;
1143 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001144 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001145 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001146 case EVENT_CMD_MODEM_REBOOT_DONE:
1147 handleNullReturnEvent(msg, "rebootModem");
1148 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001149 case CMD_REQUEST_ENABLE_MODEM:
1150 request = (MainThreadRequest) msg.obj;
1151 boolean enable = (boolean) request.argument;
1152 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001153 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001154 PhoneConfigurationManager.getInstance()
1155 .enablePhone(request.phone, enable, onCompleted);
1156 break;
1157 case EVENT_ENABLE_MODEM_DONE:
1158 ar = (AsyncResult) msg.obj;
1159 request = (MainThreadRequest) ar.userObj;
1160 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001161 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001162 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001163 if ((boolean) request.result) {
1164 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1165 updateModemStateMetrics();
1166 } else {
1167 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1168 + ar.exception);
1169 }
1170 notifyRequester(request);
1171 break;
1172 case CMD_GET_MODEM_STATUS:
1173 request = (MainThreadRequest) msg.obj;
1174 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1175 PhoneConfigurationManager.getInstance()
1176 .getPhoneStatusFromModem(request.phone, onCompleted);
1177 break;
1178 case EVENT_GET_MODEM_STATUS_DONE:
1179 ar = (AsyncResult) msg.obj;
1180 request = (MainThreadRequest) ar.userObj;
1181 int id = request.phone.getPhoneId();
1182 if (ar.exception == null && ar.result != null) {
1183 request.result = ar.result;
1184 //update the cache as modem status has changed
1185 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1186 (boolean) request.result);
1187 } else {
1188 // Return true if modem status cannot be retrieved. For most cases,
1189 // modem status is on. And for older version modems, GET_MODEM_STATUS
1190 // and disable modem are not supported. Modem is always on.
1191 // TODO: this should be fixed in R to support a third
1192 // status UNKNOWN b/131631629
1193 request.result = true;
1194 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1195 + ar.exception);
1196 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001197 notifyRequester(request);
1198 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001199 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1200 request = (MainThreadRequest) msg.obj;
1201 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1202 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1203 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1204 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1205 break;
1206 }
1207 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1208 ar = (AsyncResult) msg.obj;
1209 request = (MainThreadRequest) ar.userObj;
1210 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1211 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1212 args.second.accept(ar.exception == null);
1213 notifyRequester(request);
1214 break;
1215 }
yincheng zhao2737e882019-09-06 17:06:54 -07001216 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1217 ar = (AsyncResult) msg.obj;
1218 request = (MainThreadRequest) ar.userObj;
1219 if (ar.exception == null && ar.result != null) {
1220 request.result = ar.result;
1221 } else {
1222 request.result = -1;
1223 loge("Failed to set Forbidden Plmns");
1224 if (ar.result == null) {
1225 loge("setForbidenPlmns: Empty response");
1226 } else if (ar.exception != null) {
1227 loge("setForbiddenPlmns: Exception: " + ar.exception);
1228 request.result = -1;
1229 } else {
1230 loge("setForbiddenPlmns: Unknown exception");
1231 }
1232 }
1233 notifyRequester(request);
1234 break;
1235 case CMD_SET_FORBIDDEN_PLMNS:
1236 request = (MainThreadRequest) msg.obj;
1237 uiccCard = getUiccCardFromRequest(request);
1238 if (uiccCard == null) {
1239 loge("setForbiddenPlmns: UiccCard is null");
1240 request.result = -1;
1241 notifyRequester(request);
1242 break;
1243 }
1244 Pair<Integer, List<String>> setFplmnsArgs =
1245 (Pair<Integer, List<String>>) request.argument;
1246 appType = setFplmnsArgs.first;
1247 List<String> fplmns = setFplmnsArgs.second;
1248 uiccApp = uiccCard.getApplicationByType(appType);
1249 if (uiccApp == null) {
1250 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1251 request.result = -1;
1252 loge("Failed to get UICC App");
1253 notifyRequester(request);
1254 } else {
1255 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1256 ((SIMRecords) uiccApp.getIccRecords())
1257 .setForbiddenPlmns(onCompleted, fplmns);
1258 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001259 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001260 case CMD_ERASE_MODEM_CONFIG:
1261 request = (MainThreadRequest) msg.obj;
1262 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1263 defaultPhone.eraseModemConfig(onCompleted);
1264 break;
1265 case EVENT_ERASE_MODEM_CONFIG_DONE:
1266 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001267 break;
zoey chene02881a2019-12-30 16:11:23 +08001268
1269 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1270 request = (MainThreadRequest) msg.obj;
1271 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1272 Pair<String, String> changed = (Pair<String, String>) request.argument;
1273 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1274 changed.first, changed.second, onCompleted);
1275 break;
1276 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1277 ar = (AsyncResult) msg.obj;
1278 request = (MainThreadRequest) ar.userObj;
1279 if (ar.exception == null) {
1280 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1281 } else {
1282 request.result = msg.arg1;
1283 }
1284 notifyRequester(request);
1285 break;
1286
1287 case CMD_SET_ICC_LOCK_ENABLED:
1288 request = (MainThreadRequest) msg.obj;
1289 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1290 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1291 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1292 enabled.first, enabled.second, onCompleted);
1293 break;
1294 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1295 ar = (AsyncResult) msg.obj;
1296 request = (MainThreadRequest) ar.userObj;
1297 if (ar.exception == null) {
1298 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1299 } else {
1300 request.result = msg.arg1;
1301 }
1302 notifyRequester(request);
1303 break;
1304
Peter Wangdafb9ac2020-01-15 14:13:38 -08001305 case MSG_NOTIFY_USER_ACTIVITY:
1306 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
1307 Intent intent = new Intent(ACTION_USER_ACTIVITY_NOTIFICATION);
1308 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1309 getDefaultPhone().getContext().sendBroadcastAsUser(
1310 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1311 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001312 default:
1313 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1314 break;
1315 }
1316 }
Jake Hambye994d462014-02-03 13:10:13 -08001317
Pengquan Menga1bb6272018-09-06 09:59:22 -07001318 private void notifyRequester(MainThreadRequest request) {
1319 synchronized (request) {
1320 request.notifyAll();
1321 }
1322 }
1323
Jake Hambye994d462014-02-03 13:10:13 -08001324 private void handleNullReturnEvent(Message msg, String command) {
1325 AsyncResult ar = (AsyncResult) msg.obj;
1326 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1327 if (ar.exception == null) {
1328 request.result = true;
1329 } else {
1330 request.result = false;
1331 if (ar.exception instanceof CommandException) {
1332 loge(command + ": CommandException: " + ar.exception);
1333 } else {
1334 loge(command + ": Unknown exception");
1335 }
1336 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001337 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001338 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001339 }
1340
1341 /**
1342 * Posts the specified command to be executed on the main thread,
1343 * waits for the request to complete, and returns the result.
1344 * @see #sendRequestAsync
1345 */
1346 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001347 return sendRequest(
1348 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001349 }
1350
1351 /**
1352 * Posts the specified command to be executed on the main thread,
1353 * waits for the request to complete, and returns the result.
1354 * @see #sendRequestAsync
1355 */
1356 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1357 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001358 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001359 }
1360
1361 /**
1362 * Posts the specified command to be executed on the main thread,
1363 * waits for the request to complete, and returns the result.
1364 * @see #sendRequestAsync
1365 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001366 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001367 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001368 }
1369
1370 /**
1371 * Posts the specified command to be executed on the main thread,
1372 * waits for the request to complete, and returns the result.
1373 * @see #sendRequestAsync
1374 */
Nathan Harold92bed182018-10-12 18:16:49 -07001375 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1376 return sendRequest(command, argument, subId, null, workSource);
1377 }
1378
1379 /**
1380 * Posts the specified command to be executed on the main thread,
1381 * waits for the request to complete, and returns the result.
1382 * @see #sendRequestAsync
1383 */
1384 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1385 return sendRequest(
1386 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1387 }
1388
1389 /**
1390 * Posts the specified command to be executed on the main thread,
1391 * waits for the request to complete, and returns the result.
1392 * @see #sendRequestAsync
1393 */
1394 private Object sendRequest(
1395 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001396 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1397 throw new RuntimeException("This method will deadlock if called from the main thread.");
1398 }
1399
Nathan Harold92bed182018-10-12 18:16:49 -07001400 MainThreadRequest request = null;
1401 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1402 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1403 } else if (phone != null) {
1404 request = new MainThreadRequest(argument, phone, workSource);
1405 } else {
1406 request = new MainThreadRequest(argument, subId, workSource);
1407 }
1408
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001409 Message msg = mMainThreadHandler.obtainMessage(command, request);
1410 msg.sendToTarget();
1411
1412 // Wait for the request to complete
1413 synchronized (request) {
1414 while (request.result == null) {
1415 try {
1416 request.wait();
1417 } catch (InterruptedException e) {
1418 // Do nothing, go back and wait until the request is complete
1419 }
1420 }
1421 }
1422 return request.result;
1423 }
1424
1425 /**
1426 * Asynchronous ("fire and forget") version of sendRequest():
1427 * Posts the specified command to be executed on the main thread, and
1428 * returns immediately.
1429 * @see #sendRequest
1430 */
1431 private void sendRequestAsync(int command) {
1432 mMainThreadHandler.sendEmptyMessage(command);
1433 }
1434
1435 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001436 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001437 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001438 */
1439 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001440 sendRequestAsync(command, argument, null, null);
1441 }
1442
1443 /**
1444 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1445 * @see {@link #sendRequest(int,Object)}
1446 */
1447 private void sendRequestAsync(
1448 int command, Object argument, Phone phone, WorkSource workSource) {
1449 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001450 Message msg = mMainThreadHandler.obtainMessage(command, request);
1451 msg.sendToTarget();
1452 }
1453
1454 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001455 * Initialize the singleton PhoneInterfaceManager instance.
1456 * This is only done once, at startup, from PhoneApp.onCreate().
1457 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001458 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459 synchronized (PhoneInterfaceManager.class) {
1460 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001461 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001462 } else {
1463 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1464 }
1465 return sInstance;
1466 }
1467 }
1468
1469 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001470 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001471 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001472 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001473 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001474 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001475 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1476 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001477 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001478 mTelephonySharedPreferences =
1479 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001480 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001481 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001482
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001483 publish();
1484 }
1485
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001486 private Phone getDefaultPhone() {
1487 Phone thePhone = getPhone(getDefaultSubscription());
1488 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1489 }
1490
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001491 private void publish() {
1492 if (DBG) log("publish: " + this);
1493
Peter Wangc035ce42020-01-08 21:00:22 -08001494 TelephonyFrameworkInitializer
1495 .getTelephonyServiceManager()
1496 .getTelephonyServiceRegisterer()
1497 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001498 }
1499
Stuart Scott584921c2015-01-15 17:10:34 -08001500 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001501 if (request.phone != null) {
1502 return request.phone;
1503 } else {
1504 return getPhoneFromSubId(request.subId);
1505 }
1506 }
1507
1508 private Phone getPhoneFromSubId(int subId) {
1509 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1510 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001511 }
1512
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001513 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1514 Phone phone = getPhoneFromRequest(request);
1515 return phone == null ? null :
1516 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1517 }
1518
Wink Saville36469e72014-06-11 15:17:00 -07001519 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001520 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001521 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001522 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001523
Naina Nallurid63128d2019-09-17 14:10:30 -07001524 private void sendEraseModemConfig(Phone phone) {
1525 if (phone != null) {
1526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1527 mApp, phone.getSubId(), "eraseModemConfig");
1528 final long identity = Binder.clearCallingIdentity();
1529 try {
1530 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1531 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1532 } finally {
1533 Binder.restoreCallingIdentity(identity);
1534 }
1535 }
1536 }
1537
Peter Wang44b186e2020-01-13 23:33:09 -08001538 private boolean isImsAvailableOnDevice() {
1539 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1540 if (pm == null) {
1541 // For some reason package manger is not available.. This will fail internally anyway,
1542 // so do not throw error and allow.
1543 return true;
1544 }
1545 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1546 }
1547
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001548 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001549 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001550 }
1551
Wink Savilleb564aae2014-10-23 10:18:09 -07001552 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001553 if (DBG) log("dial: " + number);
1554 // No permission check needed here: This is just a wrapper around the
1555 // ACTION_DIAL intent, which is available to any app since it puts up
1556 // the UI before it does anything.
1557
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001558 final long identity = Binder.clearCallingIdentity();
1559 try {
1560 String url = createTelUrl(number);
1561 if (url == null) {
1562 return;
1563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001564
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001565 // PENDING: should we just silently fail if phone is offhook or ringing?
1566 PhoneConstants.State state = mCM.getState(subId);
1567 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1568 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1569 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1570 mApp.startActivity(intent);
1571 }
1572 } finally {
1573 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001574 }
1575 }
1576
1577 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001578 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001579 }
1580
Wink Savilleb564aae2014-10-23 10:18:09 -07001581 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001582 if (DBG) log("call: " + number);
1583
1584 // This is just a wrapper around the ACTION_CALL intent, but we still
1585 // need to do a permission check since we're calling startActivity()
1586 // from the context of the phone app.
1587 enforceCallPermission();
1588
Jordan Liu1617b712019-07-10 15:06:26 -07001589 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001590 != AppOpsManager.MODE_ALLOWED) {
1591 return;
1592 }
1593
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001594 final long identity = Binder.clearCallingIdentity();
1595 try {
1596 String url = createTelUrl(number);
1597 if (url == null) {
1598 return;
1599 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001600
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001601 boolean isValid = false;
1602 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1603 if (slist != null) {
1604 for (SubscriptionInfo subInfoRecord : slist) {
1605 if (subInfoRecord.getSubscriptionId() == subId) {
1606 isValid = true;
1607 break;
1608 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001609 }
Wink Saville08874612014-08-31 19:19:58 -07001610 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001611 if (!isValid) {
1612 return;
1613 }
Wink Saville08874612014-08-31 19:19:58 -07001614
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001615 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1616 intent.putExtra(SUBSCRIPTION_KEY, subId);
1617 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1618 mApp.startActivity(intent);
1619 } finally {
1620 Binder.restoreCallingIdentity(identity);
1621 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001622 }
1623
Wink Savilleb564aae2014-10-23 10:18:09 -07001624 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001625 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001626 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1627 }
1628
Wink Savilleb564aae2014-10-23 10:18:09 -07001629 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001630 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001631 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1632 }
1633
Wink Savilleb564aae2014-10-23 10:18:09 -07001634 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001635 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001636
1637 final long identity = Binder.clearCallingIdentity();
1638 try {
1639 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1640 checkSimPin.start();
1641 return checkSimPin.unlockSim(null, pin);
1642 } finally {
1643 Binder.restoreCallingIdentity(identity);
1644 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001645 }
1646
Wink Savilleb564aae2014-10-23 10:18:09 -07001647 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001648 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001649
1650 final long identity = Binder.clearCallingIdentity();
1651 try {
1652 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1653 checkSimPuk.start();
1654 return checkSimPuk.unlockSim(puk, pin);
1655 } finally {
1656 Binder.restoreCallingIdentity(identity);
1657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 }
1659
1660 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001661 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001662 * a synchronous one.
1663 */
1664 private static class UnlockSim extends Thread {
1665
1666 private final IccCard mSimCard;
1667
1668 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001669 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1670 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671
1672 // For replies from SimCard interface
1673 private Handler mHandler;
1674
1675 // For async handler to identify request type
1676 private static final int SUPPLY_PIN_COMPLETE = 100;
1677
1678 public UnlockSim(IccCard simCard) {
1679 mSimCard = simCard;
1680 }
1681
1682 @Override
1683 public void run() {
1684 Looper.prepare();
1685 synchronized (UnlockSim.this) {
1686 mHandler = new Handler() {
1687 @Override
1688 public void handleMessage(Message msg) {
1689 AsyncResult ar = (AsyncResult) msg.obj;
1690 switch (msg.what) {
1691 case SUPPLY_PIN_COMPLETE:
1692 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1693 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001694 mRetryCount = msg.arg1;
1695 if (ar.exception != null) {
1696 if (ar.exception instanceof CommandException &&
1697 ((CommandException)(ar.exception)).getCommandError()
1698 == CommandException.Error.PASSWORD_INCORRECT) {
1699 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1700 } else {
1701 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1702 }
1703 } else {
1704 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1705 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001706 mDone = true;
1707 UnlockSim.this.notifyAll();
1708 }
1709 break;
1710 }
1711 }
1712 };
1713 UnlockSim.this.notifyAll();
1714 }
1715 Looper.loop();
1716 }
1717
1718 /*
1719 * Use PIN or PUK to unlock SIM card
1720 *
1721 * If PUK is null, unlock SIM card with PIN
1722 *
1723 * If PUK is not null, unlock SIM card with PUK and set PIN code
1724 */
Wink Saville9de0f752013-10-22 19:04:03 -07001725 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001726
1727 while (mHandler == null) {
1728 try {
1729 wait();
1730 } catch (InterruptedException e) {
1731 Thread.currentThread().interrupt();
1732 }
1733 }
1734 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1735
1736 if (puk == null) {
1737 mSimCard.supplyPin(pin, callback);
1738 } else {
1739 mSimCard.supplyPuk(puk, pin, callback);
1740 }
1741
1742 while (!mDone) {
1743 try {
1744 Log.d(LOG_TAG, "wait for done");
1745 wait();
1746 } catch (InterruptedException e) {
1747 // Restore the interrupted status
1748 Thread.currentThread().interrupt();
1749 }
1750 }
1751 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001752 int[] resultArray = new int[2];
1753 resultArray[0] = mResult;
1754 resultArray[1] = mRetryCount;
1755 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 }
1757 }
1758
1759 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001760 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001761
1762 }
1763
Wink Savilleb564aae2014-10-23 10:18:09 -07001764 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001765 // No permission check needed here: this call is harmless, and it's
1766 // needed for the ServiceState.requestStateUpdate() call (which is
1767 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001768 final long identity = Binder.clearCallingIdentity();
1769 try {
1770 final Phone phone = getPhone(subId);
1771 if (phone != null) {
1772 phone.updateServiceLocation();
1773 }
1774 } finally {
1775 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001777 }
1778
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001779 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001780 @Override
1781 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001782 return isRadioOnWithFeature(callingPackage, null);
1783 }
1784
1785
1786 @Override
1787 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1788 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1789 callingFeatureId);
1790 }
1791
1792 @Deprecated
1793 @Override
1794 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1795 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001796 }
1797
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001798 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001799 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1800 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001801 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001802 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001803 return false;
1804 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001805
1806 final long identity = Binder.clearCallingIdentity();
1807 try {
1808 return isRadioOnForSubscriber(subId);
1809 } finally {
1810 Binder.restoreCallingIdentity(identity);
1811 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001812 }
1813
1814 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001815 final long identity = Binder.clearCallingIdentity();
1816 try {
1817 final Phone phone = getPhone(subId);
1818 if (phone != null) {
1819 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1820 } else {
1821 return false;
1822 }
1823 } finally {
1824 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001825 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001826 }
1827
1828 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001829 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001830 }
Wink Saville36469e72014-06-11 15:17:00 -07001831
Wink Savilleb564aae2014-10-23 10:18:09 -07001832 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001833 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001834
1835 final long identity = Binder.clearCallingIdentity();
1836 try {
1837 final Phone phone = getPhone(subId);
1838 if (phone != null) {
1839 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1840 }
1841 } finally {
1842 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001843 }
Wink Saville36469e72014-06-11 15:17:00 -07001844 }
1845
1846 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001847 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001848 }
1849
Wink Savilleb564aae2014-10-23 10:18:09 -07001850 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001851 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001852
1853 final long identity = Binder.clearCallingIdentity();
1854 try {
1855 final Phone phone = getPhone(subId);
1856 if (phone == null) {
1857 return false;
1858 }
1859 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1860 toggleRadioOnOffForSubscriber(subId);
1861 }
1862 return true;
1863 } finally {
1864 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001865 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001866 }
Wink Saville36469e72014-06-11 15:17:00 -07001867
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001868 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08001869 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001870 /*
1871 * If any of the Radios are available, it will need to be
1872 * shutdown. So return true if any Radio is available.
1873 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001874 final long identity = Binder.clearCallingIdentity();
1875 try {
1876 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1877 Phone phone = PhoneFactory.getPhone(i);
1878 if (phone != null && phone.isRadioAvailable()) return true;
1879 }
1880 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1881 return false;
1882 } finally {
1883 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001884 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001885 }
1886
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001887 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001888 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001889 enforceModifyPermission();
1890
1891 final long identity = Binder.clearCallingIdentity();
1892 try {
1893 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1894 logv("Shutting down Phone " + i);
1895 shutdownRadioUsingPhoneId(i);
1896 }
1897 } finally {
1898 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001899 }
1900 }
1901
1902 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001903 Phone phone = PhoneFactory.getPhone(phoneId);
1904 if (phone != null && phone.isRadioAvailable()) {
1905 phone.shutdownRadio();
1906 }
1907 }
1908
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001909 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001910 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001911
1912 final long identity = Binder.clearCallingIdentity();
1913 try {
1914 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1915 if (defaultPhone != null) {
1916 defaultPhone.setRadioPower(turnOn);
1917 return true;
1918 } else {
1919 loge("There's no default phone.");
1920 return false;
1921 }
1922 } finally {
1923 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001924 }
Wink Saville36469e72014-06-11 15:17:00 -07001925 }
1926
Wink Savilleb564aae2014-10-23 10:18:09 -07001927 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001928 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001929
1930 final long identity = Binder.clearCallingIdentity();
1931 try {
1932 final Phone phone = getPhone(subId);
1933 if (phone != null) {
1934 phone.setRadioPower(turnOn);
1935 return true;
1936 } else {
1937 return false;
1938 }
1939 } finally {
1940 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001941 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 }
1943
Wink Saville36469e72014-06-11 15:17:00 -07001944 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001945 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946 public boolean enableDataConnectivity() {
1947 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001948
1949 final long identity = Binder.clearCallingIdentity();
1950 try {
1951 int subId = mSubscriptionController.getDefaultDataSubId();
1952 final Phone phone = getPhone(subId);
1953 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001954 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001955 return true;
1956 } else {
1957 return false;
1958 }
1959 } finally {
1960 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001961 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001962 }
1963
Wink Saville36469e72014-06-11 15:17:00 -07001964 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001965 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001966 public boolean disableDataConnectivity() {
1967 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001968
1969 final long identity = Binder.clearCallingIdentity();
1970 try {
1971 int subId = mSubscriptionController.getDefaultDataSubId();
1972 final Phone phone = getPhone(subId);
1973 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001974 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001975 return true;
1976 } else {
1977 return false;
1978 }
1979 } finally {
1980 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001981 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001982 }
1983
Sanket Padawe356d7632015-06-22 14:03:32 -07001984 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001985 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001986 final long identity = Binder.clearCallingIdentity();
1987 try {
1988 final Phone phone = getPhone(subId);
1989 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001990 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001991 } else {
1992 return false;
1993 }
1994 } finally {
1995 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001996 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001997 }
1998
1999 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002000 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002001 }
2002
pkanwarae03a6b2016-11-06 20:37:09 -08002003 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002004 enforceCallPermission();
2005
2006 final long identity = Binder.clearCallingIdentity();
2007 try {
2008 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2009 return;
2010 }
2011 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2012 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2013 } finally {
2014 Binder.restoreCallingIdentity(identity);
2015 }
pkanwar32d516d2016-10-14 19:37:38 -07002016 };
2017
Wink Savilleb564aae2014-10-23 10:18:09 -07002018 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002019 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002020
2021 final long identity = Binder.clearCallingIdentity();
2022 try {
2023 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2024 return false;
2025 }
2026 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2027 } finally {
2028 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002029 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002030 }
2031
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002032 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002033 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002034 }
2035
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002036 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002037 final long identity = Binder.clearCallingIdentity();
2038 try {
2039 Phone phone = PhoneFactory.getPhone(slotIndex);
2040 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2041 PhoneConstantConversions.convertCallState(phone.getState());
2042 } finally {
2043 Binder.restoreCallingIdentity(identity);
2044 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002045 }
2046
Sanket Padawe356d7632015-06-22 14:03:32 -07002047 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002048 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002049 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2050 }
2051
2052 @Override
2053 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002054 final long identity = Binder.clearCallingIdentity();
2055 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002056 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002057 if (phone != null) {
2058 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2059 } else {
2060 return PhoneConstantConversions.convertDataState(
2061 PhoneConstants.DataState.DISCONNECTED);
2062 }
2063 } finally {
2064 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002065 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002066 }
2067
Sanket Padawe356d7632015-06-22 14:03:32 -07002068 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002069 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002070 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2071 }
2072
2073 @Override
2074 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002075 final long identity = Binder.clearCallingIdentity();
2076 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002077 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002078 if (phone != null) {
2079 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2080 } else {
2081 return TelephonyManager.DATA_ACTIVITY_NONE;
2082 }
2083 } finally {
2084 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002085 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002086 }
2087
2088 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002089 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002090 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002091 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002092
2093 LocationAccessPolicy.LocationPermissionResult locationResult =
2094 LocationAccessPolicy.checkLocationPermission(mApp,
2095 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2096 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002097 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002098 .setCallingPid(Binder.getCallingPid())
2099 .setCallingUid(Binder.getCallingUid())
2100 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002101 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002102 .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 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004768 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4769 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004770 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004771 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004772 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004773
4774 final long identity = Binder.clearCallingIdentity();
4775 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004776 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004777 // may happen if the device does not support IMS.
4778 return;
4779 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004780 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004781 } finally {
4782 Binder.restoreCallingIdentity(identity);
4783 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004784 }
4785
4786 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004787 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4788 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004789 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004790 public void disableIms(int slotId) {
4791 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004792
4793 final long identity = Binder.clearCallingIdentity();
4794 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004795 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004796 // may happen if the device does not support IMS.
4797 return;
4798 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004799 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004800 } finally {
4801 Binder.restoreCallingIdentity(identity);
4802 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004803 }
4804
4805 /**
4806 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4807 * feature or {@link null} if the service is not available. If the feature is available, the
4808 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4809 */
4810 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004811 IImsServiceFeatureCallback callback) {
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 null;
4819 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004820 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004821 } finally {
4822 Binder.restoreCallingIdentity(identity);
4823 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004824 }
4825
4826 /**
4827 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4828 * feature during emergency calling or {@link null} if the service is not available. If the
4829 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4830 * listener for feature updates.
4831 */
4832 public IImsRcsFeature getRcsFeatureAndListen(int slotId, 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.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004842 } finally {
4843 Binder.restoreCallingIdentity(identity);
4844 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004845 }
4846
Brad Ebinger5f64b052017-12-14 14:26:15 -08004847 /**
4848 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004849 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004850 */
4851 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4852 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004853
4854 final long identity = Binder.clearCallingIdentity();
4855 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004856 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004857 // may happen if the device does not support IMS.
4858 return null;
4859 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004860 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004861 } finally {
4862 Binder.restoreCallingIdentity(identity);
4863 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004864 }
4865
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004866 /**
4867 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004868 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004869 */
4870 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4871 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004872
4873 final long identity = Binder.clearCallingIdentity();
4874 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004875 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004876 // may happen if the device does not support IMS.
4877 return null;
4878 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004879 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004880 } finally {
4881 Binder.restoreCallingIdentity(identity);
4882 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004883 }
4884
Brad Ebinger884c07b2018-02-15 16:17:40 -08004885 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004886 * Sets the ImsService Package Name that Telephony will bind to.
4887 *
Brad Ebinger24c29992019-12-05 13:03:21 -08004888 * @param slotIndex the slot ID that the ImsService should bind for.
4889 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004890 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08004891 * @param featureTypes An integer array of feature types associated with a packageName.
4892 * @param packageName The name of the package that the current configuration will be replaced
4893 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004894 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004895 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004896 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4897 int[] featureTypes, String packageName) {
4898 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4899 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004900 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4901 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08004902 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004903
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004904 final long identity = Binder.clearCallingIdentity();
4905 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004906 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004907 // may happen if the device does not support IMS.
4908 return false;
4909 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004910 Map<Integer, String> featureConfig = new HashMap<>();
4911 for (int featureType : featureTypes) {
4912 featureConfig.put(featureType, packageName);
4913 }
4914 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4915 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004916 } finally {
4917 Binder.restoreCallingIdentity(identity);
4918 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004919 }
4920
4921 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08004922 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004923 *
4924 * @param slotId The slot that the ImsService is associated with.
4925 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4926 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08004927 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004928 * @return the package name of the ImsService configuration.
4929 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004930 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4931 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004932 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08004933 TelephonyPermissions
4934 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4935 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4936 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004937
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004938 final long identity = Binder.clearCallingIdentity();
4939 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004940 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004941 // may happen if the device does not support IMS.
4942 return "";
4943 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004944 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08004945 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4946 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004947 } finally {
4948 Binder.restoreCallingIdentity(identity);
4949 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004950 }
4951
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004952 /**
4953 * Get the MmTelFeature state associated with the requested subscription id.
4954 * @param subId The subscription that the MmTelFeature is associated with.
4955 * @param callback A callback with an integer containing the
4956 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4957 */
4958 @Override
4959 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4960 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4961 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4962 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4963 "IMS not available on device.");
4964 }
4965 final long token = Binder.clearCallingIdentity();
4966 try {
4967 int slotId = getSlotIndex(subId);
4968 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4969 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4970 + subId + "'");
4971 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4972 }
4973 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4974 try {
4975 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4976 } catch (RemoteException e) {
4977 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4978 + "Ignore");
4979 }
4980 });
4981 } finally {
4982 Binder.restoreCallingIdentity(token);
4983 }
4984 }
4985
Wink Saville36469e72014-06-11 15:17:00 -07004986 public void setImsRegistrationState(boolean registered) {
4987 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004988
4989 final long identity = Binder.clearCallingIdentity();
4990 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004991 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004992 } finally {
4993 Binder.restoreCallingIdentity(identity);
4994 }
Wink Saville36469e72014-06-11 15:17:00 -07004995 }
4996
4997 /**
Stuart Scott54788802015-03-30 13:18:01 -07004998 * Set the network selection mode to automatic.
4999 *
5000 */
5001 @Override
5002 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5004 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005005
5006 final long identity = Binder.clearCallingIdentity();
5007 try {
shilufc958392020-01-20 11:36:01 -08005008 if (!isActiveSubscription(subId)) {
5009 return;
5010 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005011 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5012 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5013 } finally {
5014 Binder.restoreCallingIdentity(identity);
5015 }
Stuart Scott54788802015-03-30 13:18:01 -07005016 }
5017
Pengquan Mengea84e042018-09-20 14:57:26 -07005018 /**
5019 * Ask the radio to connect to the input network and change selection mode to manual.
5020 *
5021 * @param subId the id of the subscription.
5022 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5023 * the operator to attach to.
5024 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5025 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5026 * normal network selection next time.
5027 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005028 */
5029 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005030 public boolean setNetworkSelectionModeManual(
5031 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005032 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5033 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005034
5035 if (!isActiveSubscription(subId)) {
5036 return false;
5037 }
5038
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005039 final long identity = Binder.clearCallingIdentity();
5040 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005041 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005042 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005043 if (DBG) {
5044 log("setNetworkSelectionModeManual: subId: " + subId
5045 + " operator: " + operatorInfo);
5046 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005047 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5048 } finally {
5049 Binder.restoreCallingIdentity(identity);
5050 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005051 }
shilu84f6e8b2019-12-19 13:58:01 -08005052 /**
5053 * Get the manual network selection
5054 *
5055 * @param subId the id of the subscription.
5056 *
5057 * @return the previously saved user selected PLMN
5058 */
5059 @Override
5060 public String getManualNetworkSelectionPlmn(int subId) {
5061 TelephonyPermissions
5062 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5063 mApp, subId, "getManualNetworkSelectionPlmn");
5064
5065 final long identity = Binder.clearCallingIdentity();
5066 try {
5067 if (!isActiveSubscription(subId)) {
5068 return "";
5069 }
5070
5071 final Phone phone = getPhone(subId);
5072 if (phone == null) {
5073 return "";
5074 }
5075 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5076 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5077 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5078 } finally {
5079 Binder.restoreCallingIdentity(identity);
5080 }
5081 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005082
5083 /**
5084 * Scans for available networks.
5085 */
5086 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005087 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5088 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005089 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5090 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005091 LocationAccessPolicy.LocationPermissionResult locationResult =
5092 LocationAccessPolicy.checkLocationPermission(mApp,
5093 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5094 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005095 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005096 .setCallingPid(Binder.getCallingPid())
5097 .setCallingUid(Binder.getCallingUid())
5098 .setMethod("getCellNetworkScanResults")
5099 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5100 .build());
5101 switch (locationResult) {
5102 case DENIED_HARD:
5103 throw new SecurityException("Not allowed to access scan results -- location");
5104 case DENIED_SOFT:
5105 return null;
5106 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005107
Pengquan Menga1bb6272018-09-06 09:59:22 -07005108 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005109 try {
5110 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005111 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005112 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005113 } finally {
5114 Binder.restoreCallingIdentity(identity);
5115 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005116 }
5117
5118 /**
yinxub1bed742017-04-17 11:45:04 -07005119 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005120 *
yinxub1bed742017-04-17 11:45:04 -07005121 * @param subId id of the subscription
5122 * @param request contains the radio access networks with bands/channels to scan
5123 * @param messenger callback messenger for scan results or errors
5124 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005125 * @return the id of the requested scan which can be used to stop the scan.
5126 */
5127 @Override
5128 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005129 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005130 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5131 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005132 LocationAccessPolicy.LocationPermissionResult locationResult =
5133 LocationAccessPolicy.checkLocationPermission(mApp,
5134 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5135 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005136 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005137 .setCallingPid(Binder.getCallingPid())
5138 .setCallingUid(Binder.getCallingUid())
5139 .setMethod("requestNetworkScan")
5140 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5141 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005142 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005143 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005144 if (e != null) {
5145 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5146 throw e;
5147 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005148 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005149 return TelephonyScanManager.INVALID_SCAN_ID;
5150 }
5151 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005152 }
Hall Liu912dfd32019-04-25 14:02:26 -07005153 int callingUid = Binder.getCallingUid();
5154 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005155 final long identity = Binder.clearCallingIdentity();
5156 try {
5157 return mNetworkScanRequestTracker.startNetworkScan(
5158 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005159 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005160 } finally {
5161 Binder.restoreCallingIdentity(identity);
5162 }
yinxu504e1392017-04-12 16:03:22 -07005163 }
5164
Hall Liub2ac8ef2019-02-28 15:56:23 -08005165 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005166 NetworkScanRequest request, int subId) {
5167 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5168 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5169 boolean hasNetworkScanPermission =
5170 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5171 == PERMISSION_GRANTED;
5172
5173 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5174 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5175 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005176 }
5177
5178 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5179 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005180 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5181 return new SecurityException("Specific channels must not be"
5182 + " scanned without location access.");
5183 }
5184 }
5185 }
5186
Hall Liub2ac8ef2019-02-28 15:56:23 -08005187 return null;
5188 }
5189
yinxu504e1392017-04-12 16:03:22 -07005190 /**
5191 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005192 *
5193 * @param subId id of the subscription
5194 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005195 */
5196 @Override
5197 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005198 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5199 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005200
Hall Liu912dfd32019-04-25 14:02:26 -07005201 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005202 final long identity = Binder.clearCallingIdentity();
5203 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005204 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005205 } finally {
5206 Binder.restoreCallingIdentity(identity);
5207 }
yinxu504e1392017-04-12 16:03:22 -07005208 }
5209
5210 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005211 * Get the calculated preferred network type.
5212 * Used for debugging incorrect network type.
5213 *
5214 * @return the preferred network type, defined in RILConstants.java.
5215 */
5216 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005217 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005218 final Phone defaultPhone = getDefaultPhone();
5219 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005220 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005221 return RILConstants.PREFERRED_NETWORK_MODE;
5222 }
5223
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005224 final long identity = Binder.clearCallingIdentity();
5225 try {
5226 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005227 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005228 } finally {
5229 Binder.restoreCallingIdentity(identity);
5230 }
Junda Liu84d15a22014-07-02 11:21:04 -07005231 }
5232
5233 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005234 * Get the preferred network type.
5235 * Used for device configuration by some CDMA operators.
5236 *
5237 * @return the preferred network type, defined in RILConstants.java.
5238 */
5239 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005240 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005241 TelephonyPermissions
5242 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5243 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005244
5245 final long identity = Binder.clearCallingIdentity();
5246 try {
5247 if (DBG) log("getPreferredNetworkType");
5248 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5249 int networkType = (result != null ? result[0] : -1);
5250 if (DBG) log("getPreferredNetworkType: " + networkType);
5251 return networkType;
5252 } finally {
5253 Binder.restoreCallingIdentity(identity);
5254 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005255 }
5256
5257 /**
5258 * Set the preferred network type.
5259 * Used for device configuration by some CDMA operators.
5260 *
5261 * @param networkType the preferred network type, defined in RILConstants.java.
5262 * @return true on success; false on any failure.
5263 */
5264 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005265 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5267 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005268
5269 final long identity = Binder.clearCallingIdentity();
5270 try {
calvinpan0ac9c1a2020-01-14 20:42:55 +08005271 Settings.Global.putInt(mApp.getContentResolver(),
5272 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5273 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005274 } finally {
5275 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005276 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005277 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005278
5279 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005280 * Get the allowed network types that store in the telephony provider.
5281 *
5282 * @param subId the id of the subscription.
5283 * @return allowedNetworkTypes the allowed network types.
5284 */
5285 @Override
5286 public long getAllowedNetworkTypes(int subId) {
5287 TelephonyPermissions
5288 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5289 mApp, subId, "getAllowedNetworkTypes");
5290
5291 final long identity = Binder.clearCallingIdentity();
5292 try {
5293 return SubscriptionManager.getLongSubscriptionProperty(
5294 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5295 } finally {
5296 Binder.restoreCallingIdentity(identity);
5297 }
5298 }
5299
5300 /**
5301 * Set the allowed network types.
5302 *
5303 * @param subId the id of the subscription.
5304 * @param allowedNetworkTypes the allowed network types.
5305 * @return true on success; false on any failure.
5306 */
5307 @Override
5308 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5310 mApp, subId, "setAllowedNetworkTypes");
5311 final long identity = Binder.clearCallingIdentity();
5312 try {
5313 SubscriptionManager.setSubscriptionProperty(subId,
5314 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5315 String.valueOf(allowedNetworkTypes));
5316 return setPreferredNetworkTypesInternal(subId);
5317 } finally {
5318 Binder.restoreCallingIdentity(identity);
5319 }
5320 }
5321
5322 private boolean setPreferredNetworkTypesInternal(int subId) {
5323 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5324 Settings.Global.getInt(mApp.getContentResolver(),
5325 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5326 RILConstants.PREFERRED_NETWORK_MODE));
5327 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5328 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5329 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5330 (int) (networkTypeBitMask & allowedNetworkTypes));
5331
5332 if (DBG) {
5333 log("setPreferredNetworkTypesInternal: subId " + subId
5334 + " networkTypes " + networkTypeBitMask
5335 + " allowedNetworkTypes " + allowedNetworkTypes
5336 + " networkMode " + networkMode);
5337 }
5338
5339 Boolean success = (Boolean) sendRequest(
5340 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5341 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5342 return success;
5343 }
5344
5345 /**
Miaoa84611c2019-03-15 09:21:10 +08005346 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005347 *
Miaoa84611c2019-03-15 09:21:10 +08005348 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005349 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005350 * @hide
5351 */
5352 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005353 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005354 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005355 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005356 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005357 try {
Miaoa84611c2019-03-15 09:21:10 +08005358 if (phone != null) {
5359 return phone.hasMatchedTetherApnSetting();
5360 } else {
5361 return false;
5362 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005363 } finally {
5364 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005365 }
Junda Liu475951f2014-11-07 16:45:03 -08005366 }
5367
5368 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005369 * Set mobile data enabled
5370 * Used by the user through settings etc to turn on/off mobile data
5371 *
5372 * @param enable {@code true} turn turn data on, else {@code false}
5373 */
5374 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005375 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5377 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005378
5379 final long identity = Binder.clearCallingIdentity();
5380 try {
5381 int phoneId = mSubscriptionController.getPhoneId(subId);
5382 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5383 Phone phone = PhoneFactory.getPhone(phoneId);
5384 if (phone != null) {
5385 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005386 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005387 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005388 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005389 }
5390 } finally {
5391 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005392 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005393 }
5394
5395 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005396 * Enable or disable always reporting signal strength changes from radio.
5397 *
5398 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5399 */
5400 @Override
5401 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5402 enforceModifyPermission();
5403 enforceSystemCaller();
5404
5405 final long identity = Binder.clearCallingIdentity();
5406 final Phone phone = getPhone(subId);
5407 try {
5408 if (phone != null) {
5409 if (DBG) {
5410 log("setAlwaysReportSignalStrength: subId=" + subId
5411 + " isEnable=" + isEnable);
5412 }
5413 phone.setAlwaysReportSignalStrength(isEnable);
5414 } else {
5415 loge("setAlwaysReportSignalStrength: no phone found for subId="
5416 + subId);
5417 }
5418 } finally {
5419 Binder.restoreCallingIdentity(identity);
5420 }
5421 }
5422
5423 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005424 * Get the user enabled state of Mobile Data.
5425 *
5426 * TODO: remove and use isUserDataEnabled.
5427 * This can't be removed now because some vendor codes
5428 * calls through ITelephony directly while they should
5429 * use TelephonyManager.
5430 *
5431 * @return true on enabled
5432 */
5433 @Override
5434 public boolean getDataEnabled(int subId) {
5435 return isUserDataEnabled(subId);
5436 }
5437
5438 /**
5439 * Get whether mobile data is enabled per user setting.
5440 *
5441 * There are other factors deciding whether mobile data is actually enabled, but they are
5442 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005443 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005444 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005445 *
5446 * @return {@code true} if data is enabled else {@code false}
5447 */
5448 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005449 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005450 try {
5451 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5452 null);
5453 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5455 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005456 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005457
5458 final long identity = Binder.clearCallingIdentity();
5459 try {
5460 int phoneId = mSubscriptionController.getPhoneId(subId);
5461 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5462 Phone phone = PhoneFactory.getPhone(phoneId);
5463 if (phone != null) {
5464 boolean retVal = phone.isUserDataEnabled();
5465 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5466 return retVal;
5467 } else {
5468 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5469 return false;
5470 }
5471 } finally {
5472 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005473 }
5474 }
5475
5476 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005477 * Checks if the device is capable of mobile data by considering whether whether the
5478 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5479 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005480 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005481 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005482 */
5483 @Override
5484 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005485 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005486
5487 final long identity = Binder.clearCallingIdentity();
5488 try {
5489 int phoneId = mSubscriptionController.getPhoneId(subId);
5490 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5491 Phone phone = PhoneFactory.getPhone(phoneId);
5492 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005493 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005494 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5495 return retVal;
5496 } else {
5497 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5498 return false;
5499 }
5500 } finally {
5501 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005502 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005503 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005504
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005505 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5506 Phone phone) {
5507 //load access rules from carrier configs, and check those as well: b/139133814
5508 SubscriptionController subController = SubscriptionController.getInstance();
5509 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5510 || subController == null) return privilegeFromSim;
5511
5512 int uid = Binder.getCallingUid();
5513 PackageManager pkgMgr = phone.getContext().getPackageManager();
5514 String[] packages = pkgMgr.getPackagesForUid(uid);
5515
5516 final long identity = Binder.clearCallingIdentity();
5517 try {
5518 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5519 SubscriptionManager subManager = (SubscriptionManager)
5520 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5521 for (String pkg : packages) {
5522 if (subManager.canManageSubscription(subInfo, pkg)) {
5523 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5524 }
5525 }
5526 return privilegeFromSim;
5527 } finally {
5528 Binder.restoreCallingIdentity(identity);
5529 }
5530 }
5531
5532 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5533 String pkgName) {
5534 //load access rules from carrier configs, and check those as well: b/139133814
5535 SubscriptionController subController = SubscriptionController.getInstance();
5536 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5537 || subController == null) return privilegeFromSim;
5538
5539 final long identity = Binder.clearCallingIdentity();
5540 try {
5541 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5542 SubscriptionManager subManager = (SubscriptionManager)
5543 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5544 return subManager.canManageSubscription(subInfo, pkgName)
5545 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5546 } finally {
5547 Binder.restoreCallingIdentity(identity);
5548 }
5549 }
5550
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005551 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005552 public int getCarrierPrivilegeStatus(int subId) {
5553 final Phone phone = getPhone(subId);
5554 if (phone == null) {
5555 loge("getCarrierPrivilegeStatus: Invalid subId");
5556 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5557 }
5558 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005559 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005560 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005561 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5562 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005563
5564 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5565 card.getCarrierPrivilegeStatusForCurrentTransaction(
5566 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005567 }
Junda Liu29340342014-07-10 15:23:27 -07005568
5569 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005570 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005571 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005572 final Phone phone = getPhone(subId);
5573 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005574 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005575 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5576 }
5577 UiccProfile profile =
5578 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5579 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005580 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005581 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5582 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005583 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005584 profile.getCarrierPrivilegeStatusForUid(
5585 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005586 }
5587
5588 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005589 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5590 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005591 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005592 }
5593
5594 int phoneId = SubscriptionManager.getPhoneId(subId);
5595 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005596 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005597 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005598 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5599 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005600 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5601 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5602 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005603 }
5604
5605 @Override
5606 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005607 if (TextUtils.isEmpty(pkgName))
5608 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005609 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5610 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5611 UiccCard card = UiccController.getInstance().getUiccCard(i);
5612 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005613 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005614 continue;
5615 }
5616
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005617 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5618 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5619 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005620 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5621 break;
5622 }
5623 }
5624
5625 return result;
Junda Liu29340342014-07-10 15:23:27 -07005626 }
Derek Tan89e89d42014-07-08 17:00:10 -07005627
5628 @Override
Junda Liue64de782015-04-16 17:19:16 -07005629 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5630 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5631 loge("phoneId " + phoneId + " is not valid.");
5632 return null;
5633 }
5634 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005635 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005636 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005637 return null ;
5638 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005639 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005640 }
5641
Amith Yamasani6e118872016-02-19 12:53:51 -08005642 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005643 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005644 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005645 List<String> privilegedPackages = new ArrayList<>();
5646 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005647 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5648 // has UICC in that slot.
5649 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005650 if (card.hasCarrierPrivilegeRules()) {
5651 if (packages == null) {
5652 // Only check packages in user 0 for now
5653 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005654 PackageManager.MATCH_DISABLED_COMPONENTS
5655 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005656 | PackageManager.GET_SIGNING_CERTIFICATES,
5657 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005658 }
5659 for (int p = packages.size() - 1; p >= 0; p--) {
5660 PackageInfo pkgInfo = packages.get(p);
5661 if (pkgInfo != null && pkgInfo.packageName != null
5662 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005663 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005664 privilegedPackages.add(pkgInfo.packageName);
5665 }
5666 }
5667 }
5668 }
5669 return privilegedPackages;
5670 }
5671
chen xuf7e9fe82019-05-09 19:31:02 -07005672 @Override
5673 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005674 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5675
5676 final long identity = Binder.clearCallingIdentity();
5677
chen xuf7e9fe82019-05-09 19:31:02 -07005678 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005679 try {
5680 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5681 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5682 }
5683 } finally {
5684 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005685 }
5686 return privilegedPackages;
5687 }
5688
Wink Savilleb564aae2014-10-23 10:18:09 -07005689 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005690 final Phone phone = getPhone(subId);
5691 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005692 if (card == null) {
5693 loge("getIccId: No UICC");
5694 return null;
5695 }
5696 String iccId = card.getIccId();
5697 if (TextUtils.isEmpty(iccId)) {
5698 loge("getIccId: ICC ID is null or empty.");
5699 return null;
5700 }
5701 return iccId;
5702 }
5703
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005704 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005705 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5706 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005707 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005708 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005709
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005710 final long identity = Binder.clearCallingIdentity();
5711 try {
5712 final String iccId = getIccId(subId);
5713 final Phone phone = getPhone(subId);
5714 if (phone == null) {
5715 return false;
5716 }
5717 final String subscriberId = phone.getSubscriberId();
5718
5719 if (DBG_MERGE) {
5720 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5721 + subscriberId + " to " + number);
5722 }
5723
5724 if (TextUtils.isEmpty(iccId)) {
5725 return false;
5726 }
5727
5728 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5729
5730 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5731 if (alphaTag == null) {
5732 editor.remove(alphaTagPrefKey);
5733 } else {
5734 editor.putString(alphaTagPrefKey, alphaTag);
5735 }
5736
5737 // Record both the line number and IMSI for this ICCID, since we need to
5738 // track all merged IMSIs based on line number
5739 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5740 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5741 if (number == null) {
5742 editor.remove(numberPrefKey);
5743 editor.remove(subscriberPrefKey);
5744 } else {
5745 editor.putString(numberPrefKey, number);
5746 editor.putString(subscriberPrefKey, subscriberId);
5747 }
5748
5749 editor.commit();
5750 return true;
5751 } finally {
5752 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005753 }
Derek Tan7226c842014-07-02 17:42:23 -07005754 }
5755
5756 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005757 public String getLine1NumberForDisplay(int subId, String callingPackage,
5758 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005759 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005760 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005761 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005762 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005763 return null;
5764 }
Derek Tan97ebb422014-09-05 16:55:38 -07005765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005766 final long identity = Binder.clearCallingIdentity();
5767 try {
5768 String iccId = getIccId(subId);
5769 if (iccId != null) {
5770 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5771 if (DBG_MERGE) {
5772 log("getLine1NumberForDisplay returning "
5773 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5774 }
5775 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005776 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005777 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5778 return null;
5779 } finally {
5780 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005781 }
Derek Tan7226c842014-07-02 17:42:23 -07005782 }
5783
5784 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005785 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5786 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005787 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005788 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005789 return null;
5790 }
Derek Tan97ebb422014-09-05 16:55:38 -07005791
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005792 final long identity = Binder.clearCallingIdentity();
5793 try {
5794 String iccId = getIccId(subId);
5795 if (iccId != null) {
5796 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5797 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5798 }
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 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005804
5805 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005806 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5807 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005808 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5809 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005810 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005811 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005812 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005813 return null;
5814 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005815
Jordan Liub49b04b2019-05-06 14:45:15 -07005816 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5817 // the process, where TelephonyManager was instantiated.
5818 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005819 final long identity = Binder.clearCallingIdentity();
5820 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005821 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005822 final TelephonyManager tele = TelephonyManager.from(context);
5823 final SubscriptionManager sub = SubscriptionManager.from(context);
5824
5825 // Figure out what subscribers are currently active
5826 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005827
Jordan Liub49b04b2019-05-06 14:45:15 -07005828 // Only consider subs which match the current subId
5829 // This logic can be simplified. See b/131189269 for progress.
5830 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005831 activeSubscriberIds.add(tele.getSubscriberId(subId));
5832 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005833
5834 // First pass, find a number override for an active subscriber
5835 String mergeNumber = null;
5836 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5837 for (String key : prefs.keySet()) {
5838 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5839 final String subscriberId = (String) prefs.get(key);
5840 if (activeSubscriberIds.contains(subscriberId)) {
5841 final String iccId = key.substring(
5842 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5843 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5844 mergeNumber = (String) prefs.get(numberKey);
5845 if (DBG_MERGE) {
5846 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5847 + " for active subscriber " + subscriberId);
5848 }
5849 if (!TextUtils.isEmpty(mergeNumber)) {
5850 break;
5851 }
5852 }
5853 }
5854 }
5855
5856 // Shortcut when no active merged subscribers
5857 if (TextUtils.isEmpty(mergeNumber)) {
5858 return null;
5859 }
5860
5861 // Second pass, find all subscribers under that line override
5862 final ArraySet<String> result = new ArraySet<>();
5863 for (String key : prefs.keySet()) {
5864 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5865 final String number = (String) prefs.get(key);
5866 if (mergeNumber.equals(number)) {
5867 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5868 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5869 final String subscriberId = (String) prefs.get(subscriberKey);
5870 if (!TextUtils.isEmpty(subscriberId)) {
5871 result.add(subscriberId);
5872 }
5873 }
5874 }
5875 }
5876
5877 final String[] resultArray = result.toArray(new String[result.size()]);
5878 Arrays.sort(resultArray);
5879 if (DBG_MERGE) {
5880 Slog.d(LOG_TAG,
5881 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5882 }
5883 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005884 } finally {
5885 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005886 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005887 }
5888
5889 @Override
zoey chen38003472019-12-13 17:16:31 +08005890 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
5891 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07005892
5893 final long identity = Binder.clearCallingIdentity();
5894 try {
5895 final TelephonyManager telephonyManager = mApp.getSystemService(
5896 TelephonyManager.class);
5897 String subscriberId = telephonyManager.getSubscriberId(subId);
5898 if (subscriberId == null) {
5899 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08005900 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07005901 + subId);
5902 }
5903 return null;
5904 }
5905
5906 final SubscriptionInfo info = SubscriptionController.getInstance()
5907 .getSubscriptionInfo(subId);
5908 final ParcelUuid groupUuid = info.getGroupUuid();
5909 // If it doesn't belong to any group, return just subscriberId of itself.
5910 if (groupUuid == null) {
5911 return new String[]{subscriberId};
5912 }
5913
5914 // Get all subscriberIds from the group.
5915 final List<String> mergedSubscriberIds = new ArrayList<>();
5916 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005917 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5918 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005919 for (SubscriptionInfo subInfo : groupInfos) {
5920 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5921 if (subscriberId != null) {
5922 mergedSubscriberIds.add(subscriberId);
5923 }
5924 }
5925
5926 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5927 } finally {
5928 Binder.restoreCallingIdentity(identity);
5929
5930 }
5931 }
5932
5933 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005934 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005935 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005936 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005937
5938 final long identity = Binder.clearCallingIdentity();
5939 try {
5940 final Phone phone = getPhone(subId);
5941 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5942 } finally {
5943 Binder.restoreCallingIdentity(identity);
5944 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005945 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005946
5947 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005948 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005949 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5950 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005951 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5952 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005953
5954 final long identity = Binder.clearCallingIdentity();
5955 try {
5956 final Phone phone = getPhone(subId);
5957 if (phone == null) {
5958 return false;
5959 }
5960 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5961 cdmaNonRoamingList);
5962 } finally {
5963 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005964 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005965 }
5966
5967 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005968 @Deprecated
5969 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5970 enforceModifyPermission();
5971
5972 int returnValue = 0;
5973 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005974 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005975 if(result.exception == null) {
5976 if (result.result != null) {
5977 byte[] responseData = (byte[])(result.result);
5978 if(responseData.length > oemResp.length) {
5979 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5980 responseData.length + "bytes. Buffer Size is " +
5981 oemResp.length + "bytes.");
5982 }
5983 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5984 returnValue = responseData.length;
5985 }
5986 } else {
5987 CommandException ex = (CommandException) result.exception;
5988 returnValue = ex.getCommandError().ordinal();
5989 if(returnValue > 0) returnValue *= -1;
5990 }
5991 } catch (RuntimeException e) {
5992 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5993 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5994 if(returnValue > 0) returnValue *= -1;
5995 }
5996
5997 return returnValue;
5998 }
5999
6000 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006001 public void setRadioCapability(RadioAccessFamily[] rafs) {
6002 try {
6003 ProxyController.getInstance().setRadioCapability(rafs);
6004 } catch (RuntimeException e) {
6005 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6006 }
6007 }
6008
6009 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006010 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006011 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006012 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006013 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006014 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006015 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006016 final long identity = Binder.clearCallingIdentity();
6017 try {
chen xub97461a2018-10-26 14:17:57 -07006018 TelephonyPermissions
6019 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6020 mApp, phone.getSubId(), "getRadioAccessFamily");
6021 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006022 } finally {
6023 Binder.restoreCallingIdentity(identity);
6024 }
chen xub97461a2018-10-26 14:17:57 -07006025 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006026 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006027
6028 @Override
6029 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006030 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006031 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006032
6033 final long identity = Binder.clearCallingIdentity();
6034 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006035 ImsManager.getInstance(defaultPhone.getContext(),
6036 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006037 } finally {
6038 Binder.restoreCallingIdentity(identity);
6039 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006040 }
6041
6042 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006043 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006044 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006045 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6046 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006047 return false;
6048 }
Svet Ganovb320e182015-04-16 12:30:10 -07006049
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006050 final long identity = Binder.clearCallingIdentity();
6051 try {
6052 // Check the user preference and the system-level IMS setting. Even if the user has
6053 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6054 // In the long run, we may instead need to check if there exists a connection service
6055 // which can support video calling.
6056 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006057 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006058 return imsManager.isVtEnabledByPlatform()
6059 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6060 && imsManager.isVtEnabledByUser();
6061 } finally {
6062 Binder.restoreCallingIdentity(identity);
6063 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006064 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006065
Andrew Leea1239f22015-03-02 17:44:07 -08006066 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006067 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6068 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006069 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006070 mApp, subId, callingPackage, callingFeatureId,
6071 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006072 return false;
6073 }
6074
6075 final long identity = Binder.clearCallingIdentity();
6076 try {
6077 CarrierConfigManager configManager =
6078 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006079 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006080 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6081 } finally {
6082 Binder.restoreCallingIdentity(identity);
6083 }
Andrew Leea1239f22015-03-02 17:44:07 -08006084 }
6085
6086 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006087 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006088 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006089 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006090 return false;
6091 }
6092
6093 final long identity = Binder.clearCallingIdentity();
6094 try {
6095 CarrierConfigManager configManager =
6096 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006097 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006098 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6099 } finally {
6100 Binder.restoreCallingIdentity(identity);
6101 }
Andrew Leea1239f22015-03-02 17:44:07 -08006102 }
6103
Andrew Lee9431b832015-03-09 18:46:45 -07006104 @Override
6105 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006106 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006107 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006108 }
6109
6110 @Override
6111 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006112 final long identity = Binder.clearCallingIdentity();
6113 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006114 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006115 } finally {
6116 Binder.restoreCallingIdentity(identity);
6117 }
Andrew Lee9431b832015-03-09 18:46:45 -07006118 }
6119
Hall Liuf6668912018-10-31 17:05:23 -07006120 /**
6121 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6122 * support for the feature and device firmware support.
6123 *
6124 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6125 */
6126 @Override
6127 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006128 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006129 final Phone phone = getPhone(subscriptionId);
6130 if (phone == null) {
6131 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6132 return false;
6133 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006134 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006135 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006136 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6137 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006138 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006139 return isCarrierSupported && isDeviceSupported;
6140 } finally {
6141 Binder.restoreCallingIdentity(identity);
6142 }
Hall Liu98187582018-01-22 19:15:32 -08006143 }
6144
Hall Liuf6668912018-10-31 17:05:23 -07006145 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006146 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6147 * RTT setting, will return true if the device and carrier both support RTT.
6148 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006149 */
6150 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006151 final long identity = Binder.clearCallingIdentity();
6152 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006153 boolean isRttSupported = isRttSupported(subscriptionId);
6154 boolean isUserRttSettingOn = Settings.Secure.getInt(
6155 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6156 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6157 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6158 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006159 } finally {
6160 Binder.restoreCallingIdentity(identity);
6161 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006162 }
6163
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006164 @Deprecated
6165 @Override
6166 public String getDeviceId(String callingPackage) {
6167 return getDeviceIdWithFeature(callingPackage, null);
6168 }
6169
Sanket Padawe7310cc72015-01-14 09:53:20 -08006170 /**
6171 * Returns the unique device ID of phone, for example, the IMEI for
6172 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6173 *
6174 * <p>Requires Permission:
6175 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6176 */
6177 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006178 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006179 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006180 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006181 return null;
6182 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006183 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006184 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006185 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006186 return null;
6187 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006188
6189 final long identity = Binder.clearCallingIdentity();
6190 try {
6191 return phone.getDeviceId();
6192 } finally {
6193 Binder.restoreCallingIdentity(identity);
6194 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006195 }
6196
Ping Sunc67b7c22016-03-02 19:16:45 +08006197 /**
6198 * {@hide}
6199 * Returns the IMS Registration Status on a particular subid
6200 *
6201 * @param subId
6202 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006203 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006204 Phone phone = getPhone(subId);
6205 if (phone != null) {
6206 return phone.isImsRegistered();
6207 } else {
6208 return false;
6209 }
6210 }
6211
Santos Cordon7a1885b2015-02-03 11:15:19 -08006212 @Override
6213 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006214 final long identity = Binder.clearCallingIdentity();
6215 try {
6216 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6217 } finally {
6218 Binder.restoreCallingIdentity(identity);
6219 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006220 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006221
Tyler Gunnf70ed162019-04-03 15:28:53 -07006222 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006223 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006224 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006225 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006226 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006227 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6228 }
6229 final long identity = Binder.clearCallingIdentity();
6230 try {
6231 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6232 } finally {
6233 Binder.restoreCallingIdentity(identity);
6234 }
6235 }
6236
6237 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006238 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6239 final long identity = Binder.clearCallingIdentity();
6240 try {
6241 Phone phone = getPhone(subscriptionId);
6242 if (phone == null) {
6243 return null;
6244 }
6245 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6246 } finally {
6247 Binder.restoreCallingIdentity(identity);
6248 }
6249 }
6250
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006251 /**
6252 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006253 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006254 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006255 final long identity = Binder.clearCallingIdentity();
6256 try {
6257 Phone phone = getPhone(subId);
6258 if (phone != null) {
6259 return phone.isWifiCallingEnabled();
6260 } else {
6261 return false;
6262 }
6263 } finally {
6264 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006265 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006266 }
6267
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006268 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006269 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006270 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006271 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006272 final long identity = Binder.clearCallingIdentity();
6273 try {
6274 Phone phone = getPhone(subId);
6275 if (phone != null) {
6276 return phone.isVideoEnabled();
6277 } else {
6278 return false;
6279 }
6280 } finally {
6281 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006282 }
6283 }
6284
6285 /**
6286 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6287 * defined in {@link ImsRegistrationImplBase}.
6288 */
6289 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006290 final long identity = Binder.clearCallingIdentity();
6291 try {
6292 Phone phone = getPhone(subId);
6293 if (phone != null) {
6294 return phone.getImsRegistrationTech();
6295 } else {
6296 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6297 }
6298 } finally {
6299 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006300 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006301 }
6302
Stuart Scott8eef64f2015-04-08 15:13:54 -07006303 @Override
6304 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006305 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006306 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6307 return;
6308 }
6309
Svet Ganovcc087f82015-05-12 20:35:54 -07006310 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006311
Svet Ganovcc087f82015-05-12 20:35:54 -07006312 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006313 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6314 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006315 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006316 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006317 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006318 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6319 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006320 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006321 // There has been issues when Sms raw table somehow stores orphan
6322 // fragments. They lead to garbled message when new fragments come
6323 // in and combined with those stale ones. In case this happens again,
6324 // user can reset all network settings which will clean up this table.
6325 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006326 // Clean up IMS settings as well here.
6327 int slotId = getSlotIndex(subId);
6328 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6329 ImsManager.getInstance(mApp, slotId).factoryReset();
6330 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006331
6332 // Erase modem config if erase modem on network setting is enabled.
6333 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6334 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6335 if (configValue != null && Boolean.parseBoolean(configValue)) {
6336 sendEraseModemConfig(getDefaultPhone());
6337 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006338 } finally {
6339 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006340 }
6341 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006342
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006343 private void cleanUpSmsRawTable(Context context) {
6344 ContentResolver resolver = context.getContentResolver();
6345 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6346 resolver.delete(uri, null, null);
6347 }
6348
Narayan Kamath1c496c22015-04-16 14:40:19 +01006349 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006350 public String getSimLocaleForSubscriber(int subId) {
6351 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6352 final Phone phone = getPhone(subId);
6353 if (phone == null) {
6354 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006355 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006356 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006357 final long identity = Binder.clearCallingIdentity();
6358 try {
chen xu5d3637b2019-01-21 23:31:38 -08006359 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006360 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08006361 if (info == null) {
6362 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6363 return null;
6364 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006365 // Try and fetch the locale from the carrier properties or from the SIM language
6366 // preferences (EF-PL and EF-LI)...
6367 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006368 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006369 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6370 if (localeFromDefaultSim != null) {
6371 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6372 if (DBG) log("Using locale from subId: " + subId + " locale: "
6373 + localeFromDefaultSim);
6374 return localeFromDefaultSim.toLanguageTag();
6375 } else {
6376 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006377 }
6378 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006379
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006380 // The SIM language preferences only store a language (e.g. fr = French), not an
6381 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6382 // the SIM and carrier preferences does not include a country we add the country
6383 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006384 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006385 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006386 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006387 return mccLocale.toLanguageTag();
6388 }
6389
6390 if (DBG) log("No locale found - returning null");
6391 return null;
6392 } finally {
6393 Binder.restoreCallingIdentity(identity);
6394 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006395 }
6396
6397 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006398 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6399 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006400 }
6401
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006402 /**
6403 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6404 */
6405 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006406 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6407 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006408 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006409
Chenjie Yu1ba97252018-01-11 18:16:20 -08006410 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006411 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006412
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006413 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006414 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6415 * representing the state of the modem.
6416 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006417 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6418 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006419 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006420 */
6421 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006422 public void requestModemActivityInfo(ResultReceiver result) {
6423 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006424 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006425
6426 final long identity = Binder.clearCallingIdentity();
6427 try {
6428 ModemActivityInfo ret = null;
6429 synchronized (mLastModemActivityInfo) {
6430 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6431 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006432 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006433 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006434 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006435 int[] txTimeMs = info.getTransmitTimeMillis();
6436 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006437 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006438 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006439 }
6440 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006441 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6442 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006443 mLastModemActivityInfo.setIdleTimeMillis(
6444 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006445 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6446 mLastModemActivityInfo.setReceiveTimeMillis(
6447 info.getReceiveTimeMillis() + mLastModemActivityInfo
6448 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006449 }
Chen Xud78231e2019-09-10 18:49:52 -07006450
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006451 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6452 mLastModemActivityInfo.getSleepTimeMillis(),
6453 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006454 mLastModemActivityInfo.getTransmitTimeMillis(),
6455 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006456 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006457 Bundle bundle = new Bundle();
6458 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6459 result.send(0, bundle);
6460 } finally {
6461 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006462 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006463 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006464
Siddharth Rayb8114062018-06-17 15:02:38 -07006465 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6466 // less than total activity duration.
6467 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6468 if (info == null) {
6469 return false;
6470 }
6471 int activityDurationMs =
6472 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6473 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006474 int[] txTimeMs = info.getTransmitTimeMillis();
6475 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6476 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006477 }
6478 return (info.isValid()
6479 && (info.getSleepTimeMillis() <= activityDurationMs)
6480 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006481 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006482 && (totalTxTimeMs <= activityDurationMs));
6483 }
6484
Jack Yu85bd38a2015-11-09 11:34:32 -08006485 /**
6486 * {@hide}
6487 * Returns the service state information on specified subscription.
6488 */
6489 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006490 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6491 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006492 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006493 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006494 return null;
6495 }
6496
Hall Liuf19c44f2018-11-27 14:38:17 -08006497 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6498 LocationAccessPolicy.checkLocationPermission(mApp,
6499 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6500 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006501 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006502 .setCallingPid(Binder.getCallingPid())
6503 .setCallingUid(Binder.getCallingUid())
6504 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006505 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006506 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6507 .build());
6508
6509 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6510 LocationAccessPolicy.checkLocationPermission(mApp,
6511 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6512 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006513 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006514 .setCallingPid(Binder.getCallingPid())
6515 .setCallingUid(Binder.getCallingUid())
6516 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006517 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006518 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6519 .build());
6520 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6521 boolean hasFinePermission =
6522 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6523 boolean hasCoarsePermission =
6524 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6525
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006526 final long identity = Binder.clearCallingIdentity();
6527 try {
6528 final Phone phone = getPhone(subId);
6529 if (phone == null) {
6530 return null;
6531 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006532
Hall Liuf19c44f2018-11-27 14:38:17 -08006533 ServiceState ss = phone.getServiceState();
6534
6535 // Scrub out the location info in ServiceState depending on what level of access
6536 // the caller has.
6537 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006538 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6539 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006540 } finally {
6541 Binder.restoreCallingIdentity(identity);
6542 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006543 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006544
6545 /**
6546 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6547 *
6548 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6549 * voicemail ringtone.
6550 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6551 * PhoneAccount.
6552 */
6553 @Override
6554 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006555 final long identity = Binder.clearCallingIdentity();
6556 try {
6557 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6558 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006559 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006560 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006561
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006562 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6563 } finally {
6564 Binder.restoreCallingIdentity(identity);
6565 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006566 }
6567
6568 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006569 * Sets the per-account voicemail ringtone.
6570 *
6571 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6572 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6573 *
6574 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6575 * voicemail ringtone.
6576 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6577 * PhoneAccount.
6578 */
6579 @Override
6580 public void setVoicemailRingtoneUri(String callingPackage,
6581 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006582 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006583 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006584 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6585 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006586 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6587 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6588 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006589 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006590
6591 final long identity = Binder.clearCallingIdentity();
6592 try {
6593 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6594 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006595 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006596 }
6597 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6598 } finally {
6599 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006600 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006601 }
6602
6603 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006604 * Returns whether vibration is set for voicemail notification in Phone settings.
6605 *
6606 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6607 * voicemail vibration setting.
6608 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6609 */
6610 @Override
6611 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006612 final long identity = Binder.clearCallingIdentity();
6613 try {
6614 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6615 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006616 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006617 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006618
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006619 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6620 } finally {
6621 Binder.restoreCallingIdentity(identity);
6622 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006623 }
6624
Youhan Wange64578a2016-05-02 15:32:42 -07006625 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006626 * Sets the per-account voicemail vibration.
6627 *
6628 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6629 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6630 *
6631 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6632 * voicemail vibration setting.
6633 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6634 * specific PhoneAccount.
6635 */
6636 @Override
6637 public void setVoicemailVibrationEnabled(String callingPackage,
6638 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006639 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006640 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006641 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6642 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006643 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6644 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6645 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006646 }
6647
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006648 final long identity = Binder.clearCallingIdentity();
6649 try {
6650 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6651 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006652 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006653 }
6654 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6655 } finally {
6656 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006657 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006658 }
6659
6660 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006661 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6662 *
6663 * @throws SecurityException if the caller does not have the required permission
6664 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006665 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006666 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006667 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006668 }
6669
6670 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006671 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6672 * permission.
6673 *
6674 * @throws SecurityException if the caller does not have the required permission
6675 */
6676 private void enforceSendSmsPermission() {
6677 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6678 }
6679
6680 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006681 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006682 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006683 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006684 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006685 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006686 final long identity = Binder.clearCallingIdentity();
6687 try {
6688 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006689 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006690 if (componentName == null) {
6691 throw new SecurityException(
6692 "Caller not current active visual voicemail package[null]");
6693 }
6694 String vvmPackage = componentName.getPackageName();
6695 if (!callingPackage.equals(vvmPackage)) {
6696 throw new SecurityException("Caller not current active visual voicemail package["
6697 + vvmPackage + "]");
6698 }
6699 } finally {
6700 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006701 }
6702 }
6703
6704 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006705 * Return the application ID for the app type.
6706 *
6707 * @param subId the subscription ID that this request applies to.
6708 * @param appType the uicc app type.
6709 * @return Application ID for specificied app type, or null if no uicc.
6710 */
6711 @Override
6712 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006713 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006714 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006715
6716 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006717 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006718 if (phone == null) {
6719 return null;
6720 }
6721 String aid = null;
6722 try {
6723 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6724 .getApplicationByType(appType).getAid();
6725 } catch (Exception e) {
6726 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6727 }
6728 return aid;
6729 } finally {
6730 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006731 }
Youhan Wange64578a2016-05-02 15:32:42 -07006732 }
6733
Youhan Wang4001d252016-05-11 10:29:41 -07006734 /**
6735 * Return the Electronic Serial Number.
6736 *
6737 * @param subId the subscription ID that this request applies to.
6738 * @return ESN or null if error.
6739 */
6740 @Override
6741 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006742 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006743 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006744
6745 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006746 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006747 if (phone == null) {
6748 return null;
6749 }
6750 String esn = null;
6751 try {
6752 esn = phone.getEsn();
6753 } catch (Exception e) {
6754 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6755 }
6756 return esn;
6757 } finally {
6758 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006759 }
Youhan Wang4001d252016-05-11 10:29:41 -07006760 }
6761
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006762 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006763 * Return the Preferred Roaming List Version.
6764 *
6765 * @param subId the subscription ID that this request applies to.
6766 * @return PRLVersion or null if error.
6767 */
6768 @Override
6769 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006770 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006771 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006772
6773 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006774 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006775 if (phone == null) {
6776 return null;
6777 }
6778 String cdmaPrlVersion = null;
6779 try {
6780 cdmaPrlVersion = phone.getCdmaPrlVersion();
6781 } catch (Exception e) {
6782 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6783 }
6784 return cdmaPrlVersion;
6785 } finally {
6786 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006787 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006788 }
6789
6790 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006791 * Get snapshot of Telephony histograms
6792 * @return List of Telephony histograms
6793 * @hide
6794 */
6795 @Override
6796 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006797 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6798 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006799
6800 final long identity = Binder.clearCallingIdentity();
6801 try {
6802 return RIL.getTelephonyRILTimingHistograms();
6803 } finally {
6804 Binder.restoreCallingIdentity(identity);
6805 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006806 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006807
6808 /**
6809 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006810 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6811 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006812 * Require system privileges. In the future we may add this to carrier APIs.
6813 *
Michele Berionne482f8202018-11-27 18:57:59 -08006814 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006815 */
6816 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006817 @TelephonyManager.SetCarrierRestrictionResult
6818 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006819 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006820 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006821
Michele Berionne482f8202018-11-27 18:57:59 -08006822 if (carrierRestrictionRules == null) {
6823 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006824 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006825
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006826 final long identity = Binder.clearCallingIdentity();
6827 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006828 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006829 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006830 } finally {
6831 Binder.restoreCallingIdentity(identity);
6832 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006833 }
6834
6835 /**
6836 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006837 * Get the allowed carrier list and the excluded carrier list, including the priority between
6838 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006839 * Require system privileges. In the future we may add this to carrier APIs.
6840 *
Michele Berionne482f8202018-11-27 18:57:59 -08006841 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006842 */
6843 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006844 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006845 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006846 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006847
6848 final long identity = Binder.clearCallingIdentity();
6849 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006850 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6851 if (response instanceof CarrierRestrictionRules) {
6852 return (CarrierRestrictionRules) response;
6853 }
6854 // Response is an Exception of some kind,
6855 // which is signalled to the user as a NULL retval
6856 return null;
6857 } catch (Exception e) {
6858 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6859 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006860 } finally {
6861 Binder.restoreCallingIdentity(identity);
6862 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006863 }
6864
fionaxu59545b42016-05-25 15:53:37 -07006865 /**
6866 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6867 * @param subId the subscription ID that this action applies to.
6868 * @param enabled control enable or disable metered apns.
6869 * {@hide}
6870 */
6871 @Override
6872 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6873 enforceModifyPermission();
6874 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006875
6876 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006877 if (phone == null) {
6878 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6879 return;
6880 }
6881 try {
6882 phone.carrierActionSetMeteredApnsEnabled(enabled);
6883 } catch (Exception e) {
6884 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006885 } finally {
6886 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006887 }
6888 }
6889
6890 /**
6891 * Action set from carrier signalling broadcast receivers to enable/disable radio
6892 * @param subId the subscription ID that this action applies to.
6893 * @param enabled control enable or disable radio.
6894 * {@hide}
6895 */
6896 @Override
6897 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6898 enforceModifyPermission();
6899 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006900
6901 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006902 if (phone == null) {
6903 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6904 return;
6905 }
6906 try {
6907 phone.carrierActionSetRadioEnabled(enabled);
6908 } catch (Exception e) {
6909 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006910 } finally {
6911 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006912 }
6913 }
6914
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006915 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006916 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6917 * network status based on which carrier apps could apply actions accordingly,
6918 * enable/disable default url handler for example.
6919 *
6920 * @param subId the subscription ID that this action applies to.
6921 * @param report control start/stop reporting the default network status.
6922 * {@hide}
6923 */
6924 @Override
6925 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6926 enforceModifyPermission();
6927 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006928
6929 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006930 if (phone == null) {
6931 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6932 return;
6933 }
6934 try {
6935 phone.carrierActionReportDefaultNetworkStatus(report);
6936 } catch (Exception e) {
6937 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006938 } finally {
6939 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006940 }
6941 }
6942
6943 /**
fionaxud9622282017-07-17 17:51:30 -07006944 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6945 * @param subId the subscription ID that this action applies to.
6946 * {@hide}
6947 */
6948 @Override
6949 public void carrierActionResetAll(int subId) {
6950 enforceModifyPermission();
6951 final Phone phone = getPhone(subId);
6952 if (phone == null) {
6953 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6954 return;
6955 }
6956 try {
6957 phone.carrierActionResetAll();
6958 } catch (Exception e) {
6959 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6960 }
6961 }
6962
6963 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006964 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6965 * bug report is being generated.
6966 */
6967 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006968 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006969 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6970 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006971 writer.println("Permission Denial: can't dump Phone from pid="
6972 + Binder.getCallingPid()
6973 + ", uid=" + Binder.getCallingUid()
6974 + "without permission "
6975 + android.Manifest.permission.DUMP);
6976 return;
6977 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006978 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006979 }
Jack Yueb89b242016-06-22 13:27:47 -07006980
Brad Ebingerdac2f002018-04-03 15:17:52 -07006981 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08006982 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
6983 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
6984 @NonNull String[] args) {
6985 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
6986 this, in.getFileDescriptor(), out.getFileDescriptor(),
6987 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006988 }
6989
Jack Yueb89b242016-06-22 13:27:47 -07006990 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006991 * Get aggregated video call data usage since boot.
6992 *
6993 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6994 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006995 * {@hide}
6996 */
6997 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006998 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006999 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
7000 null);
7001
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007002 final long identity = Binder.clearCallingIdentity();
7003 try {
7004 // NetworkStatsService keeps tracking the active network interface and identity. It
7005 // records the delta with the corresponding network identity.
7006 // We just return the total video call data usage snapshot since boot.
7007 Phone phone = getPhone(subId);
7008 if (phone != null) {
7009 return phone.getVtDataUsage(perUidStats);
7010 }
7011 return null;
7012 } finally {
7013 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07007014 }
Jack Yueb89b242016-06-22 13:27:47 -07007015 }
Jack Yu75ab2952016-07-08 14:29:33 -07007016
7017 /**
7018 * Policy control of data connection. Usually used when data limit is passed.
7019 * @param enabled True if enabling the data, otherwise disabling.
7020 * @param subId Subscription index
7021 * {@hide}
7022 */
7023 @Override
7024 public void setPolicyDataEnabled(boolean enabled, int subId) {
7025 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007026
7027 final long identity = Binder.clearCallingIdentity();
7028 try {
7029 Phone phone = getPhone(subId);
7030 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007031 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007032 }
7033 } finally {
7034 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007035 }
7036 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007037
7038 /**
7039 * Get Client request stats
7040 * @return List of Client Request Stats
7041 * @hide
7042 */
7043 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007044 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7045 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007046 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007047 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007048 return null;
7049 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007050 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007051
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007052 final long identity = Binder.clearCallingIdentity();
7053 try {
7054 if (phone != null) {
7055 return phone.getClientRequestStats();
7056 }
7057
7058 return null;
7059 } finally {
7060 Binder.restoreCallingIdentity(identity);
7061 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007062 }
7063
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007064 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007065 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007066 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007067 }
Jack Yueb4124c2017-02-16 15:32:43 -08007068
7069 /**
Grace Chen70990072017-03-24 17:21:30 -07007070 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007071 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007072 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007073 * @param state State of SIM (power down, power up, pass through)
7074 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7075 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7076 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007077 *
7078 **/
7079 @Override
Grace Chen70990072017-03-24 17:21:30 -07007080 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007081 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007082 Phone phone = PhoneFactory.getPhone(slotIndex);
7083
vagdeviaf9a5b92018-08-15 16:01:53 -07007084 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7085
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007086 final long identity = Binder.clearCallingIdentity();
7087 try {
7088 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007089 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007090 }
7091 } finally {
7092 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007093 }
7094 }
Shuo Qiandd210312017-04-12 22:11:33 +00007095
Tyler Gunn65d45c22017-06-05 11:22:26 -07007096 private boolean isUssdApiAllowed(int subId) {
7097 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007098 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007099 if (configManager == null) {
7100 return false;
7101 }
7102 PersistableBundle pb = configManager.getConfigForSubId(subId);
7103 if (pb == null) {
7104 return false;
7105 }
7106 return pb.getBoolean(
7107 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7108 }
7109
Shuo Qiandd210312017-04-12 22:11:33 +00007110 /**
7111 * Check if phone is in emergency callback mode
7112 * @return true if phone is in emergency callback mode
7113 * @param subId sub id
7114 */
goneil9c5f4872017-12-05 14:07:56 -08007115 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007116 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007117 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007118 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007119
7120 final long identity = Binder.clearCallingIdentity();
7121 try {
7122 if (phone != null) {
7123 return phone.isInEcm();
7124 } else {
7125 return false;
7126 }
7127 } finally {
7128 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007129 }
7130 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007131
7132 /**
7133 * Get the current signal strength information for the given subscription.
7134 * Because this information is not updated when the device is in a low power state
7135 * it should not be relied-upon to be current.
7136 * @param subId Subscription index
7137 * @return the most recent cached signal strength info from the modem
7138 */
7139 @Override
7140 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007141 final long identity = Binder.clearCallingIdentity();
7142 try {
7143 Phone p = getPhone(subId);
7144 if (p == null) {
7145 return null;
7146 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007147
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007148 return p.getSignalStrength();
7149 } finally {
7150 Binder.restoreCallingIdentity(identity);
7151 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007152 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007153
Pengquan Meng77b7f132018-08-22 14:49:57 -07007154 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007155 * Get the current modem radio state for the given slot.
7156 * @param slotIndex slot index.
7157 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007158 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007159 * @return the current radio power state from the modem
7160 */
7161 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007162 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007163 Phone phone = PhoneFactory.getPhone(slotIndex);
7164 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007165 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7166 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007167 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7168 }
7169
7170 final long identity = Binder.clearCallingIdentity();
7171 try {
7172 return phone.getRadioPowerState();
7173 } finally {
7174 Binder.restoreCallingIdentity(identity);
7175 }
7176 }
7177 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7178 }
7179
7180 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007181 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7182 *
7183 * <p>Requires one of the following permissions:
7184 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7185 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7186 * privileges.
7187 *
7188 * @param subId subscription id
7189 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7190 * {@code false}.
7191 */
7192 @Override
7193 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007194 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7195 null /* message */);
7196
Pengquan Menga1bb6272018-09-06 09:59:22 -07007197 boolean isEnabled = false;
7198 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007199 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007200 Phone phone = getPhone(subId);
7201 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007202 } catch (Exception e) {
7203 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7204 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007205 } finally {
7206 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007207 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007208 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007209 }
7210
7211
7212 /**
7213 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7214 *
7215 * <p> Requires permission:
7216 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7217 * privileges.
7218 *
7219 * @param subId subscription id
7220 * @param isEnabled {@code true} means enable, {@code false} means disable.
7221 */
7222 @Override
7223 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007224 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7225 mApp, subId, "setDataRoamingEnabled");
7226
Pengquan Menga1bb6272018-09-06 09:59:22 -07007227 final long identity = Binder.clearCallingIdentity();
7228 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007229 Phone phone = getPhone(subId);
7230 if (phone != null) {
7231 phone.setDataRoamingEnabled(isEnabled);
7232 }
7233 } finally {
7234 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007235 }
7236 }
7237
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007238 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007239 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007240 TelephonyPermissions
7241 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007242 mApp, subId, "isManualNetworkSelectionAllowed");
7243
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007244 boolean isAllowed = true;
7245 final long identity = Binder.clearCallingIdentity();
7246 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007247 Phone phone = getPhone(subId);
7248 if (phone != null) {
7249 isAllowed = phone.isCspPlmnEnabled();
7250 }
7251 } finally {
7252 Binder.restoreCallingIdentity(identity);
7253 }
7254 return isAllowed;
7255 }
7256
7257 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007258 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007259 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007260 try {
7261 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007262 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007263 } catch (SecurityException e) {
7264 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7265 // has carrier privileges on an active UICC
7266 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7267 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007268 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007269 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007270 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007271
7272 final long identity = Binder.clearCallingIdentity();
7273 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007274 UiccController uiccController = UiccController.getInstance();
7275 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007276 if (hasReadPermission) {
7277 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007278 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007279
7280 // Remove private info if the caller doesn't have access
7281 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7282 for (UiccCardInfo cardInfo : cardInfos) {
7283 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7284 // is available
7285 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7286 if (card == null || card.getUiccProfile() == null) {
7287 // assume no access if the card or profile is unavailable
7288 filteredInfos.add(cardInfo.getUnprivileged());
7289 continue;
7290 }
7291 UiccProfile profile = card.getUiccProfile();
7292 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7293 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7294 filteredInfos.add(cardInfo);
7295 } else {
7296 filteredInfos.add(cardInfo.getUnprivileged());
7297 }
7298 }
7299 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007300 } finally {
7301 Binder.restoreCallingIdentity(identity);
7302 }
7303 }
7304
7305 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007306 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007307 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007308
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007309 final long identity = Binder.clearCallingIdentity();
7310 try {
7311 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7312 if (slots == null) {
7313 Rlog.i(LOG_TAG, "slots is null.");
7314 return null;
7315 }
7316
7317 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7318 for (int i = 0; i < slots.length; i++) {
7319 UiccSlot slot = slots[i];
7320 if (slot == null) {
7321 continue;
7322 }
7323
Jordan Liu7be7e652019-05-06 18:55:02 +00007324 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007325 UiccCard card = slot.getUiccCard();
7326 if (card != null) {
7327 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007328 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007329 cardId = slot.getEid();
7330 if (TextUtils.isEmpty(cardId)) {
7331 cardId = slot.getIccId();
7332 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007333 }
7334
Jordan Liu857451f2019-05-09 16:35:35 -07007335 if (cardId != null) {
7336 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7337 // if cardId is an EID, it's all digits so this is fine
7338 cardId = IccUtils.stripTrailingFs(cardId);
7339 }
7340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007341 int cardState = 0;
7342 switch (slot.getCardState()) {
7343 case CARDSTATE_ABSENT:
7344 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7345 break;
7346 case CARDSTATE_PRESENT:
7347 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7348 break;
7349 case CARDSTATE_ERROR:
7350 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7351 break;
7352 case CARDSTATE_RESTRICTED:
7353 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7354 break;
7355 default:
7356 break;
7357
7358 }
7359
7360 infos[i] = new UiccSlotInfo(
7361 slot.isActive(),
7362 slot.isEuicc(),
7363 cardId,
7364 cardState,
7365 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007366 slot.isExtendedApduSupported(),
7367 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007368 }
7369 return infos;
7370 } finally {
7371 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007372 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007373 }
7374
7375 @Override
7376 public boolean switchSlots(int[] physicalSlots) {
7377 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007378
7379 final long identity = Binder.clearCallingIdentity();
7380 try {
7381 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7382 } finally {
7383 Binder.restoreCallingIdentity(identity);
7384 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007385 }
Jack Yu4c988042018-02-27 15:30:01 -08007386
7387 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007388 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007389 final long identity = Binder.clearCallingIdentity();
7390 try {
7391 return UiccController.getInstance().getCardIdForDefaultEuicc();
7392 } finally {
7393 Binder.restoreCallingIdentity(identity);
7394 }
7395 }
7396
7397 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007398 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7399 enforceModifyPermission();
7400 final Phone phone = getPhone(subId);
7401 if (phone == null) {
7402 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7403 return;
7404 }
7405
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007406 final long identity = Binder.clearCallingIdentity();
7407 try {
7408 phone.setRadioIndicationUpdateMode(filters, mode);
7409 } finally {
7410 Binder.restoreCallingIdentity(identity);
7411 }
Jack Yu4c988042018-02-27 15:30:01 -08007412 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007413
7414 /**
goneil47ffb6e2018-04-06 15:40:58 -07007415 * A test API to reload the UICC profile.
7416 *
7417 * <p>Requires that the calling app has permission
7418 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7419 * @hide
7420 */
7421 @Override
7422 public void refreshUiccProfile(int subId) {
7423 enforceModifyPermission();
7424
7425 final long identity = Binder.clearCallingIdentity();
7426 try {
7427 Phone phone = getPhone(subId);
7428 if (phone == null) {
7429 return;
7430 }
7431 UiccCard uiccCard = phone.getUiccCard();
7432 if (uiccCard == null) {
7433 return;
7434 }
7435 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7436 if (uiccProfile == null) {
7437 return;
7438 }
7439 uiccProfile.refresh();
7440 } finally {
7441 Binder.restoreCallingIdentity(identity);
7442 }
7443 }
7444
7445 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007446 * Returns false if the mobile data is disabled by default, otherwise return true.
7447 */
7448 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007449 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007450 }
7451
7452 /**
7453 * Returns true if the data roaming is enabled by default, i.e the system property
7454 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7455 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7456 */
7457 private boolean getDefaultDataRoamingEnabled(int subId) {
7458 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007459 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007460 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007461 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7462 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7463 return isDataRoamingEnabled;
7464 }
7465
7466 /**
7467 * Returns the default network type for the given {@code subId}, if the default network type is
7468 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7469 */
7470 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007471 List<Integer> list = TelephonyProperties.default_network();
7472 int phoneId = mSubscriptionController.getPhoneId(subId);
7473 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7474 return list.get(phoneId);
7475 }
7476 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007477 }
fionaxua13278b2018-03-21 00:08:13 -07007478
7479 @Override
7480 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007481 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007482 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007483
7484 final long identity = Binder.clearCallingIdentity();
7485 try {
7486 final Phone phone = getPhone(subId);
7487 if (phone == null) {
7488 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7489 return;
7490 }
chen xueaba88a2019-03-15 13:15:10 -07007491 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7492 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007493 } finally {
7494 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007495 }
fionaxua13278b2018-03-21 00:08:13 -07007496 }
7497
7498 @Override
7499 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007500 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007501
7502 final long identity = Binder.clearCallingIdentity();
7503 try {
7504 final Phone phone = getPhone(subId);
7505 if (phone == null) {
7506 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7507 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7508 }
7509 return phone.getCarrierIdListVersion();
7510 } finally {
7511 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007512 }
fionaxua13278b2018-03-21 00:08:13 -07007513 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007514
7515 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007516 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7517 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007518 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007519 mApp, subId, callingPackage, callingFeatureId,
7520 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007521 return -1;
7522 }
7523
7524 final long identity = Binder.clearCallingIdentity();
7525 try {
7526 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7527 } finally {
7528 Binder.restoreCallingIdentity(identity);
7529 }
7530 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007531
7532 @Override
7533 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007534 TelephonyPermissions
7535 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007536 mApp, subId, "getCdmaRoamingMode");
7537
7538 final long identity = Binder.clearCallingIdentity();
7539 try {
7540 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7541 } finally {
7542 Binder.restoreCallingIdentity(identity);
7543 }
7544 }
7545
7546 @Override
7547 public boolean setCdmaRoamingMode(int subId, int mode) {
7548 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7549 mApp, subId, "setCdmaRoamingMode");
7550
7551 final long identity = Binder.clearCallingIdentity();
7552 try {
7553 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7554 } finally {
7555 Binder.restoreCallingIdentity(identity);
7556 }
7557 }
7558
7559 @Override
7560 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7561 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7562 mApp, subId, "setCdmaSubscriptionMode");
7563
7564 final long identity = Binder.clearCallingIdentity();
7565 try {
7566 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7567 } finally {
7568 Binder.restoreCallingIdentity(identity);
7569 }
7570 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007571
sqianc5eccab2018-10-19 18:46:41 -07007572 @Override
sqian8c685422019-02-22 15:55:18 -08007573 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007574 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007575 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007576 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7577 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007578 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7579 }
7580 final long identity = Binder.clearCallingIdentity();
7581 try {
sqian854d44b2018-12-12 16:48:18 -08007582 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7583 for (Phone phone: PhoneFactory.getPhones()) {
7584 if (phone.getEmergencyNumberTracker() != null
7585 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7586 emergencyNumberListInternal.put(
7587 phone.getSubId(),
7588 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7589 }
sqian11b7a0e2018-12-05 18:48:28 -08007590 }
sqian854d44b2018-12-12 16:48:18 -08007591 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007592 } finally {
7593 Binder.restoreCallingIdentity(identity);
7594 }
sqianc5eccab2018-10-19 18:46:41 -07007595 }
7596
7597 @Override
sqian8c685422019-02-22 15:55:18 -08007598 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007599 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007600 if (!exactMatch) {
7601 TelephonyPermissions
7602 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007603 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007604 }
7605 final long identity = Binder.clearCallingIdentity();
7606 try {
sqian854d44b2018-12-12 16:48:18 -08007607 for (Phone phone: PhoneFactory.getPhones()) {
7608 if (phone.getEmergencyNumberTracker() != null
7609 && phone.getEmergencyNumberTracker() != null) {
7610 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7611 number, exactMatch)) {
7612 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007613 }
7614 }
sqian11b7a0e2018-12-05 18:48:28 -08007615 }
7616 return false;
7617 } finally {
7618 Binder.restoreCallingIdentity(identity);
7619 }
7620 }
7621
sqianf4ca7ed2019-01-15 18:32:07 -08007622 /**
7623 * Update emergency number list for test mode.
7624 */
7625 @Override
7626 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7627 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7628 "updateEmergencyNumberListTestMode");
7629
7630 final long identity = Binder.clearCallingIdentity();
7631 try {
7632 for (Phone phone: PhoneFactory.getPhones()) {
7633 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7634 if (tracker != null) {
7635 tracker.executeEmergencyNumberTestModeCommand(action, num);
7636 }
7637 }
7638 } finally {
7639 Binder.restoreCallingIdentity(identity);
7640 }
7641 }
7642
7643 /**
7644 * Get the full emergency number list for test mode.
7645 */
7646 @Override
7647 public List<String> getEmergencyNumberListTestMode() {
7648 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7649 "getEmergencyNumberListTestMode");
7650
7651 final long identity = Binder.clearCallingIdentity();
7652 try {
7653 Set<String> emergencyNumbers = new HashSet<>();
7654 for (Phone phone: PhoneFactory.getPhones()) {
7655 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7656 if (tracker != null) {
7657 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7658 emergencyNumbers.add(num.getNumber());
7659 }
7660 }
7661 }
7662 return new ArrayList<>(emergencyNumbers);
7663 } finally {
7664 Binder.restoreCallingIdentity(identity);
7665 }
7666 }
7667
chen xud6b45bd2018-10-30 22:27:10 -07007668 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007669 public int getEmergencyNumberDbVersion(int subId) {
7670 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7671
7672 final long identity = Binder.clearCallingIdentity();
7673 try {
7674 final Phone phone = getPhone(subId);
7675 if (phone == null) {
7676 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7677 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7678 }
7679 return phone.getEmergencyNumberDbVersion();
7680 } finally {
7681 Binder.restoreCallingIdentity(identity);
7682 }
7683 }
7684
7685 @Override
7686 public void notifyOtaEmergencyNumberDbInstalled() {
7687 enforceModifyPermission();
7688
7689 final long identity = Binder.clearCallingIdentity();
7690 try {
7691 for (Phone phone: PhoneFactory.getPhones()) {
7692 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7693 if (tracker != null) {
7694 tracker.updateOtaEmergencyNumberDatabase();
7695 }
7696 }
7697 } finally {
7698 Binder.restoreCallingIdentity(identity);
7699 }
7700 }
7701
7702 @Override
7703 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7704 enforceActiveEmergencySessionPermission();
7705
7706 final long identity = Binder.clearCallingIdentity();
7707 try {
7708 for (Phone phone: PhoneFactory.getPhones()) {
7709 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7710 if (tracker != null) {
7711 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7712 }
7713 }
7714 } finally {
7715 Binder.restoreCallingIdentity(identity);
7716 }
7717 }
7718
7719 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007720 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7721 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7722 Phone phone = getPhone(subId);
7723 if (phone == null) {
7724 return null;
7725 }
7726 final long identity = Binder.clearCallingIdentity();
7727 try {
7728 UiccProfile profile = UiccController.getInstance()
7729 .getUiccProfileForPhone(phone.getPhoneId());
7730 if (profile != null) {
7731 return profile.getCertsFromCarrierPrivilegeAccessRules();
7732 }
7733 } finally {
7734 Binder.restoreCallingIdentity(identity);
7735 }
7736 return null;
7737 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007738
7739 /**
7740 * Enable or disable a modem stack.
7741 */
7742 @Override
7743 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7744 enforceModifyPermission();
7745
7746 final long identity = Binder.clearCallingIdentity();
7747 try {
7748 Phone phone = PhoneFactory.getPhone(slotIndex);
7749 if (phone == null) {
7750 return false;
7751 } else {
7752 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7753 }
7754 } finally {
7755 Binder.restoreCallingIdentity(identity);
7756 }
7757 }
Michelecea4cf22018-12-21 15:00:11 -08007758
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007759 /**
7760 * Whether a modem stack is enabled or not.
7761 */
7762 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007763 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7764 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007765 Phone phone = PhoneFactory.getPhone(slotIndex);
7766 if (phone == null) return false;
7767
7768 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007769 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7770 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007771 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7772 }
7773
7774 final long identity = Binder.clearCallingIdentity();
7775 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007776 try {
7777 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7778 } catch (NoSuchElementException ex) {
7779 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7780 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007781 } finally {
7782 Binder.restoreCallingIdentity(identity);
7783 }
7784 }
7785
Michelecea4cf22018-12-21 15:00:11 -08007786 @Override
Michele0ea7d782019-03-19 14:58:42 -07007787 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007788 enforceModifyPermission();
7789
7790 final long identity = Binder.clearCallingIdentity();
7791 try {
7792 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007793 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007794 .commit();
7795 } finally {
7796 Binder.restoreCallingIdentity(identity);
7797 }
7798 }
7799
7800 @Override
Michele0ea7d782019-03-19 14:58:42 -07007801 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007802 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007803 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007804 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7805 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007806 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007807 }
Michelecea4cf22018-12-21 15:00:11 -08007808
7809 final long identity = Binder.clearCallingIdentity();
7810 try {
Michele0ea7d782019-03-19 14:58:42 -07007811 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007812 } finally {
7813 Binder.restoreCallingIdentity(identity);
7814 }
7815 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007816
Michele0ea7d782019-03-19 14:58:42 -07007817 @TelephonyManager.IsMultiSimSupportedResult
7818 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007819 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7820 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7821 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007822 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7823 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007824 }
7825 // Check if the hardware supports multisim functionality. If usage of multisim is not
7826 // supported by the modem, indicate that it is restricted.
7827 PhoneCapability staticCapability =
7828 mPhoneConfigurationManager.getStaticPhoneCapability();
7829 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007830 loge("isMultiSimSupportedInternal: no static configuration available");
7831 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007832 }
Sarah Chin0605abf2019-12-06 10:24:18 -08007833 if (staticCapability.getLogicalModemUuids().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007834 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7835 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007836 }
7837 // Check if support of multiple SIMs is restricted by carrier
7838 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007839 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007840 }
7841
Michele0ea7d782019-03-19 14:58:42 -07007842 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007843 }
7844
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007845 /**
7846 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007847 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7848 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7849 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007850 * @param numOfSims number of active sims we want to switch to
7851 */
7852 @Override
7853 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007854 if (numOfSims == 1) {
7855 enforceModifyPermission();
7856 } else {
7857 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7858 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7859 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007860 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007861
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007862 try {
Michele30b57b22019-03-01 12:01:14 -08007863 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007864 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007865 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7866 return;
7867 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007868 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7869 } finally {
7870 Binder.restoreCallingIdentity(identity);
7871 }
7872 }
7873
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007874 @Override
7875 public boolean isApplicationOnUicc(int subId, int appType) {
7876 enforceReadPrivilegedPermission("isApplicationOnUicc");
7877 Phone phone = getPhone(subId);
7878 if (phone == null) {
7879 return false;
7880 }
7881 final long identity = Binder.clearCallingIdentity();
7882 try {
7883 UiccCard uiccCard = phone.getUiccCard();
7884 if (uiccCard == null) {
7885 return false;
7886 }
7887 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7888 if (uiccProfile == null) {
7889 return false;
7890 }
7891 if (TelephonyManager.APPTYPE_SIM <= appType
7892 && appType <= TelephonyManager.APPTYPE_ISIM) {
7893 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7894 }
7895 return false;
7896 } finally {
7897 Binder.restoreCallingIdentity(identity);
7898 }
7899 }
7900
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007901 /**
chen xub4baa772019-04-03 10:23:41 -07007902 * Get whether making changes to modem configurations will trigger reboot.
7903 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007904 */
7905 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007906 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7907 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007908 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007909 mApp, subId, callingPackage, callingFeatureId,
7910 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007911 return false;
7912 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007913 final long identity = Binder.clearCallingIdentity();
7914 try {
7915 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7916 } finally {
7917 Binder.restoreCallingIdentity(identity);
7918 }
7919 }
7920
Nathan Harold29f5f052019-02-15 13:41:57 -08007921 private void updateModemStateMetrics() {
7922 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7923 // TODO: check the state for each modem if the api is ready.
7924 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7925 }
7926
Pengquan Meng3889a572019-01-23 11:16:29 -08007927 @Override
7928 public int[] getSlotsMapping() {
7929 enforceReadPrivilegedPermission("getSlotsMapping");
7930
7931 final long identity = Binder.clearCallingIdentity();
7932 try {
7933 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7934 // All logical slots should have a mapping to a physical slot.
7935 int[] logicalSlotsMapping = new int[phoneCount];
7936 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7937 for (int i = 0; i < slotInfos.length; i++) {
7938 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7939 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7940 }
7941 }
7942 return logicalSlotsMapping;
7943 } finally {
7944 Binder.restoreCallingIdentity(identity);
7945 }
7946 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007947
7948 /**
7949 * Get the IRadio HAL Version
7950 */
7951 @Override
7952 public int getRadioHalVersion() {
7953 Phone phone = getDefaultPhone();
7954 if (phone == null) return -1;
7955 HalVersion hv = phone.getHalVersion();
7956 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7957 return hv.major * 100 + hv.minor;
7958 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007959
7960 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08007961 * Get the current calling package name.
7962 * @return the current calling package name
7963 */
7964 @Override
7965 public String getCurrentPackageName() {
7966 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
7967 }
7968
7969 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007970 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7971 * corresponding network requests on a subId.
7972 *
7973 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007974 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007975 * 2) APN is un-metered for this subscription, or
7976 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08007977 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07007978 *
7979 * @return whether data is allowed for a apn type.
7980 *
7981 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007982 */
7983 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007984 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007985 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7986 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007987
7988 // Now that all security checks passes, perform the operation as ourselves.
7989 final long identity = Binder.clearCallingIdentity();
7990 try {
7991 Phone phone = getPhone(subId);
7992 if (phone == null) return false;
7993
Jack Yu41407ee2019-05-13 16:54:09 -07007994 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007995 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7996 } finally {
7997 Binder.restoreCallingIdentity(identity);
7998 }
7999 }
8000
8001 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008002 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008003 enforceReadPrivilegedPermission("isApnMetered");
8004
8005 // Now that all security checks passes, perform the operation as ourselves.
8006 final long identity = Binder.clearCallingIdentity();
8007 try {
8008 Phone phone = getPhone(subId);
8009 if (phone == null) return true; // By default return true.
8010
Jack Yu41407ee2019-05-13 16:54:09 -07008011 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008012 } finally {
8013 Binder.restoreCallingIdentity(identity);
8014 }
8015 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008016
8017 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008018 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8019 int subscriptionId, IBooleanConsumer resultCallback) {
8020 enforceModifyPermission();
8021 long token = Binder.clearCallingIdentity();
8022 try {
8023 Phone phone = getPhone(subscriptionId);
8024 if (phone == null) {
8025 try {
8026 if (resultCallback != null) {
8027 resultCallback.accept(false);
8028 }
8029 } catch (RemoteException e) {
8030 // ignore
8031 }
8032 return;
8033 }
8034 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8035 Pair.create(specifiers, (x) -> {
8036 try {
8037 if (resultCallback != null) {
8038 resultCallback.accept(x);
8039 }
8040 } catch (RemoteException e) {
8041 // ignore
8042 }
8043 });
8044 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8045 } finally {
8046 Binder.restoreCallingIdentity(token);
8047 }
8048 }
8049
8050 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008051 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8052 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8053 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8054 if (iccRecords == null) {
8055 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8056 return false;
8057 }
8058 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8059 }
8060
8061 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07008062 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008063 if (callingPackage == null) {
8064 callingPackage = getCurrentPackageName();
8065 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008066 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8067 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
8068 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
8069 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8070 }
8071 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8072 Intent intent = new Intent();
8073 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8074 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8075 // Bring up choose default SMS subscription dialog right now
8076 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8077 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8078 mApp.startActivity(intent);
8079 }
chen xud5ca2d52019-05-28 15:20:57 -07008080
8081 @Override
8082 public String getMmsUAProfUrl(int subId) {
8083 //TODO investigate if this API should require proper permission check in R b/133791609
8084 final long identity = Binder.clearCallingIdentity();
8085 try {
8086 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8087 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8088 } finally {
8089 Binder.restoreCallingIdentity(identity);
8090 }
8091 }
8092
8093 @Override
8094 public String getMmsUserAgent(int subId) {
8095 //TODO investigate if this API should require proper permission check in R b/133791609
8096 final long identity = Binder.clearCallingIdentity();
8097 try {
8098 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8099 .getString(com.android.internal.R.string.config_mms_user_agent);
8100 } finally {
8101 Binder.restoreCallingIdentity(identity);
8102 }
8103 }
Jack Yub07d4972019-05-28 16:12:25 -07008104
8105 @Override
8106 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8107 enforceModifyPermission();
8108
8109 // Now that all security checks passes, perform the operation as ourselves.
8110 final long identity = Binder.clearCallingIdentity();
8111 try {
8112 Phone phone = getPhone(subId);
8113 if (phone == null) return false;
8114
8115 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8116 } finally {
8117 Binder.restoreCallingIdentity(identity);
8118 }
8119 }
8120
8121 @Override
8122 public boolean isDataAllowedInVoiceCall(int subId) {
8123 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8124
8125 // Now that all security checks passes, perform the operation as ourselves.
8126 final long identity = Binder.clearCallingIdentity();
8127 try {
8128 Phone phone = getPhone(subId);
8129 if (phone == null) return false;
8130
8131 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8132 } finally {
8133 Binder.restoreCallingIdentity(identity);
8134 }
8135 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008136
changbettyd5c246e2019-12-24 15:40:37 +08008137 @Override
8138 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8139 enforceModifyPermission();
8140
8141 // Now that all security checks passes, perform the operation as ourselves.
8142 final long identity = Binder.clearCallingIdentity();
8143 try {
8144 Phone phone = getPhone(subId);
8145 if (phone == null) return false;
8146
8147 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8148 } finally {
8149 Binder.restoreCallingIdentity(identity);
8150 }
8151 }
8152
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008153 /**
8154 * Updates whether conference event pacakge handling is enabled.
8155 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8156 * otherwise.
8157 */
8158 @Override
8159 public void setCepEnabled(boolean isCepEnabled) {
8160 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8161
8162 final long identity = Binder.clearCallingIdentity();
8163 try {
8164 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8165 for (Phone phone : PhoneFactory.getPhones()) {
8166 Phone defaultPhone = phone.getImsPhone();
8167 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8168 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8169 ImsPhoneCallTracker imsPhoneCallTracker =
8170 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8171 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8172 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8173 + imsPhone.getMsisdn());
8174 }
8175 }
8176 } finally {
8177 Binder.restoreCallingIdentity(identity);
8178 }
8179 }
allenwtsu46dcc572020-01-08 18:24:03 +08008180
8181 /**
8182 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8183 *
8184 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8185 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8186 * before being read.
8187 */
8188 @Override
8189 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8190 isCompressed) {
8191 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8192 mApp, subId, "notifyRcsAutoConfigurationReceived");
8193 try {
8194 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8195 if (configBinder == null) {
8196 Rlog.e(LOG_TAG, "null result for getImsConfig");
8197 } else {
8198 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8199 }
8200 } catch (RemoteException e) {
8201 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8202 }
8203 }
zoey chene02881a2019-12-30 16:11:23 +08008204
8205 @Override
8206 public boolean isIccLockEnabled(int subId) {
8207 enforceReadPrivilegedPermission("isIccLockEnabled");
8208
8209 // Now that all security checks passes, perform the operation as ourselves.
8210 final long identity = Binder.clearCallingIdentity();
8211 try {
8212 Phone phone = getPhone(subId);
8213 if (phone != null && phone.getIccCard() != null) {
8214 return phone.getIccCard().getIccLockEnabled();
8215 } else {
8216 return false;
8217 }
8218 } finally {
8219 Binder.restoreCallingIdentity(identity);
8220 }
8221 }
8222
8223 /**
8224 * Set the ICC pin lock enabled or disabled.
8225 *
8226 * @return an integer representing the status of IccLock enabled or disabled in the following
8227 * three cases:
8228 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8229 * successfully.
8230 * - Positive number and zero for remaining password attempts.
8231 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8232 *
8233 */
8234 @Override
8235 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8236 enforceModifyPermission();
8237
8238 Phone phone = getPhone(subId);
8239 if (phone == null) {
8240 return 0;
8241 }
8242 // Now that all security checks passes, perform the operation as ourselves.
8243 final long identity = Binder.clearCallingIdentity();
8244 try {
8245 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8246 new Pair<Boolean, String>(enabled, password), phone, null);
8247 return attemptsRemaining;
8248
8249 } catch (Exception e) {
8250 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8251 } finally {
8252 Binder.restoreCallingIdentity(identity);
8253 }
8254 return 0;
8255 }
8256
8257 /**
8258 * Change the ICC password used in ICC pin lock.
8259 *
8260 * @return an integer representing the status of IccLock changed in the following three cases:
8261 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8262 * - Positive number and zero for remaining password attempts.
8263 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8264 *
8265 */
8266 @Override
8267 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8268 enforceModifyPermission();
8269
8270 Phone phone = getPhone(subId);
8271 if (phone == null) {
8272 return 0;
8273 }
8274 // Now that all security checks passes, perform the operation as ourselves.
8275 final long identity = Binder.clearCallingIdentity();
8276 try {
8277 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8278 new Pair<String, String>(oldPassword, newPassword), phone, null);
8279 return attemptsRemaining;
8280
8281 } catch (Exception e) {
8282 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8283 } finally {
8284 Binder.restoreCallingIdentity(identity);
8285 }
8286 return 0;
8287 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008288
8289 /**
8290 * Request for receiving user activity notification
8291 */
8292 @Override
8293 public void requestUserActivityNotification() {
8294 if (!mNotifyUserActivity.get()
8295 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8296 mNotifyUserActivity.set(true);
8297 }
8298 }
8299
8300 /**
8301 * Called when userActivity is signalled in the power manager.
8302 * This is safe to call from any thread, with any window manager locks held or not.
8303 */
8304 @Override
8305 public void userActivity() {
8306 // ***************************************
8307 // * Inherited from PhoneWindowManager *
8308 // ***************************************
8309 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8310 // WITH ITS LOCKS HELD.
8311 //
8312 // This code must be VERY careful about the locks
8313 // it acquires.
8314 // In fact, the current code acquires way too many,
8315 // and probably has lurking deadlocks.
8316
8317 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8318 throw new SecurityException("Only the OS may call notifyUserActivity()");
8319 }
8320
8321 if (mNotifyUserActivity.getAndSet(false)) {
8322 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8323 USER_ACTIVITY_NOTIFICATION_DELAY);
8324 }
8325 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008326}