blob: 67bbfef778a6e61063c2a474354f12ec5fbd9788 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070038import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.net.Uri;
40import android.os.AsyncResult;
41import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080042import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.os.Bundle;
44import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070045import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.Looper;
47import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070048import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080049import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070050import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070051import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080052import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080053import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070054import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070055import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070060import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080061import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070062import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090063import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080064import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080065import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070066import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070067import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080071import android.telephony.CellIdentityCdma;
72import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070074import android.telephony.CellInfoGsm;
75import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070076import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070077import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070078import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080079import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070080import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070082import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080083import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080084import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080088import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080089import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080091import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070092import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080095import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000096import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070097import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsMmTelFeature;
108import android.telephony.ims.aidl.IImsRcsFeature;
109import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700110import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800113import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800114import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800115import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800119import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800120import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800121
Andrew Lee312e8172014-10-23 17:01:36 -0700122import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800123import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700124import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700125import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700126import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800127import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700128import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700129import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800131import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800132import com.android.internal.telephony.IBooleanConsumer;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700133import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800134import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700135import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800136import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700137import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700138import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700139import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700141import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800142import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700143import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700144import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700145import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700146import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700147import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700148import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700149import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700150import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800151import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800152import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700153import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800154import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700155import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800156import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700157import com.android.internal.telephony.imsphone.ImsPhone;
158import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800159import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700160import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700161import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800162import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800164import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700165import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800166import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700167import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800168import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000169import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800170import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700171import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800172import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700173import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700174import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800175import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700176import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700177import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang44b186e2020-01-13 23:33:09 -0800178import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800179
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700180import java.io.FileDescriptor;
181import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700182import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800183import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800184import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800185import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800186import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100187import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800188import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700189import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800190import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800191import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800192import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193
194/**
195 * Implementation of the ITelephony interface.
196 */
Santos Cordon117fee72014-05-16 17:56:12 -0700197public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198 private static final String LOG_TAG = "PhoneInterfaceManager";
199 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
200 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800201 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700202
203 // Message codes used with mMainThreadHandler
204 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700205 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
206 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700207 private static final int CMD_OPEN_CHANNEL = 9;
208 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
209 private static final int CMD_CLOSE_CHANNEL = 11;
210 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800211 private static final int CMD_NV_READ_ITEM = 13;
212 private static final int EVENT_NV_READ_ITEM_DONE = 14;
213 private static final int CMD_NV_WRITE_ITEM = 15;
214 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
215 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
216 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700217 private static final int CMD_RESET_MODEM_CONFIG = 19;
218 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800219 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
220 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
221 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
222 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800223 private static final int CMD_SEND_ENVELOPE = 25;
224 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000225 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
226 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700227 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
228 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
229 private static final int CMD_EXCHANGE_SIM_IO = 31;
230 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800231 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
232 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700233 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
234 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700235 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
236 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700237 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
238 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
239 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
240 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700241 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
242 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
243 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
244 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700245 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800246 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
247 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000248 private static final int CMD_SWITCH_SLOTS = 50;
249 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700250 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
251 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
252 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
253 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
254 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
255 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
256 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
257 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700258 private static final int CMD_GET_ALL_CELL_INFO = 60;
259 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
260 private static final int CMD_GET_CELL_LOCATION = 62;
261 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700262 private static final int CMD_MODEM_REBOOT = 64;
263 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700264 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
265 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800266 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
267 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700268 private static final int CMD_GET_MODEM_STATUS = 70;
269 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700270 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
271 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700272 private static final int CMD_ERASE_MODEM_CONFIG = 74;
273 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800274 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
275 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
276 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
277 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800278 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
279 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800280 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700281
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800282 // Parameters of select command.
283 private static final int SELECT_COMMAND = 0xA4;
284 private static final int SELECT_P1 = 0x04;
285 private static final int SELECT_P2 = 0;
286 private static final int SELECT_P3 = 0x10;
287
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700288 /** The singleton instance. */
289 private static PhoneInterfaceManager sInstance;
290
Wink Saville3ab207e2014-11-20 13:07:20 -0800291 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800292 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800293 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700294 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800295 private AppOpsManager mAppOps;
296 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800297 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800298 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700299 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700300
Peter Wangdafb9ac2020-01-15 14:13:38 -0800301 /** User Activity */
302 private AtomicBoolean mNotifyUserActivity;
303 private static final String ACTION_USER_ACTIVITY_NOTIFICATION =
304 "android.intent.action.USER_ACTIVITY_NOTIFICATION";
305 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
306
Derek Tan97ebb422014-09-05 16:55:38 -0700307 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
308 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800309 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800310 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700311
Michelecea4cf22018-12-21 15:00:11 -0800312 // String to store multi SIM allowed
313 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
314
Derek Tan740e1672017-06-27 14:56:27 -0700315 // The AID of ISD-R.
316 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
317
yinxub1bed742017-04-17 11:45:04 -0700318 private NetworkScanRequestTracker mNetworkScanRequestTracker;
319
David Kelly5e06a7f2018-03-12 14:10:59 +0000320 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
321 private static final int MANUFACTURER_CODE_LENGTH = 8;
322
Derek Tan89e89d42014-07-08 17:00:10 -0700323 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700324 * Experiment flag to enable erase modem config on reset network, default value is false
325 */
326 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
327 "reset_network_erase_modem_config_enabled";
328
329 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700330 * A request object to use for transmitting data to an ICC.
331 */
332 private static final class IccAPDUArgument {
333 public int channel, cla, command, p1, p2, p3;
334 public String data;
335
336 public IccAPDUArgument(int channel, int cla, int command,
337 int p1, int p2, int p3, String data) {
338 this.channel = channel;
339 this.cla = cla;
340 this.command = command;
341 this.p1 = p1;
342 this.p2 = p2;
343 this.p3 = p3;
344 this.data = data;
345 }
346 }
347
348 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700349 * A request object to use for transmitting data to an ICC.
350 */
351 private static final class ManualNetworkSelectionArgument {
352 public OperatorInfo operatorInfo;
353 public boolean persistSelection;
354
355 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
356 this.operatorInfo = operatorInfo;
357 this.persistSelection = persistSelection;
358 }
359 }
360
361 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
363 * request after sending. The main thread will notify the request when it is complete.
364 */
365 private static final class MainThreadRequest {
366 /** The argument to use for the request */
367 public Object argument;
368 /** The result of the request that is run on the main thread */
369 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800370 // The subscriber id that this request applies to. Defaults to
371 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
372 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373
Nathan Harold92bed182018-10-12 18:16:49 -0700374 // In cases where subId is unavailable, the caller needs to specify the phone.
375 public Phone phone;
376
vagdeviaf9a5b92018-08-15 16:01:53 -0700377 public WorkSource workSource;
378
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700379 public MainThreadRequest(Object argument) {
380 this.argument = argument;
381 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800382
Nathan Harold92bed182018-10-12 18:16:49 -0700383 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
384 this.argument = argument;
385 if (phone != null) {
386 this.phone = phone;
387 }
388 this.workSource = workSource;
389 }
390
vagdeviaf9a5b92018-08-15 16:01:53 -0700391 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800392 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800393 if (subId != null) {
394 this.subId = subId;
395 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700396 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800397 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398 }
399
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800400 private static final class IncomingThirdPartyCallArgs {
401 public final ComponentName component;
402 public final String callId;
403 public final String callerDisplayName;
404
405 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
406 String callerDisplayName) {
407 this.component = component;
408 this.callId = callId;
409 this.callerDisplayName = callerDisplayName;
410 }
411 }
412
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413 /**
414 * A handler that processes messages on the main thread in the phone process. Since many
415 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
416 * inbound binder threads to the main thread in the phone process. The Binder thread
417 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
418 * on, which will be notified when the operation completes and will contain the result of the
419 * request.
420 *
421 * <p>If a MainThreadRequest object is provided in the msg.obj field,
422 * note that request.result must be set to something non-null for the calling thread to
423 * unblock.
424 */
425 private final class MainThreadHandler extends Handler {
426 @Override
427 public void handleMessage(Message msg) {
428 MainThreadRequest request;
429 Message onCompleted;
430 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800431 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700432 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800433 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434
435 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700436 case CMD_HANDLE_USSD_REQUEST: {
437 request = (MainThreadRequest) msg.obj;
438 final Phone phone = getPhoneFromRequest(request);
439 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
440 String ussdRequest = ussdObject.first;
441 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700442
Pengquan Menga1bb6272018-09-06 09:59:22 -0700443 if (!isUssdApiAllowed(request.subId)) {
444 // Carrier does not support use of this API, return failure.
445 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
446 UssdResponse response = new UssdResponse(ussdRequest, null);
447 Bundle returnData = new Bundle();
448 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
449 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700450
Pengquan Menga1bb6272018-09-06 09:59:22 -0700451 request.result = true;
452 notifyRequester(request);
453 return;
454 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700455
Pengquan Menga1bb6272018-09-06 09:59:22 -0700456 try {
457 request.result = phone != null
458 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
459 } catch (CallStateException cse) {
460 request.result = false;
461 }
462 // Wake up the requesting thread
463 notifyRequester(request);
464 break;
pkanwar32d516d2016-10-14 19:37:38 -0700465 }
466
Yorke Lee716f67e2015-06-17 15:39:16 -0700467 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700468 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700469 final Phone phone = getPhoneFromRequest(request);
470 request.result = phone != null ?
471 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
472 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700473 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700474 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700475 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700476 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700477
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700478 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700479 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700480 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800481 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700482 if (uiccCard == null) {
483 loge("iccTransmitApduLogicalChannel: No UICC");
484 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700485 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700486 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
488 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700489 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 iccArgument.channel, iccArgument.cla, iccArgument.command,
491 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700492 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700493 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700494 break;
495
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700497 ar = (AsyncResult) msg.obj;
498 request = (MainThreadRequest) ar.userObj;
499 if (ar.exception == null && ar.result != null) {
500 request.result = ar.result;
501 } else {
502 request.result = new IccIoResult(0x6F, 0, (byte[])null);
503 if (ar.result == null) {
504 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800505 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700506 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800507 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700508 } else {
509 loge("iccTransmitApduLogicalChannel: Unknown exception");
510 }
511 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700512 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700513 break;
514
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700515 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
516 request = (MainThreadRequest) msg.obj;
517 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800518 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700519 if (uiccCard == null) {
520 loge("iccTransmitApduBasicChannel: No UICC");
521 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700522 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 } else {
524 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
525 request);
526 uiccCard.iccTransmitApduBasicChannel(
527 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
528 iccArgument.p3, iccArgument.data, onCompleted);
529 }
530 break;
531
532 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
533 ar = (AsyncResult) msg.obj;
534 request = (MainThreadRequest) ar.userObj;
535 if (ar.exception == null && ar.result != null) {
536 request.result = ar.result;
537 } else {
538 request.result = new IccIoResult(0x6F, 0, (byte[])null);
539 if (ar.result == null) {
540 loge("iccTransmitApduBasicChannel: Empty response");
541 } else if (ar.exception instanceof CommandException) {
542 loge("iccTransmitApduBasicChannel: CommandException: " +
543 ar.exception);
544 } else {
545 loge("iccTransmitApduBasicChannel: Unknown exception");
546 }
547 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700548 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700549 break;
550
551 case CMD_EXCHANGE_SIM_IO:
552 request = (MainThreadRequest) msg.obj;
553 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800554 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700555 if (uiccCard == null) {
556 loge("iccExchangeSimIO: No UICC");
557 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700558 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700559 } else {
560 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
561 request);
562 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
563 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
564 iccArgument.data, onCompleted);
565 }
566 break;
567
568 case EVENT_EXCHANGE_SIM_IO_DONE:
569 ar = (AsyncResult) msg.obj;
570 request = (MainThreadRequest) ar.userObj;
571 if (ar.exception == null && ar.result != null) {
572 request.result = ar.result;
573 } else {
574 request.result = new IccIoResult(0x6f, 0, (byte[])null);
575 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700576 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700577 break;
578
Derek Tan4d5e5c12014-02-04 11:54:58 -0800579 case CMD_SEND_ENVELOPE:
580 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800581 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700582 if (uiccCard == null) {
583 loge("sendEnvelopeWithStatus: No UICC");
584 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700585 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700586 } else {
587 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
588 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
589 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800590 break;
591
592 case EVENT_SEND_ENVELOPE_DONE:
593 ar = (AsyncResult) msg.obj;
594 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700595 if (ar.exception == null && ar.result != null) {
596 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800597 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700598 request.result = new IccIoResult(0x6F, 0, (byte[])null);
599 if (ar.result == null) {
600 loge("sendEnvelopeWithStatus: Empty response");
601 } else if (ar.exception instanceof CommandException) {
602 loge("sendEnvelopeWithStatus: CommandException: " +
603 ar.exception);
604 } else {
605 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
606 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800607 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700608 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800609 break;
610
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 case CMD_OPEN_CHANNEL:
612 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800613 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800614 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700615 if (uiccCard == null) {
616 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800617 request.result = new IccOpenLogicalChannelResponse(-1,
618 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700620 } else {
621 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800622 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
623 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700624 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 break;
626
627 case EVENT_OPEN_CHANNEL_DONE:
628 ar = (AsyncResult) msg.obj;
629 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700632 int[] result = (int[]) ar.result;
633 int channelId = result[0];
634 byte[] selectResponse = null;
635 if (result.length > 1) {
636 selectResponse = new byte[result.length - 1];
637 for (int i = 1; i < result.length; ++i) {
638 selectResponse[i - 1] = (byte) result[i];
639 }
640 }
641 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700642 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 if (ar.result == null) {
645 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700647 if (ar.exception != null) {
648 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
649 }
650
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700651 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700652 if (ar.exception instanceof CommandException) {
653 CommandException.Error error =
654 ((CommandException) (ar.exception)).getCommandError();
655 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700656 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700657 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700658 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700659 }
660 }
661 openChannelResp = new IccOpenLogicalChannelResponse(
662 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700664 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700665 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700666 break;
667
668 case CMD_CLOSE_CHANNEL:
669 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800670 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700671 if (uiccCard == null) {
672 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900673 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700674 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700675 } else {
676 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
677 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
678 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 break;
680
681 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800682 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
683 break;
684
685 case CMD_NV_READ_ITEM:
686 request = (MainThreadRequest) msg.obj;
687 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800688 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
689 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800690 break;
691
692 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700693 ar = (AsyncResult) msg.obj;
694 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800695 if (ar.exception == null && ar.result != null) {
696 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700697 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800698 request.result = "";
699 if (ar.result == null) {
700 loge("nvReadItem: Empty response");
701 } else if (ar.exception instanceof CommandException) {
702 loge("nvReadItem: CommandException: " +
703 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700704 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800705 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 }
707 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700708 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700709 break;
710
Jake Hambye994d462014-02-03 13:10:13 -0800711 case CMD_NV_WRITE_ITEM:
712 request = (MainThreadRequest) msg.obj;
713 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
714 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800715 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700716 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800717 break;
718
719 case EVENT_NV_WRITE_ITEM_DONE:
720 handleNullReturnEvent(msg, "nvWriteItem");
721 break;
722
723 case CMD_NV_WRITE_CDMA_PRL:
724 request = (MainThreadRequest) msg.obj;
725 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800726 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800727 break;
728
729 case EVENT_NV_WRITE_CDMA_PRL_DONE:
730 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
731 break;
732
chen xu6dac5ab2018-10-26 17:39:23 -0700733 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800734 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700735 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800736 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800737 break;
738
chen xu6dac5ab2018-10-26 17:39:23 -0700739 case EVENT_RESET_MODEM_CONFIG_DONE:
740 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800741 break;
742
Jake Hamby7c27be32014-03-03 13:25:59 -0800743 case CMD_GET_PREFERRED_NETWORK_TYPE:
744 request = (MainThreadRequest) msg.obj;
745 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700746 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800747 break;
748
749 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
750 ar = (AsyncResult) msg.obj;
751 request = (MainThreadRequest) ar.userObj;
752 if (ar.exception == null && ar.result != null) {
753 request.result = ar.result; // Integer
754 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800755 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800756 if (ar.result == null) {
757 loge("getPreferredNetworkType: Empty response");
758 } else if (ar.exception instanceof CommandException) {
759 loge("getPreferredNetworkType: CommandException: " +
760 ar.exception);
761 } else {
762 loge("getPreferredNetworkType: Unknown exception");
763 }
764 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700765 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800766 break;
767
768 case CMD_SET_PREFERRED_NETWORK_TYPE:
769 request = (MainThreadRequest) msg.obj;
770 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
771 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700772 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800773 break;
774
775 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
776 handleNullReturnEvent(msg, "setPreferredNetworkType");
777 break;
778
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000779 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
780 request = (MainThreadRequest)msg.obj;
781 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800782 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000783 break;
784
785 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
786 ar = (AsyncResult)msg.obj;
787 request = (MainThreadRequest)ar.userObj;
788 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700789 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000790 break;
791
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800792 case CMD_SET_VOICEMAIL_NUMBER:
793 request = (MainThreadRequest) msg.obj;
794 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
795 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800796 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
797 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800798 break;
799
800 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
801 handleNullReturnEvent(msg, "setVoicemailNumber");
802 break;
803
Stuart Scott54788802015-03-30 13:18:01 -0700804 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
805 request = (MainThreadRequest) msg.obj;
806 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
807 request);
808 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
809 break;
810
811 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
812 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
813 break;
814
Shishir Agrawal302c8692015-06-19 13:49:39 -0700815 case CMD_PERFORM_NETWORK_SCAN:
816 request = (MainThreadRequest) msg.obj;
817 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
818 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
819 break;
820
821 case EVENT_PERFORM_NETWORK_SCAN_DONE:
822 ar = (AsyncResult) msg.obj;
823 request = (MainThreadRequest) ar.userObj;
824 CellNetworkScanResult cellScanResult;
825 if (ar.exception == null && ar.result != null) {
826 cellScanResult = new CellNetworkScanResult(
827 CellNetworkScanResult.STATUS_SUCCESS,
828 (List<OperatorInfo>) ar.result);
829 } else {
830 if (ar.result == null) {
831 loge("getCellNetworkScanResults: Empty response");
832 }
833 if (ar.exception != null) {
834 loge("getCellNetworkScanResults: Exception: " + ar.exception);
835 }
836 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
837 if (ar.exception instanceof CommandException) {
838 CommandException.Error error =
839 ((CommandException) (ar.exception)).getCommandError();
840 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
841 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
842 } else if (error == CommandException.Error.GENERIC_FAILURE) {
843 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
844 }
845 }
846 cellScanResult = new CellNetworkScanResult(errorCode, null);
847 }
848 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700849 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700850 break;
851
852 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
853 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700854 ManualNetworkSelectionArgument selArg =
855 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700856 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
857 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700858 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
859 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700860 break;
861
862 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700863 ar = (AsyncResult) msg.obj;
864 request = (MainThreadRequest) ar.userObj;
865 if (ar.exception == null) {
866 request.result = true;
867 } else {
868 request.result = false;
869 loge("setNetworkSelectionModeManual " + ar.exception);
870 }
871 notifyRequester(request);
872 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700873 break;
874
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700875 case CMD_GET_MODEM_ACTIVITY_INFO:
876 request = (MainThreadRequest) msg.obj;
877 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700878 if (defaultPhone != null) {
879 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
880 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700881 break;
882
883 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
884 ar = (AsyncResult) msg.obj;
885 request = (MainThreadRequest) ar.userObj;
886 if (ar.exception == null && ar.result != null) {
887 request.result = ar.result;
888 } else {
889 if (ar.result == null) {
890 loge("queryModemActivityInfo: Empty response");
891 } else if (ar.exception instanceof CommandException) {
892 loge("queryModemActivityInfo: CommandException: " +
893 ar.exception);
894 } else {
895 loge("queryModemActivityInfo: Unknown exception");
896 }
897 }
Amit Mahajand4766222016-01-28 15:28:28 -0800898 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
899 if (request.result == null) {
Peter Collingbournec00e9022019-11-26 09:56:26 -0800900 request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800901 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700902 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700903 break;
904
Meng Wang1a7c35a2016-05-05 20:56:15 -0700905 case CMD_SET_ALLOWED_CARRIERS:
906 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800907 CarrierRestrictionRules argument =
908 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700909 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800910 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700911 break;
912
913 case EVENT_SET_ALLOWED_CARRIERS_DONE:
914 ar = (AsyncResult) msg.obj;
915 request = (MainThreadRequest) ar.userObj;
916 if (ar.exception == null && ar.result != null) {
917 request.result = ar.result;
918 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800919 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
920 if (ar.exception instanceof CommandException) {
921 loge("setAllowedCarriers: CommandException: " + ar.exception);
922 CommandException.Error error =
923 ((CommandException) (ar.exception)).getCommandError();
924 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
925 request.result =
926 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
927 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700928 } else {
929 loge("setAllowedCarriers: Unknown exception");
930 }
931 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700932 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700933 break;
934
935 case CMD_GET_ALLOWED_CARRIERS:
936 request = (MainThreadRequest) msg.obj;
937 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800938 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700939 break;
940
941 case EVENT_GET_ALLOWED_CARRIERS_DONE:
942 ar = (AsyncResult) msg.obj;
943 request = (MainThreadRequest) ar.userObj;
944 if (ar.exception == null && ar.result != null) {
945 request.result = ar.result;
946 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800947 request.result = new IllegalStateException(
948 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700949 if (ar.result == null) {
950 loge("getAllowedCarriers: Empty response");
951 } else if (ar.exception instanceof CommandException) {
952 loge("getAllowedCarriers: CommandException: " +
953 ar.exception);
954 } else {
955 loge("getAllowedCarriers: Unknown exception");
956 }
957 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700958 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700959 break;
960
Nathan Haroldb3014052017-01-25 15:57:32 -0800961 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
962 ar = (AsyncResult) msg.obj;
963 request = (MainThreadRequest) ar.userObj;
964 if (ar.exception == null && ar.result != null) {
965 request.result = ar.result;
966 } else {
967 request.result = new IllegalArgumentException(
968 "Failed to retrieve Forbidden Plmns");
969 if (ar.result == null) {
970 loge("getForbiddenPlmns: Empty response");
971 } else {
972 loge("getForbiddenPlmns: Unknown exception");
973 }
974 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700975 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800976 break;
977
978 case CMD_GET_FORBIDDEN_PLMNS:
979 request = (MainThreadRequest) msg.obj;
980 uiccCard = getUiccCardFromRequest(request);
981 if (uiccCard == null) {
982 loge("getForbiddenPlmns() UiccCard is null");
983 request.result = new IllegalArgumentException(
984 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700985 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800986 break;
987 }
988 Integer appType = (Integer) request.argument;
989 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
990 if (uiccApp == null) {
991 loge("getForbiddenPlmns() no app with specified type -- "
992 + appType);
993 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700994 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800995 break;
996 } else {
997 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
998 + " specified type -- " + appType);
999 }
1000 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1001 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1002 onCompleted);
1003 break;
1004
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001005 case CMD_SWITCH_SLOTS:
1006 request = (MainThreadRequest) msg.obj;
1007 int[] physicalSlots = (int[]) request.argument;
1008 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1009 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1010 break;
1011
1012 case EVENT_SWITCH_SLOTS_DONE:
1013 ar = (AsyncResult) msg.obj;
1014 request = (MainThreadRequest) ar.userObj;
1015 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001016 notifyRequester(request);
1017 break;
1018 case CMD_GET_NETWORK_SELECTION_MODE:
1019 request = (MainThreadRequest) msg.obj;
1020 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1021 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1022 break;
1023
1024 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1025 ar = (AsyncResult) msg.obj;
1026 request = (MainThreadRequest) ar.userObj;
1027 if (ar.exception != null) {
1028 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1029 } else {
1030 int mode = ((int[]) ar.result)[0];
1031 if (mode == 0) {
1032 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1033 } else {
1034 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1035 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001036 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001037 notifyRequester(request);
1038 break;
1039 case CMD_GET_CDMA_ROAMING_MODE:
1040 request = (MainThreadRequest) msg.obj;
1041 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1042 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1043 break;
1044 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1045 ar = (AsyncResult) msg.obj;
1046 request = (MainThreadRequest) ar.userObj;
1047 if (ar.exception != null) {
1048 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1049 } else {
1050 request.result = ((int[]) ar.result)[0];
1051 }
1052 notifyRequester(request);
1053 break;
1054 case CMD_SET_CDMA_ROAMING_MODE:
1055 request = (MainThreadRequest) msg.obj;
1056 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1057 int mode = (int) request.argument;
1058 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1059 break;
1060 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1061 ar = (AsyncResult) msg.obj;
1062 request = (MainThreadRequest) ar.userObj;
1063 request.result = ar.exception == null;
1064 notifyRequester(request);
1065 break;
1066 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1067 request = (MainThreadRequest) msg.obj;
1068 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1069 int subscriptionMode = (int) request.argument;
1070 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1071 break;
1072 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1073 ar = (AsyncResult) msg.obj;
1074 request = (MainThreadRequest) ar.userObj;
1075 request.result = ar.exception == null;
1076 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001077 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001078 case CMD_GET_ALL_CELL_INFO:
1079 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001080 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001081 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001082 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001083 case EVENT_GET_ALL_CELL_INFO_DONE:
1084 ar = (AsyncResult) msg.obj;
1085 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001086 // If a timeout occurs, the response will be null
1087 request.result = (ar.exception == null && ar.result != null)
1088 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001089 synchronized (request) {
1090 request.notifyAll();
1091 }
1092 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001093 case CMD_REQUEST_CELL_INFO_UPDATE:
1094 request = (MainThreadRequest) msg.obj;
1095 request.phone.requestCellInfoUpdate(request.workSource,
1096 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1097 break;
1098 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1099 ar = (AsyncResult) msg.obj;
1100 request = (MainThreadRequest) ar.userObj;
1101 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1102 try {
1103 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001104 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001105 cb.onError(
1106 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1107 ar.exception.getClass().getName(),
1108 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001109 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001110 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001111 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001112 } else {
1113 // use the result as returned
1114 cb.onCellInfo((List<CellInfo>) ar.result);
1115 }
1116 } catch (RemoteException re) {
1117 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1118 }
1119 break;
1120 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001121 request = (MainThreadRequest) msg.obj;
1122 WorkSource ws = (WorkSource) request.argument;
1123 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001124 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001125 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001126 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001127 ar = (AsyncResult) msg.obj;
1128 request = (MainThreadRequest) ar.userObj;
1129 if (ar.exception == null) {
1130 request.result = ar.result;
1131 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001132 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001133 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001134 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001135 }
1136
1137 synchronized (request) {
1138 request.notifyAll();
1139 }
1140 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001141 case CMD_MODEM_REBOOT:
1142 request = (MainThreadRequest) msg.obj;
1143 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001144 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001145 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001146 case EVENT_CMD_MODEM_REBOOT_DONE:
1147 handleNullReturnEvent(msg, "rebootModem");
1148 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001149 case CMD_REQUEST_ENABLE_MODEM:
1150 request = (MainThreadRequest) msg.obj;
1151 boolean enable = (boolean) request.argument;
1152 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001153 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001154 PhoneConfigurationManager.getInstance()
1155 .enablePhone(request.phone, enable, onCompleted);
1156 break;
1157 case EVENT_ENABLE_MODEM_DONE:
1158 ar = (AsyncResult) msg.obj;
1159 request = (MainThreadRequest) ar.userObj;
1160 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001161 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001162 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001163 if ((boolean) request.result) {
1164 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1165 updateModemStateMetrics();
1166 } else {
1167 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1168 + ar.exception);
1169 }
1170 notifyRequester(request);
1171 break;
1172 case CMD_GET_MODEM_STATUS:
1173 request = (MainThreadRequest) msg.obj;
1174 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1175 PhoneConfigurationManager.getInstance()
1176 .getPhoneStatusFromModem(request.phone, onCompleted);
1177 break;
1178 case EVENT_GET_MODEM_STATUS_DONE:
1179 ar = (AsyncResult) msg.obj;
1180 request = (MainThreadRequest) ar.userObj;
1181 int id = request.phone.getPhoneId();
1182 if (ar.exception == null && ar.result != null) {
1183 request.result = ar.result;
1184 //update the cache as modem status has changed
1185 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1186 (boolean) request.result);
1187 } else {
1188 // Return true if modem status cannot be retrieved. For most cases,
1189 // modem status is on. And for older version modems, GET_MODEM_STATUS
1190 // and disable modem are not supported. Modem is always on.
1191 // TODO: this should be fixed in R to support a third
1192 // status UNKNOWN b/131631629
1193 request.result = true;
1194 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1195 + ar.exception);
1196 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001197 notifyRequester(request);
1198 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001199 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1200 request = (MainThreadRequest) msg.obj;
1201 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1202 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1203 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1204 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1205 break;
1206 }
1207 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1208 ar = (AsyncResult) msg.obj;
1209 request = (MainThreadRequest) ar.userObj;
1210 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1211 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1212 args.second.accept(ar.exception == null);
1213 notifyRequester(request);
1214 break;
1215 }
yincheng zhao2737e882019-09-06 17:06:54 -07001216 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1217 ar = (AsyncResult) msg.obj;
1218 request = (MainThreadRequest) ar.userObj;
1219 if (ar.exception == null && ar.result != null) {
1220 request.result = ar.result;
1221 } else {
1222 request.result = -1;
1223 loge("Failed to set Forbidden Plmns");
1224 if (ar.result == null) {
1225 loge("setForbidenPlmns: Empty response");
1226 } else if (ar.exception != null) {
1227 loge("setForbiddenPlmns: Exception: " + ar.exception);
1228 request.result = -1;
1229 } else {
1230 loge("setForbiddenPlmns: Unknown exception");
1231 }
1232 }
1233 notifyRequester(request);
1234 break;
1235 case CMD_SET_FORBIDDEN_PLMNS:
1236 request = (MainThreadRequest) msg.obj;
1237 uiccCard = getUiccCardFromRequest(request);
1238 if (uiccCard == null) {
1239 loge("setForbiddenPlmns: UiccCard is null");
1240 request.result = -1;
1241 notifyRequester(request);
1242 break;
1243 }
1244 Pair<Integer, List<String>> setFplmnsArgs =
1245 (Pair<Integer, List<String>>) request.argument;
1246 appType = setFplmnsArgs.first;
1247 List<String> fplmns = setFplmnsArgs.second;
1248 uiccApp = uiccCard.getApplicationByType(appType);
1249 if (uiccApp == null) {
1250 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1251 request.result = -1;
1252 loge("Failed to get UICC App");
1253 notifyRequester(request);
1254 } else {
1255 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1256 ((SIMRecords) uiccApp.getIccRecords())
1257 .setForbiddenPlmns(onCompleted, fplmns);
1258 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001259 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001260 case CMD_ERASE_MODEM_CONFIG:
1261 request = (MainThreadRequest) msg.obj;
1262 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1263 defaultPhone.eraseModemConfig(onCompleted);
1264 break;
1265 case EVENT_ERASE_MODEM_CONFIG_DONE:
1266 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001267 break;
zoey chene02881a2019-12-30 16:11:23 +08001268
1269 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1270 request = (MainThreadRequest) msg.obj;
1271 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1272 Pair<String, String> changed = (Pair<String, String>) request.argument;
1273 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1274 changed.first, changed.second, onCompleted);
1275 break;
1276 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1277 ar = (AsyncResult) msg.obj;
1278 request = (MainThreadRequest) ar.userObj;
1279 if (ar.exception == null) {
1280 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1281 } else {
1282 request.result = msg.arg1;
1283 }
1284 notifyRequester(request);
1285 break;
1286
1287 case CMD_SET_ICC_LOCK_ENABLED:
1288 request = (MainThreadRequest) msg.obj;
1289 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1290 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1291 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1292 enabled.first, enabled.second, onCompleted);
1293 break;
1294 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1295 ar = (AsyncResult) msg.obj;
1296 request = (MainThreadRequest) ar.userObj;
1297 if (ar.exception == null) {
1298 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1299 } else {
1300 request.result = msg.arg1;
1301 }
1302 notifyRequester(request);
1303 break;
1304
Peter Wangdafb9ac2020-01-15 14:13:38 -08001305 case MSG_NOTIFY_USER_ACTIVITY:
1306 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
1307 Intent intent = new Intent(ACTION_USER_ACTIVITY_NOTIFICATION);
1308 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1309 getDefaultPhone().getContext().sendBroadcastAsUser(
1310 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1311 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001312 default:
1313 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1314 break;
1315 }
1316 }
Jake Hambye994d462014-02-03 13:10:13 -08001317
Pengquan Menga1bb6272018-09-06 09:59:22 -07001318 private void notifyRequester(MainThreadRequest request) {
1319 synchronized (request) {
1320 request.notifyAll();
1321 }
1322 }
1323
Jake Hambye994d462014-02-03 13:10:13 -08001324 private void handleNullReturnEvent(Message msg, String command) {
1325 AsyncResult ar = (AsyncResult) msg.obj;
1326 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1327 if (ar.exception == null) {
1328 request.result = true;
1329 } else {
1330 request.result = false;
1331 if (ar.exception instanceof CommandException) {
1332 loge(command + ": CommandException: " + ar.exception);
1333 } else {
1334 loge(command + ": Unknown exception");
1335 }
1336 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001337 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001338 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001339 }
1340
1341 /**
1342 * Posts the specified command to be executed on the main thread,
1343 * waits for the request to complete, and returns the result.
1344 * @see #sendRequestAsync
1345 */
1346 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001347 return sendRequest(
1348 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001349 }
1350
1351 /**
1352 * Posts the specified command to be executed on the main thread,
1353 * waits for the request to complete, and returns the result.
1354 * @see #sendRequestAsync
1355 */
1356 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1357 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001358 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001359 }
1360
1361 /**
1362 * Posts the specified command to be executed on the main thread,
1363 * waits for the request to complete, and returns the result.
1364 * @see #sendRequestAsync
1365 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001366 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001367 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001368 }
1369
1370 /**
1371 * Posts the specified command to be executed on the main thread,
1372 * waits for the request to complete, and returns the result.
1373 * @see #sendRequestAsync
1374 */
Nathan Harold92bed182018-10-12 18:16:49 -07001375 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1376 return sendRequest(command, argument, subId, null, workSource);
1377 }
1378
1379 /**
1380 * Posts the specified command to be executed on the main thread,
1381 * waits for the request to complete, and returns the result.
1382 * @see #sendRequestAsync
1383 */
1384 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1385 return sendRequest(
1386 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1387 }
1388
1389 /**
1390 * Posts the specified command to be executed on the main thread,
1391 * waits for the request to complete, and returns the result.
1392 * @see #sendRequestAsync
1393 */
1394 private Object sendRequest(
1395 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001396 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1397 throw new RuntimeException("This method will deadlock if called from the main thread.");
1398 }
1399
Nathan Harold92bed182018-10-12 18:16:49 -07001400 MainThreadRequest request = null;
1401 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1402 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1403 } else if (phone != null) {
1404 request = new MainThreadRequest(argument, phone, workSource);
1405 } else {
1406 request = new MainThreadRequest(argument, subId, workSource);
1407 }
1408
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001409 Message msg = mMainThreadHandler.obtainMessage(command, request);
1410 msg.sendToTarget();
1411
1412 // Wait for the request to complete
1413 synchronized (request) {
1414 while (request.result == null) {
1415 try {
1416 request.wait();
1417 } catch (InterruptedException e) {
1418 // Do nothing, go back and wait until the request is complete
1419 }
1420 }
1421 }
1422 return request.result;
1423 }
1424
1425 /**
1426 * Asynchronous ("fire and forget") version of sendRequest():
1427 * Posts the specified command to be executed on the main thread, and
1428 * returns immediately.
1429 * @see #sendRequest
1430 */
1431 private void sendRequestAsync(int command) {
1432 mMainThreadHandler.sendEmptyMessage(command);
1433 }
1434
1435 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001436 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001437 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001438 */
1439 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001440 sendRequestAsync(command, argument, null, null);
1441 }
1442
1443 /**
1444 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1445 * @see {@link #sendRequest(int,Object)}
1446 */
1447 private void sendRequestAsync(
1448 int command, Object argument, Phone phone, WorkSource workSource) {
1449 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001450 Message msg = mMainThreadHandler.obtainMessage(command, request);
1451 msg.sendToTarget();
1452 }
1453
1454 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001455 * Initialize the singleton PhoneInterfaceManager instance.
1456 * This is only done once, at startup, from PhoneApp.onCreate().
1457 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001458 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459 synchronized (PhoneInterfaceManager.class) {
1460 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001461 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001462 } else {
1463 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1464 }
1465 return sInstance;
1466 }
1467 }
1468
1469 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001470 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001471 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001472 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001473 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001474 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001475 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1476 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001477 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001478 mTelephonySharedPreferences =
1479 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001480 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001481 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001482
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001483 publish();
1484 }
1485
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001486 private Phone getDefaultPhone() {
1487 Phone thePhone = getPhone(getDefaultSubscription());
1488 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1489 }
1490
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001491 private void publish() {
1492 if (DBG) log("publish: " + this);
1493
Peter Wangc035ce42020-01-08 21:00:22 -08001494 TelephonyFrameworkInitializer
1495 .getTelephonyServiceManager()
1496 .getTelephonyServiceRegisterer()
1497 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001498 }
1499
Stuart Scott584921c2015-01-15 17:10:34 -08001500 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001501 if (request.phone != null) {
1502 return request.phone;
1503 } else {
1504 return getPhoneFromSubId(request.subId);
1505 }
1506 }
1507
1508 private Phone getPhoneFromSubId(int subId) {
1509 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1510 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001511 }
1512
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001513 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1514 Phone phone = getPhoneFromRequest(request);
1515 return phone == null ? null :
1516 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1517 }
1518
Wink Saville36469e72014-06-11 15:17:00 -07001519 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001520 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001521 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001522 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001523
Naina Nallurid63128d2019-09-17 14:10:30 -07001524 private void sendEraseModemConfig(Phone phone) {
1525 if (phone != null) {
1526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1527 mApp, phone.getSubId(), "eraseModemConfig");
1528 final long identity = Binder.clearCallingIdentity();
1529 try {
1530 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1531 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1532 } finally {
1533 Binder.restoreCallingIdentity(identity);
1534 }
1535 }
1536 }
1537
Peter Wang44b186e2020-01-13 23:33:09 -08001538 private boolean isImsAvailableOnDevice() {
1539 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1540 if (pm == null) {
1541 // For some reason package manger is not available.. This will fail internally anyway,
1542 // so do not throw error and allow.
1543 return true;
1544 }
1545 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1546 }
1547
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001548 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001549 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001550 }
1551
Wink Savilleb564aae2014-10-23 10:18:09 -07001552 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001553 if (DBG) log("dial: " + number);
1554 // No permission check needed here: This is just a wrapper around the
1555 // ACTION_DIAL intent, which is available to any app since it puts up
1556 // the UI before it does anything.
1557
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001558 final long identity = Binder.clearCallingIdentity();
1559 try {
1560 String url = createTelUrl(number);
1561 if (url == null) {
1562 return;
1563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001564
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001565 // PENDING: should we just silently fail if phone is offhook or ringing?
1566 PhoneConstants.State state = mCM.getState(subId);
1567 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1568 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1569 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1570 mApp.startActivity(intent);
1571 }
1572 } finally {
1573 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001574 }
1575 }
1576
1577 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001578 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001579 }
1580
Wink Savilleb564aae2014-10-23 10:18:09 -07001581 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001582 if (DBG) log("call: " + number);
1583
1584 // This is just a wrapper around the ACTION_CALL intent, but we still
1585 // need to do a permission check since we're calling startActivity()
1586 // from the context of the phone app.
1587 enforceCallPermission();
1588
Jordan Liu1617b712019-07-10 15:06:26 -07001589 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001590 != AppOpsManager.MODE_ALLOWED) {
1591 return;
1592 }
1593
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001594 final long identity = Binder.clearCallingIdentity();
1595 try {
1596 String url = createTelUrl(number);
1597 if (url == null) {
1598 return;
1599 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001600
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001601 boolean isValid = false;
1602 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1603 if (slist != null) {
1604 for (SubscriptionInfo subInfoRecord : slist) {
1605 if (subInfoRecord.getSubscriptionId() == subId) {
1606 isValid = true;
1607 break;
1608 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001609 }
Wink Saville08874612014-08-31 19:19:58 -07001610 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001611 if (!isValid) {
1612 return;
1613 }
Wink Saville08874612014-08-31 19:19:58 -07001614
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001615 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1616 intent.putExtra(SUBSCRIPTION_KEY, subId);
1617 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1618 mApp.startActivity(intent);
1619 } finally {
1620 Binder.restoreCallingIdentity(identity);
1621 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001622 }
1623
Wink Savilleb564aae2014-10-23 10:18:09 -07001624 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001625 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001626 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1627 }
1628
Wink Savilleb564aae2014-10-23 10:18:09 -07001629 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001630 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001631 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1632 }
1633
Wink Savilleb564aae2014-10-23 10:18:09 -07001634 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001635 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001636
1637 final long identity = Binder.clearCallingIdentity();
1638 try {
1639 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1640 checkSimPin.start();
1641 return checkSimPin.unlockSim(null, pin);
1642 } finally {
1643 Binder.restoreCallingIdentity(identity);
1644 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001645 }
1646
Wink Savilleb564aae2014-10-23 10:18:09 -07001647 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001648 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001649
1650 final long identity = Binder.clearCallingIdentity();
1651 try {
1652 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1653 checkSimPuk.start();
1654 return checkSimPuk.unlockSim(puk, pin);
1655 } finally {
1656 Binder.restoreCallingIdentity(identity);
1657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 }
1659
1660 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001661 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001662 * a synchronous one.
1663 */
1664 private static class UnlockSim extends Thread {
1665
1666 private final IccCard mSimCard;
1667
1668 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001669 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1670 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671
1672 // For replies from SimCard interface
1673 private Handler mHandler;
1674
1675 // For async handler to identify request type
1676 private static final int SUPPLY_PIN_COMPLETE = 100;
1677
1678 public UnlockSim(IccCard simCard) {
1679 mSimCard = simCard;
1680 }
1681
1682 @Override
1683 public void run() {
1684 Looper.prepare();
1685 synchronized (UnlockSim.this) {
1686 mHandler = new Handler() {
1687 @Override
1688 public void handleMessage(Message msg) {
1689 AsyncResult ar = (AsyncResult) msg.obj;
1690 switch (msg.what) {
1691 case SUPPLY_PIN_COMPLETE:
1692 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1693 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001694 mRetryCount = msg.arg1;
1695 if (ar.exception != null) {
1696 if (ar.exception instanceof CommandException &&
1697 ((CommandException)(ar.exception)).getCommandError()
1698 == CommandException.Error.PASSWORD_INCORRECT) {
1699 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1700 } else {
1701 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1702 }
1703 } else {
1704 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1705 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001706 mDone = true;
1707 UnlockSim.this.notifyAll();
1708 }
1709 break;
1710 }
1711 }
1712 };
1713 UnlockSim.this.notifyAll();
1714 }
1715 Looper.loop();
1716 }
1717
1718 /*
1719 * Use PIN or PUK to unlock SIM card
1720 *
1721 * If PUK is null, unlock SIM card with PIN
1722 *
1723 * If PUK is not null, unlock SIM card with PUK and set PIN code
1724 */
Wink Saville9de0f752013-10-22 19:04:03 -07001725 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001726
1727 while (mHandler == null) {
1728 try {
1729 wait();
1730 } catch (InterruptedException e) {
1731 Thread.currentThread().interrupt();
1732 }
1733 }
1734 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1735
1736 if (puk == null) {
1737 mSimCard.supplyPin(pin, callback);
1738 } else {
1739 mSimCard.supplyPuk(puk, pin, callback);
1740 }
1741
1742 while (!mDone) {
1743 try {
1744 Log.d(LOG_TAG, "wait for done");
1745 wait();
1746 } catch (InterruptedException e) {
1747 // Restore the interrupted status
1748 Thread.currentThread().interrupt();
1749 }
1750 }
1751 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001752 int[] resultArray = new int[2];
1753 resultArray[0] = mResult;
1754 resultArray[1] = mRetryCount;
1755 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 }
1757 }
1758
1759 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001760 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001761
1762 }
1763
Wink Savilleb564aae2014-10-23 10:18:09 -07001764 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001765 // No permission check needed here: this call is harmless, and it's
1766 // needed for the ServiceState.requestStateUpdate() call (which is
1767 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001768 final long identity = Binder.clearCallingIdentity();
1769 try {
1770 final Phone phone = getPhone(subId);
1771 if (phone != null) {
1772 phone.updateServiceLocation();
1773 }
1774 } finally {
1775 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001777 }
1778
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001779 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001780 @Override
1781 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001782 return isRadioOnWithFeature(callingPackage, null);
1783 }
1784
1785
1786 @Override
1787 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1788 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1789 callingFeatureId);
1790 }
1791
1792 @Deprecated
1793 @Override
1794 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1795 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001796 }
1797
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001798 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001799 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1800 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001801 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001802 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001803 return false;
1804 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001805
1806 final long identity = Binder.clearCallingIdentity();
1807 try {
1808 return isRadioOnForSubscriber(subId);
1809 } finally {
1810 Binder.restoreCallingIdentity(identity);
1811 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001812 }
1813
1814 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001815 final long identity = Binder.clearCallingIdentity();
1816 try {
1817 final Phone phone = getPhone(subId);
1818 if (phone != null) {
1819 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1820 } else {
1821 return false;
1822 }
1823 } finally {
1824 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001825 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001826 }
1827
1828 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001829 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001830 }
Wink Saville36469e72014-06-11 15:17:00 -07001831
Wink Savilleb564aae2014-10-23 10:18:09 -07001832 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001833 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001834
1835 final long identity = Binder.clearCallingIdentity();
1836 try {
1837 final Phone phone = getPhone(subId);
1838 if (phone != null) {
1839 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1840 }
1841 } finally {
1842 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001843 }
Wink Saville36469e72014-06-11 15:17:00 -07001844 }
1845
1846 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001847 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001848 }
1849
Wink Savilleb564aae2014-10-23 10:18:09 -07001850 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001851 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001852
1853 final long identity = Binder.clearCallingIdentity();
1854 try {
1855 final Phone phone = getPhone(subId);
1856 if (phone == null) {
1857 return false;
1858 }
1859 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1860 toggleRadioOnOffForSubscriber(subId);
1861 }
1862 return true;
1863 } finally {
1864 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001865 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001866 }
Wink Saville36469e72014-06-11 15:17:00 -07001867
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001868 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08001869 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001870 /*
1871 * If any of the Radios are available, it will need to be
1872 * shutdown. So return true if any Radio is available.
1873 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001874 final long identity = Binder.clearCallingIdentity();
1875 try {
1876 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1877 Phone phone = PhoneFactory.getPhone(i);
1878 if (phone != null && phone.isRadioAvailable()) return true;
1879 }
1880 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1881 return false;
1882 } finally {
1883 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001884 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001885 }
1886
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001887 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001888 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001889 enforceModifyPermission();
1890
1891 final long identity = Binder.clearCallingIdentity();
1892 try {
1893 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1894 logv("Shutting down Phone " + i);
1895 shutdownRadioUsingPhoneId(i);
1896 }
1897 } finally {
1898 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001899 }
1900 }
1901
1902 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001903 Phone phone = PhoneFactory.getPhone(phoneId);
1904 if (phone != null && phone.isRadioAvailable()) {
1905 phone.shutdownRadio();
1906 }
1907 }
1908
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001909 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001910 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001911
1912 final long identity = Binder.clearCallingIdentity();
1913 try {
1914 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1915 if (defaultPhone != null) {
1916 defaultPhone.setRadioPower(turnOn);
1917 return true;
1918 } else {
1919 loge("There's no default phone.");
1920 return false;
1921 }
1922 } finally {
1923 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001924 }
Wink Saville36469e72014-06-11 15:17:00 -07001925 }
1926
Wink Savilleb564aae2014-10-23 10:18:09 -07001927 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001928 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001929
1930 final long identity = Binder.clearCallingIdentity();
1931 try {
1932 final Phone phone = getPhone(subId);
1933 if (phone != null) {
1934 phone.setRadioPower(turnOn);
1935 return true;
1936 } else {
1937 return false;
1938 }
1939 } finally {
1940 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001941 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 }
1943
Wink Saville36469e72014-06-11 15:17:00 -07001944 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001945 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946 public boolean enableDataConnectivity() {
1947 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001948
1949 final long identity = Binder.clearCallingIdentity();
1950 try {
1951 int subId = mSubscriptionController.getDefaultDataSubId();
1952 final Phone phone = getPhone(subId);
1953 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001954 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001955 return true;
1956 } else {
1957 return false;
1958 }
1959 } finally {
1960 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001961 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001962 }
1963
Wink Saville36469e72014-06-11 15:17:00 -07001964 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001965 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001966 public boolean disableDataConnectivity() {
1967 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001968
1969 final long identity = Binder.clearCallingIdentity();
1970 try {
1971 int subId = mSubscriptionController.getDefaultDataSubId();
1972 final Phone phone = getPhone(subId);
1973 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001974 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001975 return true;
1976 } else {
1977 return false;
1978 }
1979 } finally {
1980 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001981 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001982 }
1983
Sanket Padawe356d7632015-06-22 14:03:32 -07001984 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001985 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001986 final long identity = Binder.clearCallingIdentity();
1987 try {
1988 final Phone phone = getPhone(subId);
1989 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001990 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001991 } else {
1992 return false;
1993 }
1994 } finally {
1995 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001996 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001997 }
1998
1999 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002000 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002001 }
2002
pkanwarae03a6b2016-11-06 20:37:09 -08002003 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002004 enforceCallPermission();
2005
2006 final long identity = Binder.clearCallingIdentity();
2007 try {
2008 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2009 return;
2010 }
2011 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2012 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2013 } finally {
2014 Binder.restoreCallingIdentity(identity);
2015 }
pkanwar32d516d2016-10-14 19:37:38 -07002016 };
2017
Wink Savilleb564aae2014-10-23 10:18:09 -07002018 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002019 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002020
2021 final long identity = Binder.clearCallingIdentity();
2022 try {
2023 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2024 return false;
2025 }
2026 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2027 } finally {
2028 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002029 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002030 }
2031
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002032 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002033 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002034 }
2035
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002036 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002037 final long identity = Binder.clearCallingIdentity();
2038 try {
2039 Phone phone = PhoneFactory.getPhone(slotIndex);
2040 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2041 PhoneConstantConversions.convertCallState(phone.getState());
2042 } finally {
2043 Binder.restoreCallingIdentity(identity);
2044 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002045 }
2046
Sanket Padawe356d7632015-06-22 14:03:32 -07002047 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002048 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002049 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2050 }
2051
2052 @Override
2053 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002054 final long identity = Binder.clearCallingIdentity();
2055 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002056 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002057 if (phone != null) {
2058 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2059 } else {
2060 return PhoneConstantConversions.convertDataState(
2061 PhoneConstants.DataState.DISCONNECTED);
2062 }
2063 } finally {
2064 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002065 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002066 }
2067
Sanket Padawe356d7632015-06-22 14:03:32 -07002068 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002069 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002070 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2071 }
2072
2073 @Override
2074 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002075 final long identity = Binder.clearCallingIdentity();
2076 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002077 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002078 if (phone != null) {
2079 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2080 } else {
2081 return TelephonyManager.DATA_ACTIVITY_NONE;
2082 }
2083 } finally {
2084 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002085 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002086 }
2087
2088 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002089 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002090 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002091 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002092
2093 LocationAccessPolicy.LocationPermissionResult locationResult =
2094 LocationAccessPolicy.checkLocationPermission(mApp,
2095 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2096 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002097 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002098 .setCallingPid(Binder.getCallingPid())
2099 .setCallingUid(Binder.getCallingUid())
2100 .setMethod("getCellLocation")
2101 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2102 .build());
2103 switch (locationResult) {
2104 case DENIED_HARD:
2105 throw new SecurityException("Not allowed to access cell location");
2106 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002107 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2108 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002109 }
2110
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002111 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002112 final long identity = Binder.clearCallingIdentity();
2113 try {
2114 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002115 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002116 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002117 } finally {
2118 Binder.restoreCallingIdentity(identity);
2119 }
Svetoslav64fad262015-04-14 14:35:21 -07002120 }
2121
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002122 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002123 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2124 String callingFeatureId) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002125 if (!TextUtils.isEmpty(callingPackage)) {
2126 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002127 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2128 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002129 return "";
2130 }
2131 }
2132
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002133 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2134 // registered cell info, so return a NULL country instead.
2135 final long identity = Binder.clearCallingIdentity();
2136 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002137 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2138 // Get default phone in this case.
2139 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2140 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002141 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002142 // Todo: fix this when we can get the actual cellular network info when the device
2143 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002144 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002145 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2146 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002147 return "";
2148 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002149 Phone phone = PhoneFactory.getPhone(phoneId);
2150 if (phone != null) {
2151 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002152 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002153 if (sst != null) {
2154 LocaleTracker lt = sst.getLocaleTracker();
2155 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002156 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2157 return lt.getCurrentCountry();
2158 } else if (emergencyNumberTracker != null) {
2159 return emergencyNumberTracker.getEmergencyCountryIso();
2160 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002161 }
2162 }
2163 }
2164 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002165 } finally {
2166 Binder.restoreCallingIdentity(identity);
2167 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002168 }
2169
2170 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002171 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002172 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002173 }
2174
Sanket Padawe356d7632015-06-22 14:03:32 -07002175 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002176 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002177 mApp.enforceCallingOrSelfPermission(
2178 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002179
2180 final long identity = Binder.clearCallingIdentity();
2181 try {
2182 final Phone phone = getPhone(subId);
2183 if (phone != null) {
2184 phone.enableLocationUpdates();
2185 }
2186 } finally {
2187 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002188 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002189 }
2190
2191 @Override
2192 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002193 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002194 }
2195
Sanket Padawe356d7632015-06-22 14:03:32 -07002196 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002197 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002198 mApp.enforceCallingOrSelfPermission(
2199 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002200
2201 final long identity = Binder.clearCallingIdentity();
2202 try {
2203 final Phone phone = getPhone(subId);
2204 if (phone != null) {
2205 phone.disableLocationUpdates();
2206 }
2207 } finally {
2208 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002209 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 }
2211
Nathan Harold31d7ff32018-10-15 20:20:30 -07002212 /**
2213 * Returns the target SDK version number for a given package name.
2214 *
Nathan Haroldec184742019-07-10 17:04:16 -07002215 * This call MUST be invoked before clearing the calling UID.
2216 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002217 * @return target SDK if the package is found or INT_MAX.
2218 */
2219 private int getTargetSdk(String packageName) {
2220 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002221 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002222 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002223 if (ai != null) return ai.targetSdkVersion;
2224 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002225 loge("Failed to get package info for pkg="
2226 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002227 }
2228 return Integer.MAX_VALUE;
2229 }
2230
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002231 @Override
2232 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002233 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2234 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002235 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002236 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2237 throw new SecurityException(
2238 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2239 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002240
Jordan Liu1617b712019-07-10 15:06:26 -07002241 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2243 return null;
2244 }
Svetoslav64fad262015-04-14 14:35:21 -07002245
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002246 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002247
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002248 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002249 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002250
Nathan Haroldf180aac2018-06-01 18:43:55 -07002251 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2252 for (CellInfo ci : info) {
2253 if (ci instanceof CellInfoGsm) {
2254 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2255 } else if (ci instanceof CellInfoWcdma) {
2256 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002259 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002260 }
2261
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002262 private List<CellInfo> getCachedCellInfo() {
2263 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2264 for (Phone phone : PhoneFactory.getPhones()) {
2265 List<CellInfo> info = phone.getAllCellInfo();
2266 if (info != null) cellInfos.addAll(info);
2267 }
2268 return cellInfos;
2269 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270
2271 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002272 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002273 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002274 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002275
2276 LocationAccessPolicy.LocationPermissionResult locationResult =
2277 LocationAccessPolicy.checkLocationPermission(mApp,
2278 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2279 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002280 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002281 .setCallingPid(Binder.getCallingPid())
2282 .setCallingUid(Binder.getCallingUid())
2283 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002284 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002285 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2286 .build());
2287 switch (locationResult) {
2288 case DENIED_HARD:
2289 throw new SecurityException("Not allowed to access cell info");
2290 case DENIED_SOFT:
2291 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002292 }
2293
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002294 final int targetSdk = getTargetSdk(callingPackage);
2295 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2296 return getCachedCellInfo();
2297 }
2298
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002299 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002300 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002301 final long identity = Binder.clearCallingIdentity();
2302 try {
2303 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2304 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002305 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002306 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002307 if (info != null) cellInfos.addAll(info);
2308 }
2309 return cellInfos;
2310 } finally {
2311 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 }
2313 }
2314
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002315 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002316 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2317 String callingFeatureId) {
2318 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2319 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002320 }
2321
2322 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002323 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2324 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002325 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002326 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002327 }
2328
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002329 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2330 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002331 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002332 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002333
2334 LocationAccessPolicy.LocationPermissionResult locationResult =
2335 LocationAccessPolicy.checkLocationPermission(mApp,
2336 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2337 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002338 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002339 .setCallingPid(Binder.getCallingPid())
2340 .setCallingUid(Binder.getCallingUid())
2341 .setMethod("requestCellInfoUpdate")
2342 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2343 .build());
2344 switch (locationResult) {
2345 case DENIED_HARD:
2346 throw new SecurityException("Not allowed to access cell info");
2347 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002348 try {
2349 cb.onCellInfo(new ArrayList<CellInfo>());
2350 } catch (RemoteException re) {
2351 // Drop without consequences
2352 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002353 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002354 }
2355
Nathan Harolda939a962019-05-09 10:13:47 -07002356
2357 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002358 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2359
2360 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2361 }
2362
2363 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002365 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002366 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002367
2368 final long identity = Binder.clearCallingIdentity();
2369 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002370 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002371 } finally {
2372 Binder.restoreCallingIdentity(identity);
2373 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002374 }
2375
Shishir Agrawala9f32182016-04-12 12:00:16 -07002376 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002377 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002378 Phone phone = PhoneFactory.getPhone(slotIndex);
2379 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002380 return null;
2381 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002382 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002383 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002384 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002385 return null;
2386 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002387
2388 final long identity = Binder.clearCallingIdentity();
2389 try {
2390 return phone.getImei();
2391 } finally {
2392 Binder.restoreCallingIdentity(identity);
2393 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002394 }
2395
2396 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002397 public String getTypeAllocationCodeForSlot(int slotIndex) {
2398 Phone phone = PhoneFactory.getPhone(slotIndex);
2399 String tac = null;
2400 if (phone != null) {
2401 String imei = phone.getImei();
2402 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2403 }
2404 return tac;
2405 }
2406
2407 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002408 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002409 Phone phone = PhoneFactory.getPhone(slotIndex);
2410 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002411 return null;
2412 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002413
Jeff Davidson913390f2018-02-23 17:11:49 -08002414 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002415 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002416 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002417 return null;
2418 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002419
2420 final long identity = Binder.clearCallingIdentity();
2421 try {
2422 return phone.getMeid();
2423 } finally {
2424 Binder.restoreCallingIdentity(identity);
2425 }
Jack Yu2af8d712017-03-15 17:14:14 -07002426 }
2427
2428 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002429 public String getManufacturerCodeForSlot(int slotIndex) {
2430 Phone phone = PhoneFactory.getPhone(slotIndex);
2431 String manufacturerCode = null;
2432 if (phone != null) {
2433 String meid = phone.getMeid();
2434 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2435 }
2436 return manufacturerCode;
2437 }
2438
2439 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002440 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2441 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002442 Phone phone = PhoneFactory.getPhone(slotIndex);
2443 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002444 return null;
2445 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002446 int subId = phone.getSubId();
2447 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002448 mApp, subId, callingPackage, callingFeatureId,
2449 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002450 return null;
2451 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002452
2453 final long identity = Binder.clearCallingIdentity();
2454 try {
2455 return phone.getDeviceSvn();
2456 } finally {
2457 Binder.restoreCallingIdentity(identity);
2458 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002459 }
2460
fionaxu43304da2017-11-27 22:51:16 -08002461 @Override
2462 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002463 final long identity = Binder.clearCallingIdentity();
2464 try {
2465 final Phone phone = getPhone(subId);
2466 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2467 } finally {
2468 Binder.restoreCallingIdentity(identity);
2469 }
fionaxu43304da2017-11-27 22:51:16 -08002470 }
2471
2472 @Override
2473 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002474 final long identity = Binder.clearCallingIdentity();
2475 try {
2476 final Phone phone = getPhone(subId);
2477 return phone == null ? null : phone.getCarrierName();
2478 } finally {
2479 Binder.restoreCallingIdentity(identity);
2480 }
fionaxu43304da2017-11-27 22:51:16 -08002481 }
2482
calvinpanffe225e2018-11-01 19:43:06 +08002483 @Override
chen xu0026ca62019-03-06 15:28:50 -08002484 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002485 final long identity = Binder.clearCallingIdentity();
2486 try {
2487 final Phone phone = getPhone(subId);
2488 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002489 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002490 } finally {
2491 Binder.restoreCallingIdentity(identity);
2492 }
2493 }
2494
2495 @Override
chen xu0026ca62019-03-06 15:28:50 -08002496 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002497 final long identity = Binder.clearCallingIdentity();
2498 try {
2499 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002500 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002501 } finally {
2502 Binder.restoreCallingIdentity(identity);
2503 }
2504 }
2505
chen xu651eec72018-11-11 19:03:44 -08002506 @Override
chen xu864e11c2018-12-06 22:10:03 -08002507 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2508 if (!isSubscriptionMccMnc) {
2509 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2510 }
chen xu651eec72018-11-11 19:03:44 -08002511 final Phone phone = PhoneFactory.getPhone(slotIndex);
2512 if (phone == null) {
2513 return TelephonyManager.UNKNOWN_CARRIER_ID;
2514 }
2515 final long identity = Binder.clearCallingIdentity();
2516 try {
2517 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2518 } finally {
2519 Binder.restoreCallingIdentity(identity);
2520 }
2521 }
2522
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002523 //
2524 // Internal helper methods.
2525 //
2526
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002527 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002528 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2529 *
2530 * @throws SecurityException if the caller does not have the required permission
2531 */
2532 private void enforceModifyPermission() {
2533 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2534 }
2535
Shuo Qiancd19c462020-01-16 20:51:11 -08002536 /**
2537 * Make sure the caller is system.
2538 *
2539 * @throws SecurityException if the caller is not system.
2540 */
2541 private void enforceSystemCaller() {
2542 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2543 throw new SecurityException("Caller must be system");
2544 }
2545 }
2546
Shuo Qian3b6ee772019-11-13 17:43:31 -08002547 private void enforceActiveEmergencySessionPermission() {
2548 mApp.enforceCallingOrSelfPermission(
2549 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2550 }
2551
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002552 /**
2553 * Make sure the caller has the CALL_PHONE permission.
2554 *
2555 * @throws SecurityException if the caller does not have the required permission
2556 */
2557 private void enforceCallPermission() {
2558 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2559 }
2560
paulhu5a773602019-08-23 19:17:33 +08002561 private void enforceSettingsPermission() {
2562 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002563 }
2564
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002565 private String createTelUrl(String number) {
2566 if (TextUtils.isEmpty(number)) {
2567 return null;
2568 }
2569
Jake Hambye994d462014-02-03 13:10:13 -08002570 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002571 }
2572
Ihab Awadf9e92732013-12-05 18:02:52 -08002573 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002574 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2575 }
2576
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002577 private static void logv(String msg) {
2578 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2579 }
2580
Ihab Awadf9e92732013-12-05 18:02:52 -08002581 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2583 }
2584
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002585 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002586 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002587 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002588 }
2589
Sanket Padawe356d7632015-06-22 14:03:32 -07002590 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002591 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002592 final long identity = Binder.clearCallingIdentity();
2593 try {
2594 final Phone phone = PhoneFactory.getPhone(slotIndex);
2595 if (phone == null) {
2596 return PhoneConstants.PHONE_TYPE_NONE;
2597 } else {
2598 return phone.getPhoneType();
2599 }
2600 } finally {
2601 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002602 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002603 }
2604
2605 /**
2606 * Returns the CDMA ERI icon index to display
2607 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002608 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002609 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2610 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2611 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002612 }
2613
Sanket Padawe356d7632015-06-22 14:03:32 -07002614 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002615 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2616 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002617 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002618 mApp, subId, callingPackage, callingFeatureId,
2619 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002620 return -1;
2621 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002622
2623 final long identity = Binder.clearCallingIdentity();
2624 try {
2625 final Phone phone = getPhone(subId);
2626 if (phone != null) {
2627 return phone.getCdmaEriIconIndex();
2628 } else {
2629 return -1;
2630 }
2631 } finally {
2632 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002633 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002634 }
2635
2636 /**
2637 * Returns the CDMA ERI icon mode,
2638 * 0 - ON
2639 * 1 - FLASHING
2640 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002641 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002642 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2643 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2644 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002645 }
2646
Sanket Padawe356d7632015-06-22 14:03:32 -07002647 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002648 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2649 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002650 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002651 mApp, subId, callingPackage, callingFeatureId,
2652 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002653 return -1;
2654 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655
2656 final long identity = Binder.clearCallingIdentity();
2657 try {
2658 final Phone phone = getPhone(subId);
2659 if (phone != null) {
2660 return phone.getCdmaEriIconMode();
2661 } else {
2662 return -1;
2663 }
2664 } finally {
2665 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002666 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002667 }
2668
2669 /**
2670 * Returns the CDMA ERI text,
2671 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002672 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002673 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2674 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2675 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002676 }
2677
Sanket Padawe356d7632015-06-22 14:03:32 -07002678 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002679 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2680 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002681 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002682 mApp, subId, callingPackage, callingFeatureId,
2683 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002684 return null;
2685 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686
2687 final long identity = Binder.clearCallingIdentity();
2688 try {
2689 final Phone phone = getPhone(subId);
2690 if (phone != null) {
2691 return phone.getCdmaEriText();
2692 } else {
2693 return null;
2694 }
2695 } finally {
2696 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002697 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002698 }
2699
2700 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002701 * Returns the CDMA MDN.
2702 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002703 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002704 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002705 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2706 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002707
2708 final long identity = Binder.clearCallingIdentity();
2709 try {
2710 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002711 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002712 return phone.getLine1Number();
2713 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002714 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002715 return null;
2716 }
2717 } finally {
2718 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002719 }
2720 }
2721
2722 /**
2723 * Returns the CDMA MIN.
2724 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002725 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002726 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002727 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2728 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002729
2730 final long identity = Binder.clearCallingIdentity();
2731 try {
2732 final Phone phone = getPhone(subId);
2733 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2734 return phone.getCdmaMin();
2735 } else {
2736 return null;
2737 }
2738 } finally {
2739 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002740 }
2741 }
2742
Hall Liud892bec2018-11-30 14:51:45 -08002743 @Override
2744 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2745 INumberVerificationCallback callback, String callingPackage) {
2746 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2747 != PERMISSION_GRANTED) {
2748 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2749 }
2750 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2751
2752 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2753 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2754 throw new SecurityException("Calling package must be configured in the device config");
2755 }
2756
2757 if (range == null) {
2758 throw new NullPointerException("Range must be non-null");
2759 }
2760
2761 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002762 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002763
2764 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2765 }
2766
Junda Liuca05d5d2014-08-14 22:36:34 -07002767 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002768 * Returns true if CDMA provisioning needs to run.
2769 */
2770 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002771 final long identity = Binder.clearCallingIdentity();
2772 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002773 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002774 } finally {
2775 Binder.restoreCallingIdentity(identity);
2776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002777 }
2778
2779 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002780 * Sets the voice mail number of a given subId.
2781 */
2782 @Override
2783 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002784 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2785 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786
2787 final long identity = Binder.clearCallingIdentity();
2788 try {
2789 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2790 new Pair<String, String>(alphaTag, number), new Integer(subId));
2791 return success;
2792 } finally {
2793 Binder.restoreCallingIdentity(identity);
2794 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002795 }
2796
Ta-wei Yen87c49842016-05-13 21:19:52 -07002797 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002798 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2799 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002800 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2801 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002802 if (!TextUtils.equals(callingPackage, systemDialer)) {
2803 throw new SecurityException("caller must be system dialer");
2804 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002805
2806 final long identity = Binder.clearCallingIdentity();
2807 try {
2808 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2809 if (phoneAccountHandle == null) {
2810 return null;
2811 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002812 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002813 } finally {
2814 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002815 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002816 }
2817
2818 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002819 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2820 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002821 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002822 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002823 mApp, subId, callingPackage, callingFeatureId,
2824 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002825 return null;
2826 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002827
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002828 final long identity = Binder.clearCallingIdentity();
2829 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002830 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002831 } finally {
2832 Binder.restoreCallingIdentity(identity);
2833 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002834 }
2835
2836 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002837 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2838 VisualVoicemailSmsFilterSettings settings) {
2839 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002840
2841 final long identity = Binder.clearCallingIdentity();
2842 try {
2843 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002844 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002845 } finally {
2846 Binder.restoreCallingIdentity(identity);
2847 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002848 }
2849
2850 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002851 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2852 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002853
2854 final long identity = Binder.clearCallingIdentity();
2855 try {
2856 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002857 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002858 } finally {
2859 Binder.restoreCallingIdentity(identity);
2860 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002861 }
2862
2863 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002864 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2865 String callingPackage, int subId) {
2866 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002867
2868 final long identity = Binder.clearCallingIdentity();
2869 try {
2870 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002871 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002872 } finally {
2873 Binder.restoreCallingIdentity(identity);
2874 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002875 }
2876
2877 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002878 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002879 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880
2881 final long identity = Binder.clearCallingIdentity();
2882 try {
2883 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002884 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002885 } finally {
2886 Binder.restoreCallingIdentity(identity);
2887 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002888 }
2889
2890 @Override
2891 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2892 String number, int port, String text, PendingIntent sentIntent) {
2893 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002894 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002895 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002896 SmsController smsController = PhoneFactory.getSmsController();
2897 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2898 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002899 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002900
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002901 /**
fionaxu0152e512016-11-14 13:36:14 -08002902 * Sets the voice activation state of a given subId.
2903 */
2904 @Override
2905 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002906 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2907 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002908
2909 final long identity = Binder.clearCallingIdentity();
2910 try {
2911 final Phone phone = getPhone(subId);
2912 if (phone != null) {
2913 phone.setVoiceActivationState(activationState);
2914 } else {
2915 loge("setVoiceActivationState fails with invalid subId: " + subId);
2916 }
2917 } finally {
2918 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002919 }
2920 }
2921
2922 /**
2923 * Sets the data activation state of a given subId.
2924 */
2925 @Override
2926 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002927 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2928 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002929
2930 final long identity = Binder.clearCallingIdentity();
2931 try {
2932 final Phone phone = getPhone(subId);
2933 if (phone != null) {
2934 phone.setDataActivationState(activationState);
2935 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002936 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002937 }
2938 } finally {
2939 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002940 }
2941 }
2942
2943 /**
2944 * Returns the voice activation state of a given subId.
2945 */
2946 @Override
2947 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002948 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002949
fionaxu0152e512016-11-14 13:36:14 -08002950 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951 final long identity = Binder.clearCallingIdentity();
2952 try {
2953 if (phone != null) {
2954 return phone.getVoiceActivationState();
2955 } else {
2956 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2957 }
2958 } finally {
2959 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002960 }
2961 }
2962
2963 /**
2964 * Returns the data activation state of a given subId.
2965 */
2966 @Override
2967 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002968 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002969
fionaxu0152e512016-11-14 13:36:14 -08002970 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002971 final long identity = Binder.clearCallingIdentity();
2972 try {
2973 if (phone != null) {
2974 return phone.getDataActivationState();
2975 } else {
2976 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2977 }
2978 } finally {
2979 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002980 }
2981 }
2982
2983 /**
Wink Saville36469e72014-06-11 15:17:00 -07002984 * Returns the unread count of voicemails for a subId
2985 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002986 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002987 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2988 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002989 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002990 mApp, subId, callingPackage, callingFeatureId,
2991 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002992 return 0;
2993 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002994 final long identity = Binder.clearCallingIdentity();
2995 try {
2996 final Phone phone = getPhone(subId);
2997 if (phone != null) {
2998 return phone.getVoiceMessageCount();
2999 } else {
3000 return 0;
3001 }
3002 } finally {
3003 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003004 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003005 }
3006
3007 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003008 * returns true, if the device is in a state where both voice and data
3009 * are supported simultaneously. This can change based on location or network condition.
3010 */
3011 @Override
3012 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003013 final long identity = Binder.clearCallingIdentity();
3014 try {
3015 final Phone phone = getPhone(subId);
3016 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3017 } finally {
3018 Binder.restoreCallingIdentity(identity);
3019 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003020 }
3021
3022 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003023 * Send the dialer code if called from the current default dialer or the caller has
3024 * carrier privilege.
3025 * @param inputCode The dialer code to send
3026 */
3027 @Override
3028 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003029 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003030 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003031 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3032 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003033 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003034 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003035 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003036 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003037
3038 final long identity = Binder.clearCallingIdentity();
3039 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003040 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003041 } finally {
3042 Binder.restoreCallingIdentity(identity);
3043 }
fionaxu235cc5e2017-03-06 22:25:57 -08003044 }
3045
Pengquan Menga1bb6272018-09-06 09:59:22 -07003046 @Override
3047 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003048 TelephonyPermissions
3049 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3050 mApp, subId, "getNetworkSelectionMode");
3051 final long identity = Binder.clearCallingIdentity();
3052 try {
3053 if (!isActiveSubscription(subId)) {
3054 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3055 }
3056 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3057 } finally {
3058 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003059 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003060 }
3061
Brad Ebinger35c841c2018-10-01 10:40:55 -07003062 @Override
Sarah Chin0605abf2019-12-06 10:24:18 -08003063 public PhoneCapability getPhoneCapability(int subId, String callingPackage,
3064 String callingFeatureId) {
3065 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3066 mApp, subId, callingPackage, callingFeatureId, "getPhoneCapability")) {
3067 return null;
3068 }
3069 final long identity = Binder.clearCallingIdentity();
3070 try {
3071 return mPhoneConfigurationManager.getStaticPhoneCapability();
3072 } finally {
3073 Binder.restoreCallingIdentity(identity);
3074 }
3075 }
3076
3077 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003078 public boolean isInEmergencySmsMode() {
3079 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3080 final long identity = Binder.clearCallingIdentity();
3081 try {
3082 for (Phone phone : PhoneFactory.getPhones()) {
3083 if (phone.isInEmergencySmsMode()) {
3084 return true;
3085 }
3086 }
3087 } finally {
3088 Binder.restoreCallingIdentity(identity);
3089 }
3090 return false;
3091 }
3092
shilu366312e2019-12-17 09:28:10 -08003093 /**
3094 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3095 * @param subId The subscription to use to check the configuration.
3096 * @param c The callback that will be used to send the result.
3097 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003098 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003099 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3100 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003101 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003102 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003103
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003104 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3105 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3106 "IMS not available on device.");
3107 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003108 final long token = Binder.clearCallingIdentity();
3109 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003110 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003111 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003112 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003113 } catch (ImsException e) {
3114 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003115 } finally {
3116 Binder.restoreCallingIdentity(token);
3117 }
3118 }
3119
shilu366312e2019-12-17 09:28:10 -08003120 /**
3121 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3122 * @param subId The subscription to use to check the configuration.
3123 * @param c The callback that will be used to send the result.
3124 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003125 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003126 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
shilu366312e2019-12-17 09:28:10 -08003127 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003128 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003129 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3130 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3131 }
Meng Wangafbc5852019-09-19 17:37:13 -07003132 final long token = Binder.clearCallingIdentity();
3133 try {
3134 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3135 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3136 .removeRegistrationCallbackForSubscription(c, subId);
3137 } catch (ImsException e) {
3138 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3139 + "is inactive, ignoring unregister.");
3140 // If the subscription is no longer active, just return, since the callback
3141 // will already have been removed internally.
3142 } finally {
3143 Binder.restoreCallingIdentity(token);
3144 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003145 }
3146
Brad Ebingera34a6c22019-10-22 17:36:18 -07003147 /**
3148 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3149 */
3150 @Override
3151 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3152 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3153 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3154 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3155 "IMS not available on device.");
3156 }
3157 final long token = Binder.clearCallingIdentity();
3158 try {
3159 Phone phone = getPhone(subId);
3160 if (phone == null) {
3161 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3162 + subId + "'");
3163 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3164 }
3165 phone.getImsRegistrationState(regState -> {
3166 try {
3167 consumer.accept((regState == null)
3168 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3169 } catch (RemoteException e) {
3170 // Ignore if the remote process is no longer available to call back.
3171 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3172 }
3173 });
3174 } finally {
3175 Binder.restoreCallingIdentity(token);
3176 }
3177 }
3178
3179 /**
3180 * Get the transport type for the IMS service registration state.
3181 */
3182 @Override
3183 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
shilu366312e2019-12-17 09:28:10 -08003184 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebingera34a6c22019-10-22 17:36:18 -07003185 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3186 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3187 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3188 "IMS not available on device.");
3189 }
3190 final long token = Binder.clearCallingIdentity();
3191 try {
3192 Phone phone = getPhone(subId);
3193 if (phone == null) {
3194 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3195 + subId + "'");
3196 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3197 }
3198 phone.getImsRegistrationTech(regTech -> {
3199 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3200 int regTechConverted = (regTech == null)
3201 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3202 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3203 regTechConverted);
3204 try {
3205 consumer.accept(regTechConverted);
3206 } catch (RemoteException e) {
3207 // Ignore if the remote process is no longer available to call back.
3208 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3209 }
3210 });
3211 } finally {
3212 Binder.restoreCallingIdentity(token);
3213 }
3214 }
3215
shilu366312e2019-12-17 09:28:10 -08003216 /**
3217 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3218 * @param subId The subscription to use to check the configuration.
3219 * @param c The callback that will be used to send the result.
3220 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003221 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003222 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3223 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003224 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003225 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003226 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3227 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3228 "IMS not available on device.");
3229 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003230 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3231 final long token = Binder.clearCallingIdentity();
3232 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003233 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003234 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003235 } catch (ImsException e) {
3236 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003237 } finally {
3238 Binder.restoreCallingIdentity(token);
3239 }
3240 }
3241
shilu366312e2019-12-17 09:28:10 -08003242 /**
3243 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3244 * @param subId The subscription to use to check the configuration.
3245 * @param c The callback that will be used to send the result.
3246 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003247 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003248 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
shilu366312e2019-12-17 09:28:10 -08003249 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003250 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003251 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3252 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3253 }
Meng Wangafbc5852019-09-19 17:37:13 -07003254
3255 final long token = Binder.clearCallingIdentity();
3256 try {
3257 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3258 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003259 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003260 } catch (ImsException e) {
3261 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3262 + "is inactive, ignoring unregister.");
3263 // If the subscription is no longer active, just return, since the callback
3264 // will already have been removed internally.
3265 } finally {
3266 Binder.restoreCallingIdentity(token);
3267 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003268 }
3269
3270 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003271 public boolean isCapable(int subId, int capability, int regTech) {
3272 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003273 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3274 final long token = Binder.clearCallingIdentity();
3275 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003276 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003277 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003278 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003279 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3280 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003281 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003282 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3283 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003284 } finally {
3285 Binder.restoreCallingIdentity(token);
3286 }
3287 }
3288
3289 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003290 public boolean isAvailable(int subId, int capability, int regTech) {
3291 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003292 final long token = Binder.clearCallingIdentity();
3293 try {
3294 Phone phone = getPhone(subId);
3295 if (phone == null) return false;
3296 return phone.isImsCapabilityAvailable(capability, regTech);
3297 } finally {
3298 Binder.restoreCallingIdentity(token);
3299 }
3300 }
3301
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003302 /**
3303 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3304 * subscription.
3305 * @param subId The subscription to use to check the configuration.
3306 * @param callback The callback that will be used to send the result.
3307 * @param capability The MmTelFeature capability that will be used to send the result.
3308 * @param transportType The transport type of the MmTelFeature capability.
3309 */
3310 @Override
3311 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3312 int transportType) {
3313 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3314 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3315 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3316 "IMS not available on device.");
3317 }
3318 final long token = Binder.clearCallingIdentity();
3319 try {
3320 int slotId = getSlotIndex(subId);
3321 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3322 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3323 + subId + "'");
3324 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3325 }
3326 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3327 transportType, aBoolean -> {
3328 try {
3329 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3330 } catch (RemoteException e) {
3331 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3332 + "running. Ignore");
3333 }
3334 });
3335 } finally {
3336 Binder.restoreCallingIdentity(token);
3337 }
3338 }
3339
shilu366312e2019-12-17 09:28:10 -08003340 /**
3341 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3342 * @param subId The subscription to use to check the configuration.
3343 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003344 @Override
3345 public boolean isAdvancedCallingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003346 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
3347 enforceReadPrivilegedPermission("isAdvancedCallingSettingEnabled");
3348
Brad Ebinger35c841c2018-10-01 10:40:55 -07003349 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3350 final long token = Binder.clearCallingIdentity();
3351 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003352 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003353 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003354 } catch (ImsException e) {
3355 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003356 } finally {
3357 Binder.restoreCallingIdentity(token);
3358 }
3359 }
3360
3361 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003362 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003363 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003364 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003365 final long identity = Binder.clearCallingIdentity();
3366 try {
3367 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003368 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003369 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003370 } catch (ImsException e) {
3371 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003372 } finally {
3373 Binder.restoreCallingIdentity(identity);
3374 }
3375 }
3376
shilu366312e2019-12-17 09:28:10 -08003377 /**
3378 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3379 * @param subId The subscription to use to check the configuration.
3380 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003381 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003382 public boolean isVtSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003383 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003384 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003385 final long identity = Binder.clearCallingIdentity();
3386 try {
3387 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003388 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3389 } catch (ImsException e) {
3390 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003391 } finally {
3392 Binder.restoreCallingIdentity(identity);
3393 }
3394 }
3395
3396 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003397 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003399 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003400 final long identity = Binder.clearCallingIdentity();
3401 try {
3402 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003403 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003404 } catch (ImsException e) {
3405 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003406 } finally {
3407 Binder.restoreCallingIdentity(identity);
3408 }
3409 }
3410
shilu366312e2019-12-17 09:28:10 -08003411 /**
3412 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3413 * @param subId The subscription to use to check the configuration.
3414 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003415 @Override
3416 public boolean isVoWiFiSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003417 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003418 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3419 final long identity = Binder.clearCallingIdentity();
3420 try {
3421 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003422 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003423 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003424 } catch (ImsException e) {
3425 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003426 } finally {
3427 Binder.restoreCallingIdentity(identity);
3428 }
3429 }
3430
3431 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003432 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003433 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003434 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003435 final long identity = Binder.clearCallingIdentity();
3436 try {
3437 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003438 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003439 } catch (ImsException e) {
3440 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003441 } finally {
3442 Binder.restoreCallingIdentity(identity);
3443 }
3444 }
3445
shilu366312e2019-12-17 09:28:10 -08003446 /**
3447 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3448 * @param subId The subscription to use to check the configuration.
3449 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003450 @Override
3451 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003452 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003453 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3454 final long identity = Binder.clearCallingIdentity();
3455 try {
3456 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003457 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003458 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003459 } catch (ImsException e) {
3460 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003461 } finally {
3462 Binder.restoreCallingIdentity(identity);
3463 }
3464 }
3465
3466 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003467 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003468 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003469 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003470 final long identity = Binder.clearCallingIdentity();
3471 try {
3472 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003473 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003474 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003475 } catch (ImsException e) {
3476 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003477 } finally {
3478 Binder.restoreCallingIdentity(identity);
3479 }
3480 }
3481
3482 @Override
3483 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3484 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3485 "setVoWiFiNonPersistent");
3486 final long identity = Binder.clearCallingIdentity();
3487 try {
3488 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003489 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003490 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003491 } catch (ImsException e) {
3492 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003493 } finally {
3494 Binder.restoreCallingIdentity(identity);
3495 }
3496 }
3497
shilu366312e2019-12-17 09:28:10 -08003498 /**
3499 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3500 * @param subId The subscription to use to check the configuration.
3501 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003502 @Override
3503 public int getVoWiFiModeSetting(int subId) {
shilu366312e2019-12-17 09:28:10 -08003504 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003505 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3506 final long identity = Binder.clearCallingIdentity();
3507 try {
3508 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003509 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003510 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003511 } catch (ImsException e) {
3512 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003513 } finally {
3514 Binder.restoreCallingIdentity(identity);
3515 }
3516 }
3517
3518 @Override
3519 public void setVoWiFiModeSetting(int subId, int mode) {
3520 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3521 "setVoWiFiModeSetting");
3522 final long identity = Binder.clearCallingIdentity();
3523 try {
3524 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003525 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003526 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003527 } catch (ImsException e) {
3528 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003529 } finally {
3530 Binder.restoreCallingIdentity(identity);
3531 }
3532 }
3533
3534 @Override
3535 public int getVoWiFiRoamingModeSetting(int subId) {
3536 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3537 final long identity = Binder.clearCallingIdentity();
3538 try {
3539 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003540 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003541 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003542 } catch (ImsException e) {
3543 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003544 } finally {
3545 Binder.restoreCallingIdentity(identity);
3546 }
3547 }
3548
3549 @Override
3550 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3551 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3552 "setVoWiFiRoamingModeSetting");
3553 final long identity = Binder.clearCallingIdentity();
3554 try {
3555 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003556 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003557 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003558 } catch (ImsException e) {
3559 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003560 } finally {
3561 Binder.restoreCallingIdentity(identity);
3562 }
3563 }
3564
3565 @Override
3566 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3568 "setRttCapabilityEnabled");
3569 final long identity = Binder.clearCallingIdentity();
3570 try {
3571 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003572 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3573 } catch (ImsException e) {
3574 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003575 } finally {
3576 Binder.restoreCallingIdentity(identity);
3577 }
3578 }
3579
shilu366312e2019-12-17 09:28:10 -08003580 /**
3581 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3582 * @param subId The subscription to use to check the configuration.
3583 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003584 @Override
3585 public boolean isTtyOverVolteEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003586 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003587 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3588 final long identity = Binder.clearCallingIdentity();
3589 try {
3590 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003591 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003592 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003593 } catch (ImsException e) {
3594 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003595 } finally {
3596 Binder.restoreCallingIdentity(identity);
3597 }
3598 }
3599
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003600 @Override
3601 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3602 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3603 final long identity = Binder.clearCallingIdentity();
3604 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003605 if (!isImsAvailableOnDevice()) {
3606 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3607 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003608 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003609 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003610 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003611 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003612 } catch (ImsException e) {
3613 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003614 } finally {
3615 Binder.restoreCallingIdentity(identity);
3616 }
3617 }
3618
3619 @Override
3620 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3621 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3622 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003623 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3624 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3625 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003626 try {
3627 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003628 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003629 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003630 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003631 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3632 + "is inactive, ignoring unregister.");
3633 // If the subscription is no longer active, just return, since the callback will already
3634 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003635 } finally {
3636 Binder.restoreCallingIdentity(identity);
3637 }
3638 }
3639
allenwtsu99c623b2020-01-03 18:24:23 +08003640
3641 private void checkModifyPhoneStatePermission(int subId, String message) {
3642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3643 message);
3644 }
3645
3646 private boolean isImsProvisioningRequired(int subId, int capability,
3647 boolean isMmtelCapability) {
3648 Phone phone = getPhone(subId);
3649 if (phone == null) {
3650 loge("phone instance null for subid " + subId);
3651 return false;
3652 }
3653 if (isMmtelCapability) {
3654 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3655 return false;
3656 }
3657 } else {
3658 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3659 return false;
3660 }
3661 }
3662 return true;
3663 }
3664
3665 @Override
3666 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3667 boolean isProvisioned) {
3668 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3669
3670 final long identity = Binder.clearCallingIdentity();
3671 try {
3672 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3673 if (!isImsProvisioningRequired(subId, capability, false)) {
3674 return;
3675 }
3676
3677 // this capability requires provisioning, route to the correct API.
3678 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3679 switch (capability) {
3680 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3681 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3682 ims.setEabProvisioned(isProvisioned);
3683 break;
3684 default: {
3685 throw new IllegalArgumentException("Tried to set provisioning for "
3686 + "rcs capability '" + capability + "', which does not require "
3687 + "provisioning.");
3688 }
3689 }
3690 } finally {
3691 Binder.restoreCallingIdentity(identity);
3692 }
3693
3694 }
3695
3696
3697 @Override
3698 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3699 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3700 final long identity = Binder.clearCallingIdentity();
3701 try {
3702 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3703 if (!isImsProvisioningRequired(subId, capability, false)) {
3704 return true;
3705 }
3706
3707 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3708 switch (capability) {
3709 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3710 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3711 return ims.isEabProvisionedOnDevice();
3712
3713 default: {
3714 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3715 + "capability '" + capability + "', which does not require "
3716 + "provisioning.");
3717 }
3718 }
3719
3720 } finally {
3721 Binder.restoreCallingIdentity(identity);
3722 }
3723 }
3724
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003725 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003726 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3727 boolean isProvisioned) {
3728 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3729 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3730 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3731 }
allenwtsu99c623b2020-01-03 18:24:23 +08003732 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003733 final long identity = Binder.clearCallingIdentity();
3734 try {
3735 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003736 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003737 return;
3738 }
3739
3740 // this capability requires provisioning, route to the correct API.
3741 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3742 switch (capability) {
3743 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3744 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3745 ims.setVolteProvisioned(isProvisioned);
3746 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3747 ims.setWfcProvisioned(isProvisioned);
3748 }
3749 break;
3750 }
3751 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3752 // There is currently no difference in VT provisioning type.
3753 ims.setVtProvisioned(isProvisioned);
3754 break;
3755 }
3756 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3757 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3758 // change the capability of the feature instead if needed.
3759 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3760 == isProvisioned) {
3761 // No change in provisioning.
3762 return;
3763 }
3764 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3765 try {
3766 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003767 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003768 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3769 + ", Exception" + e.getMessage());
3770 }
3771 break;
3772 }
3773 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003774 throw new IllegalArgumentException("Tried to set provisioning for "
3775 + "MmTel capability '" + capability + "', which does not require "
3776 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003777 }
3778 }
3779
3780 } finally {
3781 Binder.restoreCallingIdentity(identity);
3782 }
3783 }
3784
3785 @Override
3786 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3787 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3788 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3789 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3790 }
3791 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3792 final long identity = Binder.clearCallingIdentity();
3793 try {
3794 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003795 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003796 return true;
3797 }
3798
3799 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3800 switch (capability) {
3801 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3802 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3803 return ims.isVolteProvisionedOnDevice();
3804 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3805 return ims.isWfcProvisionedOnDevice();
3806 }
3807 // This should never happen, since we are checking tech above to make sure it
3808 // is either LTE or IWLAN.
3809 throw new IllegalArgumentException("Invalid radio technology for voice "
3810 + "capability.");
3811 }
3812 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3813 // There is currently no difference in VT provisioning type.
3814 return ims.isVtProvisionedOnDevice();
3815 }
3816 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3817 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3818 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3819 }
3820 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003821 throw new IllegalArgumentException(
3822 "Tried to get provisioning for MmTel capability '" + capability
3823 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003824 }
3825 }
3826
3827 } finally {
3828 Binder.restoreCallingIdentity(identity);
3829 }
3830 }
3831
3832 @Override
3833 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3834 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3835 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3836 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3837 }
3838 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3839 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3840 return (provisionedBits & capability) > 0;
3841 }
3842
3843 @Override
3844 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3845 boolean isProvisioned) {
3846 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3847 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3848 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3849 }
3850 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3851 "setProvisioningStatusForCapability");
3852 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3853 // If the current provisioning status for capability already matches isProvisioned,
3854 // do nothing.
3855 if (((provisionedBits & capability) > 0) == isProvisioned) {
3856 return;
3857 }
3858 if (isProvisioned) {
3859 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3860 } else {
3861 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3862 }
3863 }
3864
3865 /**
3866 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3867 * technology. The bitfield should mirror the bitfield defined by
3868 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3869 */
3870 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3871 String key = getMmTelProvisioningKey(subId, tech);
3872 // Default is no capabilities are provisioned.
3873 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3874 }
3875
3876 /**
3877 * Sets the MmTel capability provisioning bitfield (defined by
3878 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3879 * technology specified.
3880 *
3881 * Note: This is a synchronous command and should not be called on UI thread.
3882 */
3883 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3884 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3885 String key = getMmTelProvisioningKey(subId, tech);
3886 editor.putInt(key, newField);
3887 editor.commit();
3888 }
3889
3890 private static String getMmTelProvisioningKey(int subId, int tech) {
3891 // resulting key is provision_ims_mmtel_{subId}_{tech}
3892 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3893 }
3894
3895 /**
3896 * Query CarrierConfig to see if the specified capability requires provisioning for the
3897 * carrier associated with the subscription id.
3898 */
3899 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3900 int capability) {
3901 CarrierConfigManager configManager = new CarrierConfigManager(context);
3902 PersistableBundle c = configManager.getConfigForSubId(subId);
3903 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003904 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003905 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3906 false);
3907 boolean requireVoiceVtProvisioning = c.getBoolean(
3908 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3909
3910 // First check to make sure that the capability requires provisioning.
3911 switch (capability) {
3912 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3913 // intentional fallthrough
3914 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3915 if (requireVoiceVtProvisioning) {
3916 // Voice and Video requires provisioning
3917 return true;
3918 }
3919 break;
3920 }
3921 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3922 if (requireUtProvisioning) {
3923 // UT requires provisioning
3924 return true;
3925 }
3926 break;
3927 }
3928 }
3929 return false;
3930 }
3931
allenwtsu99c623b2020-01-03 18:24:23 +08003932 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
3933 int capability) {
3934 CarrierConfigManager configManager = new CarrierConfigManager(context);
3935 PersistableBundle c = configManager.getConfigForSubId(subId);
3936
3937 boolean requireRcsProvisioning = c.getBoolean(
3938 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
3939
3940 // First check to make sure that the capability requires provisioning.
3941 switch (capability) {
3942 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3943 // intentional fallthrough
3944 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
3945 if (requireRcsProvisioning) {
3946 // OPTION or PRESENCE requires provisioning
3947 return true;
3948 }
3949 break;
3950 }
3951 }
3952 return false;
3953 }
3954
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003955 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003956 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003957 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3958 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3959 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003960 enforceReadPrivilegedPermission("getImsProvisioningInt");
3961 final long identity = Binder.clearCallingIdentity();
3962 try {
3963 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003964 int slotId = getSlotIndex(subId);
3965 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3966 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3967 + subId + "' for key:" + key);
3968 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3969 }
3970 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003971 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003972 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3973 + subId + "' for key:" + key);
3974 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003975 } finally {
3976 Binder.restoreCallingIdentity(identity);
3977 }
3978 }
3979
3980 @Override
3981 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003982 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3983 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3984 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003985 enforceReadPrivilegedPermission("getImsProvisioningString");
3986 final long identity = Binder.clearCallingIdentity();
3987 try {
3988 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003989 int slotId = getSlotIndex(subId);
3990 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3991 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3992 + subId + "' for key:" + key);
3993 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3994 }
3995 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003996 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003997 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3998 + subId + "' for key:" + key);
3999 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004000 } finally {
4001 Binder.restoreCallingIdentity(identity);
4002 }
4003 }
4004
4005 @Override
4006 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004007 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4008 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4009 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004010 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4011 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004012 final long identity = Binder.clearCallingIdentity();
4013 try {
4014 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004015 int slotId = getSlotIndex(subId);
4016 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4017 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4018 + subId + "' for key:" + key);
4019 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4020 }
4021 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004022 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004023 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4024 + "' for key:" + key);
4025 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004026 } finally {
4027 Binder.restoreCallingIdentity(identity);
4028 }
4029 }
4030
4031 @Override
4032 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004033 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4034 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4035 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004036 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4037 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004038 final long identity = Binder.clearCallingIdentity();
4039 try {
4040 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004041 int slotId = getSlotIndex(subId);
4042 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4043 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4044 + subId + "' for key:" + key);
4045 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4046 }
4047 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004048 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004049 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4050 + "' for key:" + key);
4051 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004052 } finally {
4053 Binder.restoreCallingIdentity(identity);
4054 }
4055 }
4056
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004057 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004058 int slotId = SubscriptionManager.getSlotIndex(subId);
4059 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004060 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4061 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004062 }
4063 return slotId;
4064 }
4065
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004066 private int getSlotIndex(int subId) {
4067 int slotId = SubscriptionManager.getSlotIndex(subId);
4068 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4069 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4070 }
4071 return slotId;
4072 }
4073
Wink Saville36469e72014-06-11 15:17:00 -07004074 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004075 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004076 */
4077 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004078 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4079 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004080 final int targetSdk = getTargetSdk(callingPackage);
4081 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004082 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004083 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004084 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004085 mApp, subId, callingPackage, callingFeatureId,
4086 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004087 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4088 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004089
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004090 final long identity = Binder.clearCallingIdentity();
4091 try {
4092 final Phone phone = getPhone(subId);
4093 if (phone != null) {
4094 return phone.getServiceState().getDataNetworkType();
4095 } else {
4096 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4097 }
4098 } finally {
4099 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004100 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004101 }
4102
4103 /**
4104 * Returns the data network type
4105 */
4106 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004107 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4108 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4109 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004110 }
4111
4112 /**
4113 * Returns the data network type for a subId
4114 */
4115 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004116 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4117 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004118 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004119 mApp, subId, callingPackage, callingFeatureId,
4120 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004121 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4122 }
4123
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004124 final long identity = Binder.clearCallingIdentity();
4125 try {
4126 final Phone phone = getPhone(subId);
4127 if (phone != null) {
4128 return phone.getServiceState().getDataNetworkType();
4129 } else {
4130 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4131 }
4132 } finally {
4133 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004134 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004135 }
4136
4137 /**
Wink Saville36469e72014-06-11 15:17:00 -07004138 * Returns the Voice network type for a subId
4139 */
4140 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004141 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4142 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004143 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004144 mApp, subId, callingPackage, callingFeatureId,
4145 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004146 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4147 }
4148
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004149 final long identity = Binder.clearCallingIdentity();
4150 try {
4151 final Phone phone = getPhone(subId);
4152 if (phone != null) {
4153 return phone.getServiceState().getVoiceNetworkType();
4154 } else {
4155 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4156 }
4157 } finally {
4158 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004159 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004160 }
4161
4162 /**
4163 * @return true if a ICC card is present
4164 */
4165 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004166 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004167 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4168 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004169 }
4170
4171 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004172 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004173 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004174 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004175 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004176 final long identity = Binder.clearCallingIdentity();
4177 try {
4178 final Phone phone = PhoneFactory.getPhone(slotIndex);
4179 if (phone != null) {
4180 return phone.getIccCard().hasIccCard();
4181 } else {
4182 return false;
4183 }
4184 } finally {
4185 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004186 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004187 }
4188
4189 /**
4190 * Return if the current radio is LTE on CDMA. This
4191 * is a tri-state return value as for a period of time
4192 * the mode may be unknown.
4193 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004194 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004195 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004196 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004197 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004198 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004199 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4200 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4201 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004202 }
4203
Sanket Padawe356d7632015-06-22 14:03:32 -07004204 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004205 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4206 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004207 try {
4208 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4209 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004210 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4211 }
4212
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004213 final long identity = Binder.clearCallingIdentity();
4214 try {
4215 final Phone phone = getPhone(subId);
4216 if (phone == null) {
4217 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4218 } else {
4219 return phone.getLteOnCdmaMode();
4220 }
4221 } finally {
4222 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004223 }
Wink Saville36469e72014-06-11 15:17:00 -07004224 }
4225
Wink Saville36469e72014-06-11 15:17:00 -07004226 /**
4227 * {@hide}
4228 * Returns Default subId, 0 in the case of single standby.
4229 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004230 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004231 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004232 }
4233
Shishir Agrawala9f32182016-04-12 12:00:16 -07004234 private int getSlotForDefaultSubscription() {
4235 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4236 }
4237
Wink Savilleb564aae2014-10-23 10:18:09 -07004238 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004239 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004240 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004241
Pengquan Menge92a50d2018-09-21 15:54:48 -07004242 private boolean isActiveSubscription(int subId) {
4243 return mSubscriptionController.isActiveSubId(subId);
4244 }
4245
Ihab Awadf2177b72013-11-25 13:33:23 -08004246 /**
4247 * @see android.telephony.TelephonyManager.WifiCallingChoices
4248 */
4249 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004250 final long identity = Binder.clearCallingIdentity();
4251 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004252 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004253 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4254 getWhenToMakeWifiCallsDefaultPreference());
4255 } finally {
4256 Binder.restoreCallingIdentity(identity);
4257 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004258 }
4259
4260 /**
4261 * @see android.telephony.TelephonyManager.WifiCallingChoices
4262 */
4263 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004264 final long identity = Binder.clearCallingIdentity();
4265 try {
4266 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004267 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004268 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4269 } finally {
4270 Binder.restoreCallingIdentity(identity);
4271 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004272 }
4273
Sailesh Nepald1e68152013-12-12 19:08:02 -08004274 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004275 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004276 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004277 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004278
Jordan Liu4c733742019-02-28 12:03:40 -08004279 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4280 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4281 if (phoneId == -1) {
4282 throw new IllegalArgumentException("Given slot index: " + slotIndex
4283 + " does not correspond to an active phone");
4284 }
4285 return PhoneFactory.getPhone(phoneId);
4286 }
4287
Shishir Agrawal566b7612013-10-28 14:41:00 -07004288 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004289 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4290 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004291 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4292 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004293 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004294 if (DBG) {
4295 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4296 }
4297 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4298 p2);
4299 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004300
Jordan Liu4c733742019-02-28 12:03:40 -08004301
4302 @Override
4303 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4304 int slotIndex, String callingPackage, String aid, int p2) {
4305 enforceModifyPermission();
4306 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4307 if (DBG) {
4308 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4309 }
4310 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4311 callingPackage, aid, p2);
4312 }
4313
4314 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4315 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004316 final long identity = Binder.clearCallingIdentity();
4317 try {
4318 if (TextUtils.equals(ISDR_AID, aid)) {
4319 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004320 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4321 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004322 if (bestComponent == null
4323 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4324 loge("The calling package is not allowed to access ISD-R.");
4325 throw new SecurityException(
4326 "The calling package is not allowed to access ISD-R.");
4327 }
Derek Tan740e1672017-06-27 14:56:27 -07004328 }
Derek Tan740e1672017-06-27 14:56:27 -07004329
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004330 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004331 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4332 null /* workSource */);
4333 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004334 return response;
4335 } finally {
4336 Binder.restoreCallingIdentity(identity);
4337 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004338 }
4339
4340 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004341 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4343 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004344 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4345 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4346 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004347
Jordan Liu4c733742019-02-28 12:03:40 -08004348 @Override
4349 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4350 enforceModifyPermission();
4351 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4352 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4353 channel);
4354 }
4355
4356 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004357 final long identity = Binder.clearCallingIdentity();
4358 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004359 if (channel < 0) {
4360 return false;
4361 }
Jordan Liu4c733742019-02-28 12:03:40 -08004362 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4363 null /* workSource */);
4364 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004365 return success;
4366 } finally {
4367 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004368 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004369 }
4370
4371 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004372 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004373 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4375 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004376 if (DBG) {
4377 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4378 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4379 + p3 + " data=" + data);
4380 }
4381 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4382 command, p1, p2, p3, data);
4383 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004384
Jordan Liu4c733742019-02-28 12:03:40 -08004385 @Override
4386 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4387 int command, int p1, int p2, int p3, String data) {
4388 enforceModifyPermission();
4389 if (DBG) {
4390 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4391 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4392 + p3 + " data=" + data);
4393 }
4394 return iccTransmitApduLogicalChannelWithPermission(
4395 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4396 data);
4397 }
4398
4399 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4400 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004401 final long identity = Binder.clearCallingIdentity();
4402 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004403 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004404 return "";
4405 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004406
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004407 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004408 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4409 null /* workSource */);
4410 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004411
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004412 // Append the returned status code to the end of the response payload.
4413 String s = Integer.toHexString(
4414 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4415 if (response.payload != null) {
4416 s = IccUtils.bytesToHexString(response.payload) + s;
4417 }
4418 return s;
4419 } finally {
4420 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004421 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004422 }
Jake Hambye994d462014-02-03 13:10:13 -08004423
Evan Charltonc66da362014-05-16 14:06:40 -07004424 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004425 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4426 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004427 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4428 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004429 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004430 if (DBG) {
4431 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4432 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4433 }
4434 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4435 cla, command, p1, p2, p3, data);
4436 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004437
Jordan Liu4c733742019-02-28 12:03:40 -08004438 @Override
4439 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4440 int command, int p1, int p2, int p3, String data) {
4441 enforceModifyPermission();
4442 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4443 if (DBG) {
4444 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4445 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4446 + " data=" + data);
4447 }
4448
4449 return iccTransmitApduBasicChannelWithPermission(
4450 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4451 p2, p3, data);
4452 }
4453
4454 // open APDU basic channel assuming the caller has sufficient permissions
4455 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4456 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004457 final long identity = Binder.clearCallingIdentity();
4458 try {
4459 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4460 && TextUtils.equals(ISDR_AID, data)) {
4461 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004462 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4463 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004464 if (bestComponent == null
4465 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4466 loge("The calling package is not allowed to select ISD-R.");
4467 throw new SecurityException(
4468 "The calling package is not allowed to select ISD-R.");
4469 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004470 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004472 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004473 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4474 null /* workSource */);
4475 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004476
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004477 // Append the returned status code to the end of the response payload.
4478 String s = Integer.toHexString(
4479 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4480 if (response.payload != null) {
4481 s = IccUtils.bytesToHexString(response.payload) + s;
4482 }
4483 return s;
4484 } finally {
4485 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004486 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004487 }
4488
4489 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004490 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004491 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4493 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004494
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004495 final long identity = Binder.clearCallingIdentity();
4496 try {
4497 if (DBG) {
4498 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4499 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4500 }
4501
4502 IccIoResult response =
4503 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4504 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4505 subId);
4506
4507 if (DBG) {
4508 log("Exchange SIM_IO [R]" + response);
4509 }
4510
4511 byte[] result = null;
4512 int length = 2;
4513 if (response.payload != null) {
4514 length = 2 + response.payload.length;
4515 result = new byte[length];
4516 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4517 } else {
4518 result = new byte[length];
4519 }
4520
4521 result[length - 1] = (byte) response.sw2;
4522 result[length - 2] = (byte) response.sw1;
4523 return result;
4524 } finally {
4525 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004526 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004527 }
4528
Nathan Haroldb3014052017-01-25 15:57:32 -08004529 /**
4530 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4531 * on a particular subscription
4532 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004533 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4534 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004535 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004536 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004537 return null;
4538 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004539
4540 final long identity = Binder.clearCallingIdentity();
4541 try {
4542 if (appType != TelephonyManager.APPTYPE_USIM
4543 && appType != TelephonyManager.APPTYPE_SIM) {
4544 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4545 return null;
4546 }
4547 Object response = sendRequest(
4548 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4549 if (response instanceof String[]) {
4550 return (String[]) response;
4551 }
yincheng zhao2737e882019-09-06 17:06:54 -07004552 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004553 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004554 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004555 } finally {
4556 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004557 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004558 }
4559
yincheng zhao2737e882019-09-06 17:06:54 -07004560 /**
4561 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4562 * subscription.
4563 *
4564 * @param subId the id of the subscription.
4565 * @param appType the uicc app type, must be USIM or SIM.
4566 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4567 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004568 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004569 * @return number of fplmns that is successfully written to the SIM.
4570 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004571 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4572 String callingFeatureId) {
4573 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4574 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004575 if (DBG) logv("no permissions for setForbiddenplmns");
4576 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4577 }
4578 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4579 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4580 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4581 }
4582 if (fplmns == null) {
4583 throw new IllegalArgumentException("Fplmn List provided is null");
4584 }
4585 for (String fplmn : fplmns) {
4586 if (!CellIdentity.isValidPlmn(fplmn)) {
4587 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4588 }
4589 }
4590 final long identity = Binder.clearCallingIdentity();
4591 try {
4592 Object response = sendRequest(
4593 CMD_SET_FORBIDDEN_PLMNS,
4594 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4595 subId);
4596 return (int) response;
4597 } finally {
4598 Binder.restoreCallingIdentity(identity);
4599 }
4600 }
4601
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004602 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004603 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004604 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4605 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004606
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004607 final long identity = Binder.clearCallingIdentity();
4608 try {
4609 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4610 if (response.payload == null) {
4611 return "";
4612 }
Evan Charltonc66da362014-05-16 14:06:40 -07004613
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004614 // Append the returned status code to the end of the response payload.
4615 String s = Integer.toHexString(
4616 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4617 s = IccUtils.bytesToHexString(response.payload) + s;
4618 return s;
4619 } finally {
4620 Binder.restoreCallingIdentity(identity);
4621 }
Evan Charltonc66da362014-05-16 14:06:40 -07004622 }
4623
Jake Hambye994d462014-02-03 13:10:13 -08004624 /**
4625 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4626 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4627 *
4628 * @param itemID the ID of the item to read
4629 * @return the NV item as a String, or null on error.
4630 */
4631 @Override
4632 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004633 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4635 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004636
4637 final long identity = Binder.clearCallingIdentity();
4638 try {
4639 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004640 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004641 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4642 return value;
4643 } finally {
4644 Binder.restoreCallingIdentity(identity);
4645 }
Jake Hambye994d462014-02-03 13:10:13 -08004646 }
4647
4648 /**
4649 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4650 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4651 *
4652 * @param itemID the ID of the item to read
4653 * @param itemValue the value to write, as a String
4654 * @return true on success; false on any failure
4655 */
4656 @Override
4657 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004658 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4660 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004661
4662 final long identity = Binder.clearCallingIdentity();
4663 try {
4664 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4665 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004666 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004667 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4668 return success;
4669 } finally {
4670 Binder.restoreCallingIdentity(identity);
4671 }
Jake Hambye994d462014-02-03 13:10:13 -08004672 }
4673
4674 /**
4675 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4676 * Used for device configuration by some CDMA operators.
4677 *
4678 * @param preferredRoamingList byte array containing the new PRL
4679 * @return true on success; false on any failure
4680 */
4681 @Override
4682 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004683 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4684 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004685
4686 final long identity = Binder.clearCallingIdentity();
4687 try {
4688 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4689 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4690 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4691 return success;
4692 } finally {
4693 Binder.restoreCallingIdentity(identity);
4694 }
Jake Hambye994d462014-02-03 13:10:13 -08004695 }
4696
4697 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004698 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004699 * Used for device configuration by some CDMA operators.
4700 *
chen xu6dac5ab2018-10-26 17:39:23 -07004701 * @param slotIndex - device slot.
4702 *
Jake Hambye994d462014-02-03 13:10:13 -08004703 * @return true on success; false on any failure
4704 */
4705 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004706 public boolean resetModemConfig(int slotIndex) {
4707 Phone phone = PhoneFactory.getPhone(slotIndex);
4708 if (phone != null) {
4709 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4710 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004711
chen xu6dac5ab2018-10-26 17:39:23 -07004712 final long identity = Binder.clearCallingIdentity();
4713 try {
4714 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4715 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4716 return success;
4717 } finally {
4718 Binder.restoreCallingIdentity(identity);
4719 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004720 }
chen xu6dac5ab2018-10-26 17:39:23 -07004721 return false;
4722 }
4723
4724 /**
4725 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4726 *
4727 * @param slotIndex - device slot.
4728 *
4729 * @return true on success; false on any failure
4730 */
4731 @Override
4732 public boolean rebootModem(int slotIndex) {
4733 Phone phone = PhoneFactory.getPhone(slotIndex);
4734 if (phone != null) {
4735 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4736 mApp, phone.getSubId(), "rebootModem");
4737
4738 final long identity = Binder.clearCallingIdentity();
4739 try {
4740 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4741 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4742 return success;
4743 } finally {
4744 Binder.restoreCallingIdentity(identity);
4745 }
4746 }
4747 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004748 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004749
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004750 public String[] getPcscfAddress(String apnType, String callingPackage,
4751 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004752 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004753 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4754 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004755 return new String[0];
4756 }
4757
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004758 final long identity = Binder.clearCallingIdentity();
4759 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004760 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004761 } finally {
4762 Binder.restoreCallingIdentity(identity);
4763 }
Wink Saville36469e72014-06-11 15:17:00 -07004764 }
4765
Brad Ebinger51f743a2017-01-23 13:50:20 -08004766 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004767 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4768 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004769 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004770 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004771 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004772
4773 final long identity = Binder.clearCallingIdentity();
4774 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004775 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004776 // may happen if the device does not support IMS.
4777 return;
4778 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004779 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004780 } finally {
4781 Binder.restoreCallingIdentity(identity);
4782 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004783 }
4784
4785 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004786 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4787 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004788 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004789 public void disableIms(int slotId) {
4790 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004791
4792 final long identity = Binder.clearCallingIdentity();
4793 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004794 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004795 // may happen if the device does not support IMS.
4796 return;
4797 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004798 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004799 } finally {
4800 Binder.restoreCallingIdentity(identity);
4801 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004802 }
4803
4804 /**
4805 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4806 * feature or {@link null} if the service is not available. If the feature is available, the
4807 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4808 */
4809 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004810 IImsServiceFeatureCallback callback) {
4811 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004812
4813 final long identity = Binder.clearCallingIdentity();
4814 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004815 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004816 // may happen if the device does not support IMS.
4817 return null;
4818 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004819 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004820 } finally {
4821 Binder.restoreCallingIdentity(identity);
4822 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004823 }
4824
4825 /**
4826 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4827 * feature during emergency calling or {@link null} if the service is not available. If the
4828 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4829 * listener for feature updates.
4830 */
4831 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4832 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004833
4834 final long identity = Binder.clearCallingIdentity();
4835 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004836 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004837 // may happen if the device does not support IMS.
4838 return null;
4839 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004840 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004841 } finally {
4842 Binder.restoreCallingIdentity(identity);
4843 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004844 }
4845
Brad Ebinger5f64b052017-12-14 14:26:15 -08004846 /**
4847 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004848 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004849 */
4850 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4851 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004852
4853 final long identity = Binder.clearCallingIdentity();
4854 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004855 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004856 // may happen if the device does not support IMS.
4857 return null;
4858 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004859 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004860 } finally {
4861 Binder.restoreCallingIdentity(identity);
4862 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004863 }
4864
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004865 /**
4866 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004867 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004868 */
4869 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4870 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004871
4872 final long identity = Binder.clearCallingIdentity();
4873 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004874 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004875 // may happen if the device does not support IMS.
4876 return null;
4877 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004878 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004879 } finally {
4880 Binder.restoreCallingIdentity(identity);
4881 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004882 }
4883
Brad Ebinger884c07b2018-02-15 16:17:40 -08004884 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004885 * Sets the ImsService Package Name that Telephony will bind to.
4886 *
Brad Ebinger24c29992019-12-05 13:03:21 -08004887 * @param slotIndex the slot ID that the ImsService should bind for.
4888 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004889 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08004890 * @param featureTypes An integer array of feature types associated with a packageName.
4891 * @param packageName The name of the package that the current configuration will be replaced
4892 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004893 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004894 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004895 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4896 int[] featureTypes, String packageName) {
4897 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4898 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004899 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4900 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08004901 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004902
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004903 final long identity = Binder.clearCallingIdentity();
4904 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004905 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004906 // may happen if the device does not support IMS.
4907 return false;
4908 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004909 Map<Integer, String> featureConfig = new HashMap<>();
4910 for (int featureType : featureTypes) {
4911 featureConfig.put(featureType, packageName);
4912 }
4913 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4914 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004915 } finally {
4916 Binder.restoreCallingIdentity(identity);
4917 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004918 }
4919
4920 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08004921 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004922 *
4923 * @param slotId The slot that the ImsService is associated with.
4924 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4925 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08004926 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004927 * @return the package name of the ImsService configuration.
4928 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004929 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4930 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004931 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08004932 TelephonyPermissions
4933 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4934 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4935 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004936
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004937 final long identity = Binder.clearCallingIdentity();
4938 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004939 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004940 // may happen if the device does not support IMS.
4941 return "";
4942 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004943 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08004944 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4945 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004946 } finally {
4947 Binder.restoreCallingIdentity(identity);
4948 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004949 }
4950
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004951 /**
4952 * Get the MmTelFeature state associated with the requested subscription id.
4953 * @param subId The subscription that the MmTelFeature is associated with.
4954 * @param callback A callback with an integer containing the
4955 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4956 */
4957 @Override
4958 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4959 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4960 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4961 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4962 "IMS not available on device.");
4963 }
4964 final long token = Binder.clearCallingIdentity();
4965 try {
4966 int slotId = getSlotIndex(subId);
4967 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4968 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4969 + subId + "'");
4970 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4971 }
4972 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4973 try {
4974 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4975 } catch (RemoteException e) {
4976 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4977 + "Ignore");
4978 }
4979 });
4980 } finally {
4981 Binder.restoreCallingIdentity(token);
4982 }
4983 }
4984
Wink Saville36469e72014-06-11 15:17:00 -07004985 public void setImsRegistrationState(boolean registered) {
4986 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004987
4988 final long identity = Binder.clearCallingIdentity();
4989 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004990 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004991 } finally {
4992 Binder.restoreCallingIdentity(identity);
4993 }
Wink Saville36469e72014-06-11 15:17:00 -07004994 }
4995
4996 /**
Stuart Scott54788802015-03-30 13:18:01 -07004997 * Set the network selection mode to automatic.
4998 *
4999 */
5000 @Override
5001 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005002 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5003 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004
5005 final long identity = Binder.clearCallingIdentity();
5006 try {
shilufc958392020-01-20 11:36:01 -08005007 if (!isActiveSubscription(subId)) {
5008 return;
5009 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005010 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5011 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5012 } finally {
5013 Binder.restoreCallingIdentity(identity);
5014 }
Stuart Scott54788802015-03-30 13:18:01 -07005015 }
5016
Pengquan Mengea84e042018-09-20 14:57:26 -07005017 /**
5018 * Ask the radio to connect to the input network and change selection mode to manual.
5019 *
5020 * @param subId the id of the subscription.
5021 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5022 * the operator to attach to.
5023 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5024 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5025 * normal network selection next time.
5026 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005027 */
5028 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005029 public boolean setNetworkSelectionModeManual(
5030 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5032 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005033
5034 if (!isActiveSubscription(subId)) {
5035 return false;
5036 }
5037
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005038 final long identity = Binder.clearCallingIdentity();
5039 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005040 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005041 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005042 if (DBG) {
5043 log("setNetworkSelectionModeManual: subId: " + subId
5044 + " operator: " + operatorInfo);
5045 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005046 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5047 } finally {
5048 Binder.restoreCallingIdentity(identity);
5049 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005050 }
shilu84f6e8b2019-12-19 13:58:01 -08005051 /**
5052 * Get the manual network selection
5053 *
5054 * @param subId the id of the subscription.
5055 *
5056 * @return the previously saved user selected PLMN
5057 */
5058 @Override
5059 public String getManualNetworkSelectionPlmn(int subId) {
5060 TelephonyPermissions
5061 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5062 mApp, subId, "getManualNetworkSelectionPlmn");
5063
5064 final long identity = Binder.clearCallingIdentity();
5065 try {
5066 if (!isActiveSubscription(subId)) {
5067 return "";
5068 }
5069
5070 final Phone phone = getPhone(subId);
5071 if (phone == null) {
5072 return "";
5073 }
5074 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5075 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5076 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5077 } finally {
5078 Binder.restoreCallingIdentity(identity);
5079 }
5080 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005081
5082 /**
5083 * Scans for available networks.
5084 */
5085 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005086 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5087 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005088 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5089 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005090 LocationAccessPolicy.LocationPermissionResult locationResult =
5091 LocationAccessPolicy.checkLocationPermission(mApp,
5092 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5093 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005094 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005095 .setCallingPid(Binder.getCallingPid())
5096 .setCallingUid(Binder.getCallingUid())
5097 .setMethod("getCellNetworkScanResults")
5098 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5099 .build());
5100 switch (locationResult) {
5101 case DENIED_HARD:
5102 throw new SecurityException("Not allowed to access scan results -- location");
5103 case DENIED_SOFT:
5104 return null;
5105 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005106
Pengquan Menga1bb6272018-09-06 09:59:22 -07005107 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005108 try {
5109 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005110 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005111 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005112 } finally {
5113 Binder.restoreCallingIdentity(identity);
5114 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005115 }
5116
5117 /**
yinxub1bed742017-04-17 11:45:04 -07005118 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005119 *
yinxub1bed742017-04-17 11:45:04 -07005120 * @param subId id of the subscription
5121 * @param request contains the radio access networks with bands/channels to scan
5122 * @param messenger callback messenger for scan results or errors
5123 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005124 * @return the id of the requested scan which can be used to stop the scan.
5125 */
5126 @Override
5127 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005128 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005129 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5130 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005131 LocationAccessPolicy.LocationPermissionResult locationResult =
5132 LocationAccessPolicy.checkLocationPermission(mApp,
5133 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5134 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005135 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005136 .setCallingPid(Binder.getCallingPid())
5137 .setCallingUid(Binder.getCallingUid())
5138 .setMethod("requestNetworkScan")
5139 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5140 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005141 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005142 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005143 if (e != null) {
5144 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5145 throw e;
5146 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005147 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005148 return TelephonyScanManager.INVALID_SCAN_ID;
5149 }
5150 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005151 }
Hall Liu912dfd32019-04-25 14:02:26 -07005152 int callingUid = Binder.getCallingUid();
5153 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005154 final long identity = Binder.clearCallingIdentity();
5155 try {
5156 return mNetworkScanRequestTracker.startNetworkScan(
5157 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005158 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005159 } finally {
5160 Binder.restoreCallingIdentity(identity);
5161 }
yinxu504e1392017-04-12 16:03:22 -07005162 }
5163
Hall Liub2ac8ef2019-02-28 15:56:23 -08005164 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005165 NetworkScanRequest request, int subId) {
5166 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5167 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5168 boolean hasNetworkScanPermission =
5169 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5170 == PERMISSION_GRANTED;
5171
5172 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5173 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5174 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005175 }
5176
5177 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5178 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005179 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5180 return new SecurityException("Specific channels must not be"
5181 + " scanned without location access.");
5182 }
5183 }
5184 }
5185
Hall Liub2ac8ef2019-02-28 15:56:23 -08005186 return null;
5187 }
5188
yinxu504e1392017-04-12 16:03:22 -07005189 /**
5190 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005191 *
5192 * @param subId id of the subscription
5193 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005194 */
5195 @Override
5196 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005197 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5198 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005199
Hall Liu912dfd32019-04-25 14:02:26 -07005200 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005201 final long identity = Binder.clearCallingIdentity();
5202 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005203 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005204 } finally {
5205 Binder.restoreCallingIdentity(identity);
5206 }
yinxu504e1392017-04-12 16:03:22 -07005207 }
5208
5209 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005210 * Get the calculated preferred network type.
5211 * Used for debugging incorrect network type.
5212 *
5213 * @return the preferred network type, defined in RILConstants.java.
5214 */
5215 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005216 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005217 final Phone defaultPhone = getDefaultPhone();
5218 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005219 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005220 return RILConstants.PREFERRED_NETWORK_MODE;
5221 }
5222
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005223 final long identity = Binder.clearCallingIdentity();
5224 try {
5225 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005226 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005227 } finally {
5228 Binder.restoreCallingIdentity(identity);
5229 }
Junda Liu84d15a22014-07-02 11:21:04 -07005230 }
5231
5232 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005233 * Get the preferred network type.
5234 * Used for device configuration by some CDMA operators.
5235 *
5236 * @return the preferred network type, defined in RILConstants.java.
5237 */
5238 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005239 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005240 TelephonyPermissions
5241 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5242 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005243
5244 final long identity = Binder.clearCallingIdentity();
5245 try {
5246 if (DBG) log("getPreferredNetworkType");
5247 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5248 int networkType = (result != null ? result[0] : -1);
5249 if (DBG) log("getPreferredNetworkType: " + networkType);
5250 return networkType;
5251 } finally {
5252 Binder.restoreCallingIdentity(identity);
5253 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005254 }
5255
5256 /**
5257 * Set the preferred network type.
5258 * Used for device configuration by some CDMA operators.
5259 *
5260 * @param networkType the preferred network type, defined in RILConstants.java.
5261 * @return true on success; false on any failure.
5262 */
5263 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005264 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005265 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5266 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005267
5268 final long identity = Binder.clearCallingIdentity();
5269 try {
calvinpan0ac9c1a2020-01-14 20:42:55 +08005270 Settings.Global.putInt(mApp.getContentResolver(),
5271 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5272 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005273 } finally {
5274 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005275 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005276 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005277
5278 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005279 * Get the allowed network types that store in the telephony provider.
5280 *
5281 * @param subId the id of the subscription.
5282 * @return allowedNetworkTypes the allowed network types.
5283 */
5284 @Override
5285 public long getAllowedNetworkTypes(int subId) {
5286 TelephonyPermissions
5287 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5288 mApp, subId, "getAllowedNetworkTypes");
5289
5290 final long identity = Binder.clearCallingIdentity();
5291 try {
5292 return SubscriptionManager.getLongSubscriptionProperty(
5293 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5294 } finally {
5295 Binder.restoreCallingIdentity(identity);
5296 }
5297 }
5298
5299 /**
5300 * Set the allowed network types.
5301 *
5302 * @param subId the id of the subscription.
5303 * @param allowedNetworkTypes the allowed network types.
5304 * @return true on success; false on any failure.
5305 */
5306 @Override
5307 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5309 mApp, subId, "setAllowedNetworkTypes");
5310 final long identity = Binder.clearCallingIdentity();
5311 try {
5312 SubscriptionManager.setSubscriptionProperty(subId,
5313 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5314 String.valueOf(allowedNetworkTypes));
5315 return setPreferredNetworkTypesInternal(subId);
5316 } finally {
5317 Binder.restoreCallingIdentity(identity);
5318 }
5319 }
5320
5321 private boolean setPreferredNetworkTypesInternal(int subId) {
5322 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5323 Settings.Global.getInt(mApp.getContentResolver(),
5324 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5325 RILConstants.PREFERRED_NETWORK_MODE));
5326 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5327 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5328 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5329 (int) (networkTypeBitMask & allowedNetworkTypes));
5330
5331 if (DBG) {
5332 log("setPreferredNetworkTypesInternal: subId " + subId
5333 + " networkTypes " + networkTypeBitMask
5334 + " allowedNetworkTypes " + allowedNetworkTypes
5335 + " networkMode " + networkMode);
5336 }
5337
5338 Boolean success = (Boolean) sendRequest(
5339 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5340 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5341 return success;
5342 }
5343
5344 /**
Miaoa84611c2019-03-15 09:21:10 +08005345 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005346 *
Miaoa84611c2019-03-15 09:21:10 +08005347 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005348 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005349 * @hide
5350 */
5351 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005352 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005353 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005354 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005355 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005356 try {
Miaoa84611c2019-03-15 09:21:10 +08005357 if (phone != null) {
5358 return phone.hasMatchedTetherApnSetting();
5359 } else {
5360 return false;
5361 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005362 } finally {
5363 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005364 }
Junda Liu475951f2014-11-07 16:45:03 -08005365 }
5366
5367 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005368 * Set mobile data enabled
5369 * Used by the user through settings etc to turn on/off mobile data
5370 *
5371 * @param enable {@code true} turn turn data on, else {@code false}
5372 */
5373 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005374 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005375 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5376 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005377
5378 final long identity = Binder.clearCallingIdentity();
5379 try {
5380 int phoneId = mSubscriptionController.getPhoneId(subId);
5381 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5382 Phone phone = PhoneFactory.getPhone(phoneId);
5383 if (phone != null) {
5384 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005385 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005386 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005387 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005388 }
5389 } finally {
5390 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005391 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005392 }
5393
5394 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005395 * Enable or disable always reporting signal strength changes from radio.
5396 *
5397 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5398 */
5399 @Override
5400 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5401 enforceModifyPermission();
5402 enforceSystemCaller();
5403
5404 final long identity = Binder.clearCallingIdentity();
5405 final Phone phone = getPhone(subId);
5406 try {
5407 if (phone != null) {
5408 if (DBG) {
5409 log("setAlwaysReportSignalStrength: subId=" + subId
5410 + " isEnable=" + isEnable);
5411 }
5412 phone.setAlwaysReportSignalStrength(isEnable);
5413 } else {
5414 loge("setAlwaysReportSignalStrength: no phone found for subId="
5415 + subId);
5416 }
5417 } finally {
5418 Binder.restoreCallingIdentity(identity);
5419 }
5420 }
5421
5422 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005423 * Get the user enabled state of Mobile Data.
5424 *
5425 * TODO: remove and use isUserDataEnabled.
5426 * This can't be removed now because some vendor codes
5427 * calls through ITelephony directly while they should
5428 * use TelephonyManager.
5429 *
5430 * @return true on enabled
5431 */
5432 @Override
5433 public boolean getDataEnabled(int subId) {
5434 return isUserDataEnabled(subId);
5435 }
5436
5437 /**
5438 * Get whether mobile data is enabled per user setting.
5439 *
5440 * There are other factors deciding whether mobile data is actually enabled, but they are
5441 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005442 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005443 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005444 *
5445 * @return {@code true} if data is enabled else {@code false}
5446 */
5447 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005448 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005449 try {
5450 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5451 null);
5452 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005453 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5454 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005455 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005456
5457 final long identity = Binder.clearCallingIdentity();
5458 try {
5459 int phoneId = mSubscriptionController.getPhoneId(subId);
5460 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5461 Phone phone = PhoneFactory.getPhone(phoneId);
5462 if (phone != null) {
5463 boolean retVal = phone.isUserDataEnabled();
5464 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5465 return retVal;
5466 } else {
5467 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5468 return false;
5469 }
5470 } finally {
5471 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005472 }
5473 }
5474
5475 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005476 * Checks if the device is capable of mobile data by considering whether whether the
5477 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5478 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005479 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005480 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005481 */
5482 @Override
5483 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005484 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005485
5486 final long identity = Binder.clearCallingIdentity();
5487 try {
5488 int phoneId = mSubscriptionController.getPhoneId(subId);
5489 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5490 Phone phone = PhoneFactory.getPhone(phoneId);
5491 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005492 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005493 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5494 return retVal;
5495 } else {
5496 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5497 return false;
5498 }
5499 } finally {
5500 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005501 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005502 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005503
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005504 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5505 Phone phone) {
5506 //load access rules from carrier configs, and check those as well: b/139133814
5507 SubscriptionController subController = SubscriptionController.getInstance();
5508 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5509 || subController == null) return privilegeFromSim;
5510
5511 int uid = Binder.getCallingUid();
5512 PackageManager pkgMgr = phone.getContext().getPackageManager();
5513 String[] packages = pkgMgr.getPackagesForUid(uid);
5514
5515 final long identity = Binder.clearCallingIdentity();
5516 try {
5517 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5518 SubscriptionManager subManager = (SubscriptionManager)
5519 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5520 for (String pkg : packages) {
5521 if (subManager.canManageSubscription(subInfo, pkg)) {
5522 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5523 }
5524 }
5525 return privilegeFromSim;
5526 } finally {
5527 Binder.restoreCallingIdentity(identity);
5528 }
5529 }
5530
5531 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5532 String pkgName) {
5533 //load access rules from carrier configs, and check those as well: b/139133814
5534 SubscriptionController subController = SubscriptionController.getInstance();
5535 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5536 || subController == null) return privilegeFromSim;
5537
5538 final long identity = Binder.clearCallingIdentity();
5539 try {
5540 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5541 SubscriptionManager subManager = (SubscriptionManager)
5542 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5543 return subManager.canManageSubscription(subInfo, pkgName)
5544 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5545 } finally {
5546 Binder.restoreCallingIdentity(identity);
5547 }
5548 }
5549
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005550 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005551 public int getCarrierPrivilegeStatus(int subId) {
5552 final Phone phone = getPhone(subId);
5553 if (phone == null) {
5554 loge("getCarrierPrivilegeStatus: Invalid subId");
5555 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5556 }
5557 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005558 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005559 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005560 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5561 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005562
5563 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5564 card.getCarrierPrivilegeStatusForCurrentTransaction(
5565 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005566 }
Junda Liu29340342014-07-10 15:23:27 -07005567
5568 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005569 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005570 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005571 final Phone phone = getPhone(subId);
5572 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005573 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005574 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5575 }
5576 UiccProfile profile =
5577 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5578 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005579 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005580 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5581 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005582 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005583 profile.getCarrierPrivilegeStatusForUid(
5584 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005585 }
5586
5587 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005588 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5589 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005590 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005591 }
5592
5593 int phoneId = SubscriptionManager.getPhoneId(subId);
5594 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005595 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005596 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005597 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5598 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005599 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5600 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5601 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005602 }
5603
5604 @Override
5605 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005606 if (TextUtils.isEmpty(pkgName))
5607 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005608 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5609 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5610 UiccCard card = UiccController.getInstance().getUiccCard(i);
5611 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005612 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005613 continue;
5614 }
5615
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005616 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5617 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5618 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005619 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5620 break;
5621 }
5622 }
5623
5624 return result;
Junda Liu29340342014-07-10 15:23:27 -07005625 }
Derek Tan89e89d42014-07-08 17:00:10 -07005626
5627 @Override
Junda Liue64de782015-04-16 17:19:16 -07005628 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5629 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5630 loge("phoneId " + phoneId + " is not valid.");
5631 return null;
5632 }
5633 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005634 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005635 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005636 return null ;
5637 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005638 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005639 }
5640
Amith Yamasani6e118872016-02-19 12:53:51 -08005641 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005642 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005643 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005644 List<String> privilegedPackages = new ArrayList<>();
5645 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005646 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5647 // has UICC in that slot.
5648 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005649 if (card.hasCarrierPrivilegeRules()) {
5650 if (packages == null) {
5651 // Only check packages in user 0 for now
5652 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005653 PackageManager.MATCH_DISABLED_COMPONENTS
5654 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005655 | PackageManager.GET_SIGNING_CERTIFICATES,
5656 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005657 }
5658 for (int p = packages.size() - 1; p >= 0; p--) {
5659 PackageInfo pkgInfo = packages.get(p);
5660 if (pkgInfo != null && pkgInfo.packageName != null
5661 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005662 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005663 privilegedPackages.add(pkgInfo.packageName);
5664 }
5665 }
5666 }
5667 }
5668 return privilegedPackages;
5669 }
5670
chen xuf7e9fe82019-05-09 19:31:02 -07005671 @Override
5672 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005673 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5674
5675 final long identity = Binder.clearCallingIdentity();
5676
chen xuf7e9fe82019-05-09 19:31:02 -07005677 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005678 try {
5679 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5680 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5681 }
5682 } finally {
5683 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005684 }
5685 return privilegedPackages;
5686 }
5687
Wink Savilleb564aae2014-10-23 10:18:09 -07005688 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005689 final Phone phone = getPhone(subId);
5690 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005691 if (card == null) {
5692 loge("getIccId: No UICC");
5693 return null;
5694 }
5695 String iccId = card.getIccId();
5696 if (TextUtils.isEmpty(iccId)) {
5697 loge("getIccId: ICC ID is null or empty.");
5698 return null;
5699 }
5700 return iccId;
5701 }
5702
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005703 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005704 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5705 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005706 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005707 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005708
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005709 final long identity = Binder.clearCallingIdentity();
5710 try {
5711 final String iccId = getIccId(subId);
5712 final Phone phone = getPhone(subId);
5713 if (phone == null) {
5714 return false;
5715 }
5716 final String subscriberId = phone.getSubscriberId();
5717
5718 if (DBG_MERGE) {
5719 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5720 + subscriberId + " to " + number);
5721 }
5722
5723 if (TextUtils.isEmpty(iccId)) {
5724 return false;
5725 }
5726
5727 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5728
5729 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5730 if (alphaTag == null) {
5731 editor.remove(alphaTagPrefKey);
5732 } else {
5733 editor.putString(alphaTagPrefKey, alphaTag);
5734 }
5735
5736 // Record both the line number and IMSI for this ICCID, since we need to
5737 // track all merged IMSIs based on line number
5738 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5739 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5740 if (number == null) {
5741 editor.remove(numberPrefKey);
5742 editor.remove(subscriberPrefKey);
5743 } else {
5744 editor.putString(numberPrefKey, number);
5745 editor.putString(subscriberPrefKey, subscriberId);
5746 }
5747
5748 editor.commit();
5749 return true;
5750 } finally {
5751 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005752 }
Derek Tan7226c842014-07-02 17:42:23 -07005753 }
5754
5755 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005756 public String getLine1NumberForDisplay(int subId, String callingPackage,
5757 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005758 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005759 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005760 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005761 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005762 return null;
5763 }
Derek Tan97ebb422014-09-05 16:55:38 -07005764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005765 final long identity = Binder.clearCallingIdentity();
5766 try {
5767 String iccId = getIccId(subId);
5768 if (iccId != null) {
5769 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5770 if (DBG_MERGE) {
5771 log("getLine1NumberForDisplay returning "
5772 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5773 }
5774 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005775 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005776 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5777 return null;
5778 } finally {
5779 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005780 }
Derek Tan7226c842014-07-02 17:42:23 -07005781 }
5782
5783 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005784 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5785 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005786 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005787 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005788 return null;
5789 }
Derek Tan97ebb422014-09-05 16:55:38 -07005790
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005791 final long identity = Binder.clearCallingIdentity();
5792 try {
5793 String iccId = getIccId(subId);
5794 if (iccId != null) {
5795 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5796 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5797 }
5798 return null;
5799 } finally {
5800 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005801 }
Derek Tan7226c842014-07-02 17:42:23 -07005802 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005803
5804 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005805 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5806 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005807 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5808 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005809 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005810 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005811 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005812 return null;
5813 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005814
Jordan Liub49b04b2019-05-06 14:45:15 -07005815 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5816 // the process, where TelephonyManager was instantiated.
5817 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005818 final long identity = Binder.clearCallingIdentity();
5819 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005820 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005821 final TelephonyManager tele = TelephonyManager.from(context);
5822 final SubscriptionManager sub = SubscriptionManager.from(context);
5823
5824 // Figure out what subscribers are currently active
5825 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005826
Jordan Liub49b04b2019-05-06 14:45:15 -07005827 // Only consider subs which match the current subId
5828 // This logic can be simplified. See b/131189269 for progress.
5829 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005830 activeSubscriberIds.add(tele.getSubscriberId(subId));
5831 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005832
5833 // First pass, find a number override for an active subscriber
5834 String mergeNumber = null;
5835 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5836 for (String key : prefs.keySet()) {
5837 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5838 final String subscriberId = (String) prefs.get(key);
5839 if (activeSubscriberIds.contains(subscriberId)) {
5840 final String iccId = key.substring(
5841 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5842 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5843 mergeNumber = (String) prefs.get(numberKey);
5844 if (DBG_MERGE) {
5845 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5846 + " for active subscriber " + subscriberId);
5847 }
5848 if (!TextUtils.isEmpty(mergeNumber)) {
5849 break;
5850 }
5851 }
5852 }
5853 }
5854
5855 // Shortcut when no active merged subscribers
5856 if (TextUtils.isEmpty(mergeNumber)) {
5857 return null;
5858 }
5859
5860 // Second pass, find all subscribers under that line override
5861 final ArraySet<String> result = new ArraySet<>();
5862 for (String key : prefs.keySet()) {
5863 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5864 final String number = (String) prefs.get(key);
5865 if (mergeNumber.equals(number)) {
5866 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5867 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5868 final String subscriberId = (String) prefs.get(subscriberKey);
5869 if (!TextUtils.isEmpty(subscriberId)) {
5870 result.add(subscriberId);
5871 }
5872 }
5873 }
5874 }
5875
5876 final String[] resultArray = result.toArray(new String[result.size()]);
5877 Arrays.sort(resultArray);
5878 if (DBG_MERGE) {
5879 Slog.d(LOG_TAG,
5880 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5881 }
5882 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005883 } finally {
5884 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005885 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005886 }
5887
5888 @Override
zoey chen38003472019-12-13 17:16:31 +08005889 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
5890 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07005891
5892 final long identity = Binder.clearCallingIdentity();
5893 try {
5894 final TelephonyManager telephonyManager = mApp.getSystemService(
5895 TelephonyManager.class);
5896 String subscriberId = telephonyManager.getSubscriberId(subId);
5897 if (subscriberId == null) {
5898 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08005899 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07005900 + subId);
5901 }
5902 return null;
5903 }
5904
5905 final SubscriptionInfo info = SubscriptionController.getInstance()
5906 .getSubscriptionInfo(subId);
5907 final ParcelUuid groupUuid = info.getGroupUuid();
5908 // If it doesn't belong to any group, return just subscriberId of itself.
5909 if (groupUuid == null) {
5910 return new String[]{subscriberId};
5911 }
5912
5913 // Get all subscriberIds from the group.
5914 final List<String> mergedSubscriberIds = new ArrayList<>();
5915 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005916 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5917 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005918 for (SubscriptionInfo subInfo : groupInfos) {
5919 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5920 if (subscriberId != null) {
5921 mergedSubscriberIds.add(subscriberId);
5922 }
5923 }
5924
5925 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5926 } finally {
5927 Binder.restoreCallingIdentity(identity);
5928
5929 }
5930 }
5931
5932 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005933 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005934 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005935 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005936
5937 final long identity = Binder.clearCallingIdentity();
5938 try {
5939 final Phone phone = getPhone(subId);
5940 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5941 } finally {
5942 Binder.restoreCallingIdentity(identity);
5943 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005944 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005945
5946 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005947 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005948 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5949 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005950 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5951 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005952
5953 final long identity = Binder.clearCallingIdentity();
5954 try {
5955 final Phone phone = getPhone(subId);
5956 if (phone == null) {
5957 return false;
5958 }
5959 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5960 cdmaNonRoamingList);
5961 } finally {
5962 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005963 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005964 }
5965
5966 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005967 @Deprecated
5968 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5969 enforceModifyPermission();
5970
5971 int returnValue = 0;
5972 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005973 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005974 if(result.exception == null) {
5975 if (result.result != null) {
5976 byte[] responseData = (byte[])(result.result);
5977 if(responseData.length > oemResp.length) {
5978 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5979 responseData.length + "bytes. Buffer Size is " +
5980 oemResp.length + "bytes.");
5981 }
5982 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5983 returnValue = responseData.length;
5984 }
5985 } else {
5986 CommandException ex = (CommandException) result.exception;
5987 returnValue = ex.getCommandError().ordinal();
5988 if(returnValue > 0) returnValue *= -1;
5989 }
5990 } catch (RuntimeException e) {
5991 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5992 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5993 if(returnValue > 0) returnValue *= -1;
5994 }
5995
5996 return returnValue;
5997 }
5998
5999 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006000 public void setRadioCapability(RadioAccessFamily[] rafs) {
6001 try {
6002 ProxyController.getInstance().setRadioCapability(rafs);
6003 } catch (RuntimeException e) {
6004 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6005 }
6006 }
6007
6008 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006009 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006010 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006011 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006012 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006013 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006014 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006015 final long identity = Binder.clearCallingIdentity();
6016 try {
chen xub97461a2018-10-26 14:17:57 -07006017 TelephonyPermissions
6018 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6019 mApp, phone.getSubId(), "getRadioAccessFamily");
6020 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006021 } finally {
6022 Binder.restoreCallingIdentity(identity);
6023 }
chen xub97461a2018-10-26 14:17:57 -07006024 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006025 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006026
6027 @Override
6028 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006029 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006030 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006031
6032 final long identity = Binder.clearCallingIdentity();
6033 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006034 ImsManager.getInstance(defaultPhone.getContext(),
6035 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006036 } finally {
6037 Binder.restoreCallingIdentity(identity);
6038 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006039 }
6040
6041 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006042 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006043 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006044 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6045 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006046 return false;
6047 }
Svet Ganovb320e182015-04-16 12:30:10 -07006048
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006049 final long identity = Binder.clearCallingIdentity();
6050 try {
6051 // Check the user preference and the system-level IMS setting. Even if the user has
6052 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6053 // In the long run, we may instead need to check if there exists a connection service
6054 // which can support video calling.
6055 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006056 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006057 return imsManager.isVtEnabledByPlatform()
6058 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6059 && imsManager.isVtEnabledByUser();
6060 } finally {
6061 Binder.restoreCallingIdentity(identity);
6062 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006063 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006064
Andrew Leea1239f22015-03-02 17:44:07 -08006065 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006066 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6067 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006069 mApp, subId, callingPackage, callingFeatureId,
6070 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006071 return false;
6072 }
6073
6074 final long identity = Binder.clearCallingIdentity();
6075 try {
6076 CarrierConfigManager configManager =
6077 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006078 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006079 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6080 } finally {
6081 Binder.restoreCallingIdentity(identity);
6082 }
Andrew Leea1239f22015-03-02 17:44:07 -08006083 }
6084
6085 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006086 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006087 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006088 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006089 return false;
6090 }
6091
6092 final long identity = Binder.clearCallingIdentity();
6093 try {
6094 CarrierConfigManager configManager =
6095 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006096 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006097 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6098 } finally {
6099 Binder.restoreCallingIdentity(identity);
6100 }
Andrew Leea1239f22015-03-02 17:44:07 -08006101 }
6102
Andrew Lee9431b832015-03-09 18:46:45 -07006103 @Override
6104 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006105 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006106 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006107 }
6108
6109 @Override
6110 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006111 final long identity = Binder.clearCallingIdentity();
6112 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006113 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006114 } finally {
6115 Binder.restoreCallingIdentity(identity);
6116 }
Andrew Lee9431b832015-03-09 18:46:45 -07006117 }
6118
Hall Liuf6668912018-10-31 17:05:23 -07006119 /**
6120 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6121 * support for the feature and device firmware support.
6122 *
6123 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6124 */
6125 @Override
6126 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006127 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006128 final Phone phone = getPhone(subscriptionId);
6129 if (phone == null) {
6130 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6131 return false;
6132 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006133 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006134 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6136 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006137 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006138 return isCarrierSupported && isDeviceSupported;
6139 } finally {
6140 Binder.restoreCallingIdentity(identity);
6141 }
Hall Liu98187582018-01-22 19:15:32 -08006142 }
6143
Hall Liuf6668912018-10-31 17:05:23 -07006144 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006145 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6146 * RTT setting, will return true if the device and carrier both support RTT.
6147 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006148 */
6149 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006150 final long identity = Binder.clearCallingIdentity();
6151 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006152 boolean isRttSupported = isRttSupported(subscriptionId);
6153 boolean isUserRttSettingOn = Settings.Secure.getInt(
6154 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6155 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6156 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6157 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006158 } finally {
6159 Binder.restoreCallingIdentity(identity);
6160 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006161 }
6162
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006163 @Deprecated
6164 @Override
6165 public String getDeviceId(String callingPackage) {
6166 return getDeviceIdWithFeature(callingPackage, null);
6167 }
6168
Sanket Padawe7310cc72015-01-14 09:53:20 -08006169 /**
6170 * Returns the unique device ID of phone, for example, the IMEI for
6171 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6172 *
6173 * <p>Requires Permission:
6174 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6175 */
6176 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006177 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006178 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006179 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006180 return null;
6181 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006182 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006183 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006184 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006185 return null;
6186 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006187
6188 final long identity = Binder.clearCallingIdentity();
6189 try {
6190 return phone.getDeviceId();
6191 } finally {
6192 Binder.restoreCallingIdentity(identity);
6193 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006194 }
6195
Ping Sunc67b7c22016-03-02 19:16:45 +08006196 /**
6197 * {@hide}
6198 * Returns the IMS Registration Status on a particular subid
6199 *
6200 * @param subId
6201 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006202 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006203 Phone phone = getPhone(subId);
6204 if (phone != null) {
6205 return phone.isImsRegistered();
6206 } else {
6207 return false;
6208 }
6209 }
6210
Santos Cordon7a1885b2015-02-03 11:15:19 -08006211 @Override
6212 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006213 final long identity = Binder.clearCallingIdentity();
6214 try {
6215 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6216 } finally {
6217 Binder.restoreCallingIdentity(identity);
6218 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006219 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006220
Tyler Gunnf70ed162019-04-03 15:28:53 -07006221 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006222 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006223 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006224 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006225 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006226 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6227 }
6228 final long identity = Binder.clearCallingIdentity();
6229 try {
6230 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6231 } finally {
6232 Binder.restoreCallingIdentity(identity);
6233 }
6234 }
6235
6236 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006237 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6238 final long identity = Binder.clearCallingIdentity();
6239 try {
6240 Phone phone = getPhone(subscriptionId);
6241 if (phone == null) {
6242 return null;
6243 }
6244 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6245 } finally {
6246 Binder.restoreCallingIdentity(identity);
6247 }
6248 }
6249
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006250 /**
6251 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006252 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006253 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006254 final long identity = Binder.clearCallingIdentity();
6255 try {
6256 Phone phone = getPhone(subId);
6257 if (phone != null) {
6258 return phone.isWifiCallingEnabled();
6259 } else {
6260 return false;
6261 }
6262 } finally {
6263 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006264 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006265 }
6266
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006267 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006268 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006269 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006270 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006271 final long identity = Binder.clearCallingIdentity();
6272 try {
6273 Phone phone = getPhone(subId);
6274 if (phone != null) {
6275 return phone.isVideoEnabled();
6276 } else {
6277 return false;
6278 }
6279 } finally {
6280 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006281 }
6282 }
6283
6284 /**
6285 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6286 * defined in {@link ImsRegistrationImplBase}.
6287 */
6288 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006289 final long identity = Binder.clearCallingIdentity();
6290 try {
6291 Phone phone = getPhone(subId);
6292 if (phone != null) {
6293 return phone.getImsRegistrationTech();
6294 } else {
6295 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6296 }
6297 } finally {
6298 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006299 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006300 }
6301
Stuart Scott8eef64f2015-04-08 15:13:54 -07006302 @Override
6303 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006304 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006305 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6306 return;
6307 }
6308
Svet Ganovcc087f82015-05-12 20:35:54 -07006309 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006310
Svet Ganovcc087f82015-05-12 20:35:54 -07006311 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006312 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6313 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006314 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006315 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006316 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006317 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6318 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006319 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006320 // There has been issues when Sms raw table somehow stores orphan
6321 // fragments. They lead to garbled message when new fragments come
6322 // in and combined with those stale ones. In case this happens again,
6323 // user can reset all network settings which will clean up this table.
6324 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006325 // Clean up IMS settings as well here.
6326 int slotId = getSlotIndex(subId);
6327 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6328 ImsManager.getInstance(mApp, slotId).factoryReset();
6329 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006330
6331 // Erase modem config if erase modem on network setting is enabled.
6332 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6333 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6334 if (configValue != null && Boolean.parseBoolean(configValue)) {
6335 sendEraseModemConfig(getDefaultPhone());
6336 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006337 } finally {
6338 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006339 }
6340 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006341
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006342 private void cleanUpSmsRawTable(Context context) {
6343 ContentResolver resolver = context.getContentResolver();
6344 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6345 resolver.delete(uri, null, null);
6346 }
6347
Narayan Kamath1c496c22015-04-16 14:40:19 +01006348 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006349 public String getSimLocaleForSubscriber(int subId) {
6350 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6351 final Phone phone = getPhone(subId);
6352 if (phone == null) {
6353 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006354 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006355 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006356 final long identity = Binder.clearCallingIdentity();
6357 try {
chen xu5d3637b2019-01-21 23:31:38 -08006358 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006359 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08006360 if (info == null) {
6361 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6362 return null;
6363 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006364 // Try and fetch the locale from the carrier properties or from the SIM language
6365 // preferences (EF-PL and EF-LI)...
6366 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006367 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006368 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6369 if (localeFromDefaultSim != null) {
6370 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6371 if (DBG) log("Using locale from subId: " + subId + " locale: "
6372 + localeFromDefaultSim);
6373 return localeFromDefaultSim.toLanguageTag();
6374 } else {
6375 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006376 }
6377 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006379 // The SIM language preferences only store a language (e.g. fr = French), not an
6380 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6381 // the SIM and carrier preferences does not include a country we add the country
6382 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006383 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006384 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006385 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006386 return mccLocale.toLanguageTag();
6387 }
6388
6389 if (DBG) log("No locale found - returning null");
6390 return null;
6391 } finally {
6392 Binder.restoreCallingIdentity(identity);
6393 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006394 }
6395
6396 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006397 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6398 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006399 }
6400
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006401 /**
6402 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6403 */
6404 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006405 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6406 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006407 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006408
Chenjie Yu1ba97252018-01-11 18:16:20 -08006409 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006410 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006411
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006412 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006413 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6414 * representing the state of the modem.
6415 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006416 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6417 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006418 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006419 */
6420 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006421 public void requestModemActivityInfo(ResultReceiver result) {
6422 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006423 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006424
6425 final long identity = Binder.clearCallingIdentity();
6426 try {
6427 ModemActivityInfo ret = null;
6428 synchronized (mLastModemActivityInfo) {
6429 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6430 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006431 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006432 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006433 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006434 int[] txTimeMs = info.getTransmitTimeMillis();
6435 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006436 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006437 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006438 }
6439 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006440 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6441 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006442 mLastModemActivityInfo.setIdleTimeMillis(
6443 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006444 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6445 mLastModemActivityInfo.setReceiveTimeMillis(
6446 info.getReceiveTimeMillis() + mLastModemActivityInfo
6447 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006448 }
Chen Xud78231e2019-09-10 18:49:52 -07006449
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006450 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6451 mLastModemActivityInfo.getSleepTimeMillis(),
6452 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006453 mLastModemActivityInfo.getTransmitTimeMillis(),
6454 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006455 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006456 Bundle bundle = new Bundle();
6457 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6458 result.send(0, bundle);
6459 } finally {
6460 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006461 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006462 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006463
Siddharth Rayb8114062018-06-17 15:02:38 -07006464 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6465 // less than total activity duration.
6466 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6467 if (info == null) {
6468 return false;
6469 }
6470 int activityDurationMs =
6471 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6472 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006473 int[] txTimeMs = info.getTransmitTimeMillis();
6474 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6475 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006476 }
6477 return (info.isValid()
6478 && (info.getSleepTimeMillis() <= activityDurationMs)
6479 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006480 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006481 && (totalTxTimeMs <= activityDurationMs));
6482 }
6483
Jack Yu85bd38a2015-11-09 11:34:32 -08006484 /**
6485 * {@hide}
6486 * Returns the service state information on specified subscription.
6487 */
6488 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006489 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6490 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006491 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006492 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006493 return null;
6494 }
6495
Hall Liuf19c44f2018-11-27 14:38:17 -08006496 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6497 LocationAccessPolicy.checkLocationPermission(mApp,
6498 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6499 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006500 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006501 .setCallingPid(Binder.getCallingPid())
6502 .setCallingUid(Binder.getCallingUid())
6503 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006504 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006505 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6506 .build());
6507
6508 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6509 LocationAccessPolicy.checkLocationPermission(mApp,
6510 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6511 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006512 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006513 .setCallingPid(Binder.getCallingPid())
6514 .setCallingUid(Binder.getCallingUid())
6515 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006516 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006517 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6518 .build());
6519 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6520 boolean hasFinePermission =
6521 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6522 boolean hasCoarsePermission =
6523 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6524
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006525 final long identity = Binder.clearCallingIdentity();
6526 try {
6527 final Phone phone = getPhone(subId);
6528 if (phone == null) {
6529 return null;
6530 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006531
Hall Liuf19c44f2018-11-27 14:38:17 -08006532 ServiceState ss = phone.getServiceState();
6533
6534 // Scrub out the location info in ServiceState depending on what level of access
6535 // the caller has.
6536 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006537 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6538 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006539 } finally {
6540 Binder.restoreCallingIdentity(identity);
6541 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006542 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006543
6544 /**
6545 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6546 *
6547 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6548 * voicemail ringtone.
6549 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6550 * PhoneAccount.
6551 */
6552 @Override
6553 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006554 final long identity = Binder.clearCallingIdentity();
6555 try {
6556 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6557 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006558 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006559 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006560
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006561 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6562 } finally {
6563 Binder.restoreCallingIdentity(identity);
6564 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006565 }
6566
6567 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006568 * Sets the per-account voicemail ringtone.
6569 *
6570 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6571 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6572 *
6573 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6574 * voicemail ringtone.
6575 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6576 * PhoneAccount.
6577 */
6578 @Override
6579 public void setVoicemailRingtoneUri(String callingPackage,
6580 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006581 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006582 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006583 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6584 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6586 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6587 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006588 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006589
6590 final long identity = Binder.clearCallingIdentity();
6591 try {
6592 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6593 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006594 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006595 }
6596 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6597 } finally {
6598 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006599 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006600 }
6601
6602 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006603 * Returns whether vibration is set for voicemail notification in Phone settings.
6604 *
6605 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6606 * voicemail vibration setting.
6607 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6608 */
6609 @Override
6610 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006611 final long identity = Binder.clearCallingIdentity();
6612 try {
6613 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6614 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006615 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006616 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006617
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006618 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6619 } finally {
6620 Binder.restoreCallingIdentity(identity);
6621 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006622 }
6623
Youhan Wange64578a2016-05-02 15:32:42 -07006624 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006625 * Sets the per-account voicemail vibration.
6626 *
6627 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6628 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6629 *
6630 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6631 * voicemail vibration setting.
6632 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6633 * specific PhoneAccount.
6634 */
6635 @Override
6636 public void setVoicemailVibrationEnabled(String callingPackage,
6637 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006638 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006639 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006640 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6641 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6643 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6644 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006645 }
6646
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006647 final long identity = Binder.clearCallingIdentity();
6648 try {
6649 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6650 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006651 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006652 }
6653 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6654 } finally {
6655 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006656 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006657 }
6658
6659 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006660 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6661 *
6662 * @throws SecurityException if the caller does not have the required permission
6663 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006664 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006665 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006666 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006667 }
6668
6669 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006670 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6671 * permission.
6672 *
6673 * @throws SecurityException if the caller does not have the required permission
6674 */
6675 private void enforceSendSmsPermission() {
6676 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6677 }
6678
6679 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006680 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006681 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006682 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006683 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006684 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006685 final long identity = Binder.clearCallingIdentity();
6686 try {
6687 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006688 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006689 if (componentName == null) {
6690 throw new SecurityException(
6691 "Caller not current active visual voicemail package[null]");
6692 }
6693 String vvmPackage = componentName.getPackageName();
6694 if (!callingPackage.equals(vvmPackage)) {
6695 throw new SecurityException("Caller not current active visual voicemail package["
6696 + vvmPackage + "]");
6697 }
6698 } finally {
6699 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006700 }
6701 }
6702
6703 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006704 * Return the application ID for the app type.
6705 *
6706 * @param subId the subscription ID that this request applies to.
6707 * @param appType the uicc app type.
6708 * @return Application ID for specificied app type, or null if no uicc.
6709 */
6710 @Override
6711 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006712 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006713 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006714
6715 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006716 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006717 if (phone == null) {
6718 return null;
6719 }
6720 String aid = null;
6721 try {
6722 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6723 .getApplicationByType(appType).getAid();
6724 } catch (Exception e) {
6725 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6726 }
6727 return aid;
6728 } finally {
6729 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006730 }
Youhan Wange64578a2016-05-02 15:32:42 -07006731 }
6732
Youhan Wang4001d252016-05-11 10:29:41 -07006733 /**
6734 * Return the Electronic Serial Number.
6735 *
6736 * @param subId the subscription ID that this request applies to.
6737 * @return ESN or null if error.
6738 */
6739 @Override
6740 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006741 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006742 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006743
6744 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006745 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006746 if (phone == null) {
6747 return null;
6748 }
6749 String esn = null;
6750 try {
6751 esn = phone.getEsn();
6752 } catch (Exception e) {
6753 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6754 }
6755 return esn;
6756 } finally {
6757 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006758 }
Youhan Wang4001d252016-05-11 10:29:41 -07006759 }
6760
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006761 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006762 * Return the Preferred Roaming List Version.
6763 *
6764 * @param subId the subscription ID that this request applies to.
6765 * @return PRLVersion or null if error.
6766 */
6767 @Override
6768 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006769 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006770 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006771
6772 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006773 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006774 if (phone == null) {
6775 return null;
6776 }
6777 String cdmaPrlVersion = null;
6778 try {
6779 cdmaPrlVersion = phone.getCdmaPrlVersion();
6780 } catch (Exception e) {
6781 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6782 }
6783 return cdmaPrlVersion;
6784 } finally {
6785 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006786 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006787 }
6788
6789 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006790 * Get snapshot of Telephony histograms
6791 * @return List of Telephony histograms
6792 * @hide
6793 */
6794 @Override
6795 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006796 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6797 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006798
6799 final long identity = Binder.clearCallingIdentity();
6800 try {
6801 return RIL.getTelephonyRILTimingHistograms();
6802 } finally {
6803 Binder.restoreCallingIdentity(identity);
6804 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006805 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006806
6807 /**
6808 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006809 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6810 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006811 * Require system privileges. In the future we may add this to carrier APIs.
6812 *
Michele Berionne482f8202018-11-27 18:57:59 -08006813 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006814 */
6815 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006816 @TelephonyManager.SetCarrierRestrictionResult
6817 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006818 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006819 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006820
Michele Berionne482f8202018-11-27 18:57:59 -08006821 if (carrierRestrictionRules == null) {
6822 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006823 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006824
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006825 final long identity = Binder.clearCallingIdentity();
6826 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006827 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006828 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006829 } finally {
6830 Binder.restoreCallingIdentity(identity);
6831 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006832 }
6833
6834 /**
6835 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006836 * Get the allowed carrier list and the excluded carrier list, including the priority between
6837 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006838 * Require system privileges. In the future we may add this to carrier APIs.
6839 *
Michele Berionne482f8202018-11-27 18:57:59 -08006840 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006841 */
6842 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006843 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006844 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006845 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006846
6847 final long identity = Binder.clearCallingIdentity();
6848 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006849 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6850 if (response instanceof CarrierRestrictionRules) {
6851 return (CarrierRestrictionRules) response;
6852 }
6853 // Response is an Exception of some kind,
6854 // which is signalled to the user as a NULL retval
6855 return null;
6856 } catch (Exception e) {
6857 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6858 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006859 } finally {
6860 Binder.restoreCallingIdentity(identity);
6861 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006862 }
6863
fionaxu59545b42016-05-25 15:53:37 -07006864 /**
6865 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6866 * @param subId the subscription ID that this action applies to.
6867 * @param enabled control enable or disable metered apns.
6868 * {@hide}
6869 */
6870 @Override
6871 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6872 enforceModifyPermission();
6873 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006874
6875 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006876 if (phone == null) {
6877 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6878 return;
6879 }
6880 try {
6881 phone.carrierActionSetMeteredApnsEnabled(enabled);
6882 } catch (Exception e) {
6883 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006884 } finally {
6885 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006886 }
6887 }
6888
6889 /**
6890 * Action set from carrier signalling broadcast receivers to enable/disable radio
6891 * @param subId the subscription ID that this action applies to.
6892 * @param enabled control enable or disable radio.
6893 * {@hide}
6894 */
6895 @Override
6896 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6897 enforceModifyPermission();
6898 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006899
6900 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006901 if (phone == null) {
6902 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6903 return;
6904 }
6905 try {
6906 phone.carrierActionSetRadioEnabled(enabled);
6907 } catch (Exception e) {
6908 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006909 } finally {
6910 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006911 }
6912 }
6913
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006914 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006915 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6916 * network status based on which carrier apps could apply actions accordingly,
6917 * enable/disable default url handler for example.
6918 *
6919 * @param subId the subscription ID that this action applies to.
6920 * @param report control start/stop reporting the default network status.
6921 * {@hide}
6922 */
6923 @Override
6924 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6925 enforceModifyPermission();
6926 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006927
6928 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006929 if (phone == null) {
6930 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6931 return;
6932 }
6933 try {
6934 phone.carrierActionReportDefaultNetworkStatus(report);
6935 } catch (Exception e) {
6936 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006937 } finally {
6938 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006939 }
6940 }
6941
6942 /**
fionaxud9622282017-07-17 17:51:30 -07006943 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6944 * @param subId the subscription ID that this action applies to.
6945 * {@hide}
6946 */
6947 @Override
6948 public void carrierActionResetAll(int subId) {
6949 enforceModifyPermission();
6950 final Phone phone = getPhone(subId);
6951 if (phone == null) {
6952 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6953 return;
6954 }
6955 try {
6956 phone.carrierActionResetAll();
6957 } catch (Exception e) {
6958 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6959 }
6960 }
6961
6962 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006963 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6964 * bug report is being generated.
6965 */
6966 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006967 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006968 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6969 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006970 writer.println("Permission Denial: can't dump Phone from pid="
6971 + Binder.getCallingPid()
6972 + ", uid=" + Binder.getCallingUid()
6973 + "without permission "
6974 + android.Manifest.permission.DUMP);
6975 return;
6976 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006977 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006978 }
Jack Yueb89b242016-06-22 13:27:47 -07006979
Brad Ebingerdac2f002018-04-03 15:17:52 -07006980 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08006981 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
6982 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
6983 @NonNull String[] args) {
6984 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
6985 this, in.getFileDescriptor(), out.getFileDescriptor(),
6986 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006987 }
6988
Jack Yueb89b242016-06-22 13:27:47 -07006989 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006990 * Get aggregated video call data usage since boot.
6991 *
6992 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6993 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006994 * {@hide}
6995 */
6996 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006997 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006998 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6999 null);
7000
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007001 final long identity = Binder.clearCallingIdentity();
7002 try {
7003 // NetworkStatsService keeps tracking the active network interface and identity. It
7004 // records the delta with the corresponding network identity.
7005 // We just return the total video call data usage snapshot since boot.
7006 Phone phone = getPhone(subId);
7007 if (phone != null) {
7008 return phone.getVtDataUsage(perUidStats);
7009 }
7010 return null;
7011 } finally {
7012 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07007013 }
Jack Yueb89b242016-06-22 13:27:47 -07007014 }
Jack Yu75ab2952016-07-08 14:29:33 -07007015
7016 /**
7017 * Policy control of data connection. Usually used when data limit is passed.
7018 * @param enabled True if enabling the data, otherwise disabling.
7019 * @param subId Subscription index
7020 * {@hide}
7021 */
7022 @Override
7023 public void setPolicyDataEnabled(boolean enabled, int subId) {
7024 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007025
7026 final long identity = Binder.clearCallingIdentity();
7027 try {
7028 Phone phone = getPhone(subId);
7029 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007030 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007031 }
7032 } finally {
7033 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007034 }
7035 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007036
7037 /**
7038 * Get Client request stats
7039 * @return List of Client Request Stats
7040 * @hide
7041 */
7042 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007043 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7044 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007045 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007046 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007047 return null;
7048 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007049 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007050
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007051 final long identity = Binder.clearCallingIdentity();
7052 try {
7053 if (phone != null) {
7054 return phone.getClientRequestStats();
7055 }
7056
7057 return null;
7058 } finally {
7059 Binder.restoreCallingIdentity(identity);
7060 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007061 }
7062
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007063 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007064 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007065 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007066 }
Jack Yueb4124c2017-02-16 15:32:43 -08007067
7068 /**
Grace Chen70990072017-03-24 17:21:30 -07007069 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007070 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007071 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007072 * @param state State of SIM (power down, power up, pass through)
7073 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7074 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7075 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007076 *
7077 **/
7078 @Override
Grace Chen70990072017-03-24 17:21:30 -07007079 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007080 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007081 Phone phone = PhoneFactory.getPhone(slotIndex);
7082
vagdeviaf9a5b92018-08-15 16:01:53 -07007083 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7084
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007085 final long identity = Binder.clearCallingIdentity();
7086 try {
7087 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007088 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007089 }
7090 } finally {
7091 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007092 }
7093 }
Shuo Qiandd210312017-04-12 22:11:33 +00007094
Tyler Gunn65d45c22017-06-05 11:22:26 -07007095 private boolean isUssdApiAllowed(int subId) {
7096 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007097 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007098 if (configManager == null) {
7099 return false;
7100 }
7101 PersistableBundle pb = configManager.getConfigForSubId(subId);
7102 if (pb == null) {
7103 return false;
7104 }
7105 return pb.getBoolean(
7106 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7107 }
7108
Shuo Qiandd210312017-04-12 22:11:33 +00007109 /**
7110 * Check if phone is in emergency callback mode
7111 * @return true if phone is in emergency callback mode
7112 * @param subId sub id
7113 */
goneil9c5f4872017-12-05 14:07:56 -08007114 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007115 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007116 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007117 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007118
7119 final long identity = Binder.clearCallingIdentity();
7120 try {
7121 if (phone != null) {
7122 return phone.isInEcm();
7123 } else {
7124 return false;
7125 }
7126 } finally {
7127 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007128 }
7129 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007130
7131 /**
7132 * Get the current signal strength information for the given subscription.
7133 * Because this information is not updated when the device is in a low power state
7134 * it should not be relied-upon to be current.
7135 * @param subId Subscription index
7136 * @return the most recent cached signal strength info from the modem
7137 */
7138 @Override
7139 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007140 final long identity = Binder.clearCallingIdentity();
7141 try {
7142 Phone p = getPhone(subId);
7143 if (p == null) {
7144 return null;
7145 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007146
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007147 return p.getSignalStrength();
7148 } finally {
7149 Binder.restoreCallingIdentity(identity);
7150 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007151 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007152
Pengquan Meng77b7f132018-08-22 14:49:57 -07007153 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007154 * Get the current modem radio state for the given slot.
7155 * @param slotIndex slot index.
7156 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007157 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007158 * @return the current radio power state from the modem
7159 */
7160 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007161 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007162 Phone phone = PhoneFactory.getPhone(slotIndex);
7163 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007164 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7165 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007166 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7167 }
7168
7169 final long identity = Binder.clearCallingIdentity();
7170 try {
7171 return phone.getRadioPowerState();
7172 } finally {
7173 Binder.restoreCallingIdentity(identity);
7174 }
7175 }
7176 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7177 }
7178
7179 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007180 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7181 *
7182 * <p>Requires one of the following permissions:
7183 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7184 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7185 * privileges.
7186 *
7187 * @param subId subscription id
7188 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7189 * {@code false}.
7190 */
7191 @Override
7192 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007193 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7194 null /* message */);
7195
Pengquan Menga1bb6272018-09-06 09:59:22 -07007196 boolean isEnabled = false;
7197 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007198 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007199 Phone phone = getPhone(subId);
7200 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007201 } catch (Exception e) {
7202 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7203 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007204 } finally {
7205 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007206 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007207 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007208 }
7209
7210
7211 /**
7212 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7213 *
7214 * <p> Requires permission:
7215 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7216 * privileges.
7217 *
7218 * @param subId subscription id
7219 * @param isEnabled {@code true} means enable, {@code false} means disable.
7220 */
7221 @Override
7222 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007223 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7224 mApp, subId, "setDataRoamingEnabled");
7225
Pengquan Menga1bb6272018-09-06 09:59:22 -07007226 final long identity = Binder.clearCallingIdentity();
7227 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007228 Phone phone = getPhone(subId);
7229 if (phone != null) {
7230 phone.setDataRoamingEnabled(isEnabled);
7231 }
7232 } finally {
7233 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007234 }
7235 }
7236
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007237 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007238 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007239 TelephonyPermissions
7240 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007241 mApp, subId, "isManualNetworkSelectionAllowed");
7242
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007243 boolean isAllowed = true;
7244 final long identity = Binder.clearCallingIdentity();
7245 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007246 Phone phone = getPhone(subId);
7247 if (phone != null) {
7248 isAllowed = phone.isCspPlmnEnabled();
7249 }
7250 } finally {
7251 Binder.restoreCallingIdentity(identity);
7252 }
7253 return isAllowed;
7254 }
7255
7256 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007257 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007258 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007259 try {
7260 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007261 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007262 } catch (SecurityException e) {
7263 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7264 // has carrier privileges on an active UICC
7265 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7266 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007267 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007268 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007269 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007270
7271 final long identity = Binder.clearCallingIdentity();
7272 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007273 UiccController uiccController = UiccController.getInstance();
7274 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007275 if (hasReadPermission) {
7276 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007277 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007278
7279 // Remove private info if the caller doesn't have access
7280 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7281 for (UiccCardInfo cardInfo : cardInfos) {
7282 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7283 // is available
7284 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7285 if (card == null || card.getUiccProfile() == null) {
7286 // assume no access if the card or profile is unavailable
7287 filteredInfos.add(cardInfo.getUnprivileged());
7288 continue;
7289 }
7290 UiccProfile profile = card.getUiccProfile();
7291 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7292 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7293 filteredInfos.add(cardInfo);
7294 } else {
7295 filteredInfos.add(cardInfo.getUnprivileged());
7296 }
7297 }
7298 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007299 } finally {
7300 Binder.restoreCallingIdentity(identity);
7301 }
7302 }
7303
7304 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007305 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007306 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007307
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007308 final long identity = Binder.clearCallingIdentity();
7309 try {
7310 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7311 if (slots == null) {
7312 Rlog.i(LOG_TAG, "slots is null.");
7313 return null;
7314 }
7315
7316 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7317 for (int i = 0; i < slots.length; i++) {
7318 UiccSlot slot = slots[i];
7319 if (slot == null) {
7320 continue;
7321 }
7322
Jordan Liu7be7e652019-05-06 18:55:02 +00007323 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007324 UiccCard card = slot.getUiccCard();
7325 if (card != null) {
7326 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007327 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007328 cardId = slot.getEid();
7329 if (TextUtils.isEmpty(cardId)) {
7330 cardId = slot.getIccId();
7331 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007332 }
7333
Jordan Liu857451f2019-05-09 16:35:35 -07007334 if (cardId != null) {
7335 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7336 // if cardId is an EID, it's all digits so this is fine
7337 cardId = IccUtils.stripTrailingFs(cardId);
7338 }
7339
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007340 int cardState = 0;
7341 switch (slot.getCardState()) {
7342 case CARDSTATE_ABSENT:
7343 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7344 break;
7345 case CARDSTATE_PRESENT:
7346 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7347 break;
7348 case CARDSTATE_ERROR:
7349 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7350 break;
7351 case CARDSTATE_RESTRICTED:
7352 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7353 break;
7354 default:
7355 break;
7356
7357 }
7358
7359 infos[i] = new UiccSlotInfo(
7360 slot.isActive(),
7361 slot.isEuicc(),
7362 cardId,
7363 cardState,
7364 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007365 slot.isExtendedApduSupported(),
7366 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007367 }
7368 return infos;
7369 } finally {
7370 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007371 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007372 }
7373
7374 @Override
7375 public boolean switchSlots(int[] physicalSlots) {
7376 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007377
7378 final long identity = Binder.clearCallingIdentity();
7379 try {
7380 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7381 } finally {
7382 Binder.restoreCallingIdentity(identity);
7383 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007384 }
Jack Yu4c988042018-02-27 15:30:01 -08007385
7386 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007387 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007388 final long identity = Binder.clearCallingIdentity();
7389 try {
7390 return UiccController.getInstance().getCardIdForDefaultEuicc();
7391 } finally {
7392 Binder.restoreCallingIdentity(identity);
7393 }
7394 }
7395
7396 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007397 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7398 enforceModifyPermission();
7399 final Phone phone = getPhone(subId);
7400 if (phone == null) {
7401 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7402 return;
7403 }
7404
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007405 final long identity = Binder.clearCallingIdentity();
7406 try {
7407 phone.setRadioIndicationUpdateMode(filters, mode);
7408 } finally {
7409 Binder.restoreCallingIdentity(identity);
7410 }
Jack Yu4c988042018-02-27 15:30:01 -08007411 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007412
7413 /**
goneil47ffb6e2018-04-06 15:40:58 -07007414 * A test API to reload the UICC profile.
7415 *
7416 * <p>Requires that the calling app has permission
7417 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7418 * @hide
7419 */
7420 @Override
7421 public void refreshUiccProfile(int subId) {
7422 enforceModifyPermission();
7423
7424 final long identity = Binder.clearCallingIdentity();
7425 try {
7426 Phone phone = getPhone(subId);
7427 if (phone == null) {
7428 return;
7429 }
7430 UiccCard uiccCard = phone.getUiccCard();
7431 if (uiccCard == null) {
7432 return;
7433 }
7434 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7435 if (uiccProfile == null) {
7436 return;
7437 }
7438 uiccProfile.refresh();
7439 } finally {
7440 Binder.restoreCallingIdentity(identity);
7441 }
7442 }
7443
7444 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007445 * Returns false if the mobile data is disabled by default, otherwise return true.
7446 */
7447 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007448 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007449 }
7450
7451 /**
7452 * Returns true if the data roaming is enabled by default, i.e the system property
7453 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7454 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7455 */
7456 private boolean getDefaultDataRoamingEnabled(int subId) {
7457 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007458 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007459 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007460 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7461 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7462 return isDataRoamingEnabled;
7463 }
7464
7465 /**
7466 * Returns the default network type for the given {@code subId}, if the default network type is
7467 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7468 */
7469 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007470 List<Integer> list = TelephonyProperties.default_network();
7471 int phoneId = mSubscriptionController.getPhoneId(subId);
7472 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7473 return list.get(phoneId);
7474 }
7475 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007476 }
fionaxua13278b2018-03-21 00:08:13 -07007477
7478 @Override
7479 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007480 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007481 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007482
7483 final long identity = Binder.clearCallingIdentity();
7484 try {
7485 final Phone phone = getPhone(subId);
7486 if (phone == null) {
7487 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7488 return;
7489 }
chen xueaba88a2019-03-15 13:15:10 -07007490 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7491 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007492 } finally {
7493 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007494 }
fionaxua13278b2018-03-21 00:08:13 -07007495 }
7496
7497 @Override
7498 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007499 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007500
7501 final long identity = Binder.clearCallingIdentity();
7502 try {
7503 final Phone phone = getPhone(subId);
7504 if (phone == null) {
7505 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7506 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7507 }
7508 return phone.getCarrierIdListVersion();
7509 } finally {
7510 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007511 }
fionaxua13278b2018-03-21 00:08:13 -07007512 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007513
7514 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007515 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7516 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007517 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007518 mApp, subId, callingPackage, callingFeatureId,
7519 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007520 return -1;
7521 }
7522
7523 final long identity = Binder.clearCallingIdentity();
7524 try {
7525 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7526 } finally {
7527 Binder.restoreCallingIdentity(identity);
7528 }
7529 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007530
7531 @Override
7532 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007533 TelephonyPermissions
7534 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007535 mApp, subId, "getCdmaRoamingMode");
7536
7537 final long identity = Binder.clearCallingIdentity();
7538 try {
7539 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7540 } finally {
7541 Binder.restoreCallingIdentity(identity);
7542 }
7543 }
7544
7545 @Override
7546 public boolean setCdmaRoamingMode(int subId, int mode) {
7547 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7548 mApp, subId, "setCdmaRoamingMode");
7549
7550 final long identity = Binder.clearCallingIdentity();
7551 try {
7552 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7553 } finally {
7554 Binder.restoreCallingIdentity(identity);
7555 }
7556 }
7557
7558 @Override
7559 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7561 mApp, subId, "setCdmaSubscriptionMode");
7562
7563 final long identity = Binder.clearCallingIdentity();
7564 try {
7565 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7566 } finally {
7567 Binder.restoreCallingIdentity(identity);
7568 }
7569 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007570
sqianc5eccab2018-10-19 18:46:41 -07007571 @Override
sqian8c685422019-02-22 15:55:18 -08007572 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007573 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007574 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007575 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7576 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007577 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7578 }
7579 final long identity = Binder.clearCallingIdentity();
7580 try {
sqian854d44b2018-12-12 16:48:18 -08007581 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7582 for (Phone phone: PhoneFactory.getPhones()) {
7583 if (phone.getEmergencyNumberTracker() != null
7584 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7585 emergencyNumberListInternal.put(
7586 phone.getSubId(),
7587 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7588 }
sqian11b7a0e2018-12-05 18:48:28 -08007589 }
sqian854d44b2018-12-12 16:48:18 -08007590 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007591 } finally {
7592 Binder.restoreCallingIdentity(identity);
7593 }
sqianc5eccab2018-10-19 18:46:41 -07007594 }
7595
7596 @Override
sqian8c685422019-02-22 15:55:18 -08007597 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007598 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007599 if (!exactMatch) {
7600 TelephonyPermissions
7601 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007602 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007603 }
7604 final long identity = Binder.clearCallingIdentity();
7605 try {
sqian854d44b2018-12-12 16:48:18 -08007606 for (Phone phone: PhoneFactory.getPhones()) {
7607 if (phone.getEmergencyNumberTracker() != null
7608 && phone.getEmergencyNumberTracker() != null) {
7609 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7610 number, exactMatch)) {
7611 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007612 }
7613 }
sqian11b7a0e2018-12-05 18:48:28 -08007614 }
7615 return false;
7616 } finally {
7617 Binder.restoreCallingIdentity(identity);
7618 }
7619 }
7620
sqianf4ca7ed2019-01-15 18:32:07 -08007621 /**
7622 * Update emergency number list for test mode.
7623 */
7624 @Override
7625 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7626 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7627 "updateEmergencyNumberListTestMode");
7628
7629 final long identity = Binder.clearCallingIdentity();
7630 try {
7631 for (Phone phone: PhoneFactory.getPhones()) {
7632 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7633 if (tracker != null) {
7634 tracker.executeEmergencyNumberTestModeCommand(action, num);
7635 }
7636 }
7637 } finally {
7638 Binder.restoreCallingIdentity(identity);
7639 }
7640 }
7641
7642 /**
7643 * Get the full emergency number list for test mode.
7644 */
7645 @Override
7646 public List<String> getEmergencyNumberListTestMode() {
7647 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7648 "getEmergencyNumberListTestMode");
7649
7650 final long identity = Binder.clearCallingIdentity();
7651 try {
7652 Set<String> emergencyNumbers = new HashSet<>();
7653 for (Phone phone: PhoneFactory.getPhones()) {
7654 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7655 if (tracker != null) {
7656 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7657 emergencyNumbers.add(num.getNumber());
7658 }
7659 }
7660 }
7661 return new ArrayList<>(emergencyNumbers);
7662 } finally {
7663 Binder.restoreCallingIdentity(identity);
7664 }
7665 }
7666
chen xud6b45bd2018-10-30 22:27:10 -07007667 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007668 public int getEmergencyNumberDbVersion(int subId) {
7669 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7670
7671 final long identity = Binder.clearCallingIdentity();
7672 try {
7673 final Phone phone = getPhone(subId);
7674 if (phone == null) {
7675 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7676 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7677 }
7678 return phone.getEmergencyNumberDbVersion();
7679 } finally {
7680 Binder.restoreCallingIdentity(identity);
7681 }
7682 }
7683
7684 @Override
7685 public void notifyOtaEmergencyNumberDbInstalled() {
7686 enforceModifyPermission();
7687
7688 final long identity = Binder.clearCallingIdentity();
7689 try {
7690 for (Phone phone: PhoneFactory.getPhones()) {
7691 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7692 if (tracker != null) {
7693 tracker.updateOtaEmergencyNumberDatabase();
7694 }
7695 }
7696 } finally {
7697 Binder.restoreCallingIdentity(identity);
7698 }
7699 }
7700
7701 @Override
7702 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7703 enforceActiveEmergencySessionPermission();
7704
7705 final long identity = Binder.clearCallingIdentity();
7706 try {
7707 for (Phone phone: PhoneFactory.getPhones()) {
7708 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7709 if (tracker != null) {
7710 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7711 }
7712 }
7713 } finally {
7714 Binder.restoreCallingIdentity(identity);
7715 }
7716 }
7717
7718 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007719 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7720 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7721 Phone phone = getPhone(subId);
7722 if (phone == null) {
7723 return null;
7724 }
7725 final long identity = Binder.clearCallingIdentity();
7726 try {
7727 UiccProfile profile = UiccController.getInstance()
7728 .getUiccProfileForPhone(phone.getPhoneId());
7729 if (profile != null) {
7730 return profile.getCertsFromCarrierPrivilegeAccessRules();
7731 }
7732 } finally {
7733 Binder.restoreCallingIdentity(identity);
7734 }
7735 return null;
7736 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007737
7738 /**
7739 * Enable or disable a modem stack.
7740 */
7741 @Override
7742 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7743 enforceModifyPermission();
7744
7745 final long identity = Binder.clearCallingIdentity();
7746 try {
7747 Phone phone = PhoneFactory.getPhone(slotIndex);
7748 if (phone == null) {
7749 return false;
7750 } else {
7751 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7752 }
7753 } finally {
7754 Binder.restoreCallingIdentity(identity);
7755 }
7756 }
Michelecea4cf22018-12-21 15:00:11 -08007757
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007758 /**
7759 * Whether a modem stack is enabled or not.
7760 */
7761 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007762 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7763 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007764 Phone phone = PhoneFactory.getPhone(slotIndex);
7765 if (phone == null) return false;
7766
7767 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007768 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7769 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007770 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7771 }
7772
7773 final long identity = Binder.clearCallingIdentity();
7774 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007775 try {
7776 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7777 } catch (NoSuchElementException ex) {
7778 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7779 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007780 } finally {
7781 Binder.restoreCallingIdentity(identity);
7782 }
7783 }
7784
Michelecea4cf22018-12-21 15:00:11 -08007785 @Override
Michele0ea7d782019-03-19 14:58:42 -07007786 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007787 enforceModifyPermission();
7788
7789 final long identity = Binder.clearCallingIdentity();
7790 try {
7791 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007792 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007793 .commit();
7794 } finally {
7795 Binder.restoreCallingIdentity(identity);
7796 }
7797 }
7798
7799 @Override
Michele0ea7d782019-03-19 14:58:42 -07007800 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007801 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007802 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007803 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7804 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007805 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007806 }
Michelecea4cf22018-12-21 15:00:11 -08007807
7808 final long identity = Binder.clearCallingIdentity();
7809 try {
Michele0ea7d782019-03-19 14:58:42 -07007810 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007811 } finally {
7812 Binder.restoreCallingIdentity(identity);
7813 }
7814 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007815
Michele0ea7d782019-03-19 14:58:42 -07007816 @TelephonyManager.IsMultiSimSupportedResult
7817 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007818 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7819 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7820 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007821 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7822 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007823 }
7824 // Check if the hardware supports multisim functionality. If usage of multisim is not
7825 // supported by the modem, indicate that it is restricted.
7826 PhoneCapability staticCapability =
7827 mPhoneConfigurationManager.getStaticPhoneCapability();
7828 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007829 loge("isMultiSimSupportedInternal: no static configuration available");
7830 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007831 }
Sarah Chin0605abf2019-12-06 10:24:18 -08007832 if (staticCapability.getLogicalModemUuids().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007833 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7834 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007835 }
7836 // Check if support of multiple SIMs is restricted by carrier
7837 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007838 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007839 }
7840
Michele0ea7d782019-03-19 14:58:42 -07007841 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007842 }
7843
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007844 /**
7845 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007846 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7847 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7848 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007849 * @param numOfSims number of active sims we want to switch to
7850 */
7851 @Override
7852 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007853 if (numOfSims == 1) {
7854 enforceModifyPermission();
7855 } else {
7856 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7857 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7858 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007859 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007860
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007861 try {
Michele30b57b22019-03-01 12:01:14 -08007862 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007863 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007864 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7865 return;
7866 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007867 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7868 } finally {
7869 Binder.restoreCallingIdentity(identity);
7870 }
7871 }
7872
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007873 @Override
7874 public boolean isApplicationOnUicc(int subId, int appType) {
7875 enforceReadPrivilegedPermission("isApplicationOnUicc");
7876 Phone phone = getPhone(subId);
7877 if (phone == null) {
7878 return false;
7879 }
7880 final long identity = Binder.clearCallingIdentity();
7881 try {
7882 UiccCard uiccCard = phone.getUiccCard();
7883 if (uiccCard == null) {
7884 return false;
7885 }
7886 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7887 if (uiccProfile == null) {
7888 return false;
7889 }
7890 if (TelephonyManager.APPTYPE_SIM <= appType
7891 && appType <= TelephonyManager.APPTYPE_ISIM) {
7892 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7893 }
7894 return false;
7895 } finally {
7896 Binder.restoreCallingIdentity(identity);
7897 }
7898 }
7899
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007900 /**
chen xub4baa772019-04-03 10:23:41 -07007901 * Get whether making changes to modem configurations will trigger reboot.
7902 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007903 */
7904 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007905 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7906 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007907 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007908 mApp, subId, callingPackage, callingFeatureId,
7909 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007910 return false;
7911 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007912 final long identity = Binder.clearCallingIdentity();
7913 try {
7914 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7915 } finally {
7916 Binder.restoreCallingIdentity(identity);
7917 }
7918 }
7919
Nathan Harold29f5f052019-02-15 13:41:57 -08007920 private void updateModemStateMetrics() {
7921 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7922 // TODO: check the state for each modem if the api is ready.
7923 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7924 }
7925
Pengquan Meng3889a572019-01-23 11:16:29 -08007926 @Override
7927 public int[] getSlotsMapping() {
7928 enforceReadPrivilegedPermission("getSlotsMapping");
7929
7930 final long identity = Binder.clearCallingIdentity();
7931 try {
7932 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7933 // All logical slots should have a mapping to a physical slot.
7934 int[] logicalSlotsMapping = new int[phoneCount];
7935 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7936 for (int i = 0; i < slotInfos.length; i++) {
7937 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7938 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7939 }
7940 }
7941 return logicalSlotsMapping;
7942 } finally {
7943 Binder.restoreCallingIdentity(identity);
7944 }
7945 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007946
7947 /**
7948 * Get the IRadio HAL Version
7949 */
7950 @Override
7951 public int getRadioHalVersion() {
7952 Phone phone = getDefaultPhone();
7953 if (phone == null) return -1;
7954 HalVersion hv = phone.getHalVersion();
7955 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7956 return hv.major * 100 + hv.minor;
7957 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007958
7959 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08007960 * Get the current calling package name.
7961 * @return the current calling package name
7962 */
7963 @Override
7964 public String getCurrentPackageName() {
7965 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
7966 }
7967
7968 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007969 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7970 * corresponding network requests on a subId.
7971 *
7972 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007973 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007974 * 2) APN is un-metered for this subscription, or
7975 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08007976 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07007977 *
7978 * @return whether data is allowed for a apn type.
7979 *
7980 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007981 */
7982 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007983 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007984 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7985 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007986
7987 // Now that all security checks passes, perform the operation as ourselves.
7988 final long identity = Binder.clearCallingIdentity();
7989 try {
7990 Phone phone = getPhone(subId);
7991 if (phone == null) return false;
7992
Jack Yu41407ee2019-05-13 16:54:09 -07007993 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007994 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7995 } finally {
7996 Binder.restoreCallingIdentity(identity);
7997 }
7998 }
7999
8000 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008001 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008002 enforceReadPrivilegedPermission("isApnMetered");
8003
8004 // Now that all security checks passes, perform the operation as ourselves.
8005 final long identity = Binder.clearCallingIdentity();
8006 try {
8007 Phone phone = getPhone(subId);
8008 if (phone == null) return true; // By default return true.
8009
Jack Yu41407ee2019-05-13 16:54:09 -07008010 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008011 } finally {
8012 Binder.restoreCallingIdentity(identity);
8013 }
8014 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008015
8016 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008017 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8018 int subscriptionId, IBooleanConsumer resultCallback) {
8019 enforceModifyPermission();
8020 long token = Binder.clearCallingIdentity();
8021 try {
8022 Phone phone = getPhone(subscriptionId);
8023 if (phone == null) {
8024 try {
8025 if (resultCallback != null) {
8026 resultCallback.accept(false);
8027 }
8028 } catch (RemoteException e) {
8029 // ignore
8030 }
8031 return;
8032 }
8033 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8034 Pair.create(specifiers, (x) -> {
8035 try {
8036 if (resultCallback != null) {
8037 resultCallback.accept(x);
8038 }
8039 } catch (RemoteException e) {
8040 // ignore
8041 }
8042 });
8043 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8044 } finally {
8045 Binder.restoreCallingIdentity(token);
8046 }
8047 }
8048
8049 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008050 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8051 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8052 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8053 if (iccRecords == null) {
8054 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8055 return false;
8056 }
8057 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8058 }
8059
8060 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07008061 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008062 if (callingPackage == null) {
8063 callingPackage = getCurrentPackageName();
8064 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008065 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8066 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
8067 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
8068 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8069 }
8070 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8071 Intent intent = new Intent();
8072 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8073 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8074 // Bring up choose default SMS subscription dialog right now
8075 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8076 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8077 mApp.startActivity(intent);
8078 }
chen xud5ca2d52019-05-28 15:20:57 -07008079
8080 @Override
8081 public String getMmsUAProfUrl(int subId) {
8082 //TODO investigate if this API should require proper permission check in R b/133791609
8083 final long identity = Binder.clearCallingIdentity();
8084 try {
8085 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8086 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8087 } finally {
8088 Binder.restoreCallingIdentity(identity);
8089 }
8090 }
8091
8092 @Override
8093 public String getMmsUserAgent(int subId) {
8094 //TODO investigate if this API should require proper permission check in R b/133791609
8095 final long identity = Binder.clearCallingIdentity();
8096 try {
8097 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8098 .getString(com.android.internal.R.string.config_mms_user_agent);
8099 } finally {
8100 Binder.restoreCallingIdentity(identity);
8101 }
8102 }
Jack Yub07d4972019-05-28 16:12:25 -07008103
8104 @Override
8105 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8106 enforceModifyPermission();
8107
8108 // Now that all security checks passes, perform the operation as ourselves.
8109 final long identity = Binder.clearCallingIdentity();
8110 try {
8111 Phone phone = getPhone(subId);
8112 if (phone == null) return false;
8113
8114 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8115 } finally {
8116 Binder.restoreCallingIdentity(identity);
8117 }
8118 }
8119
8120 @Override
8121 public boolean isDataAllowedInVoiceCall(int subId) {
8122 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8123
8124 // Now that all security checks passes, perform the operation as ourselves.
8125 final long identity = Binder.clearCallingIdentity();
8126 try {
8127 Phone phone = getPhone(subId);
8128 if (phone == null) return false;
8129
8130 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8131 } finally {
8132 Binder.restoreCallingIdentity(identity);
8133 }
8134 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008135
changbettyd5c246e2019-12-24 15:40:37 +08008136 @Override
8137 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8138 enforceModifyPermission();
8139
8140 // Now that all security checks passes, perform the operation as ourselves.
8141 final long identity = Binder.clearCallingIdentity();
8142 try {
8143 Phone phone = getPhone(subId);
8144 if (phone == null) return false;
8145
8146 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8147 } finally {
8148 Binder.restoreCallingIdentity(identity);
8149 }
8150 }
8151
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008152 /**
8153 * Updates whether conference event pacakge handling is enabled.
8154 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8155 * otherwise.
8156 */
8157 @Override
8158 public void setCepEnabled(boolean isCepEnabled) {
8159 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8160
8161 final long identity = Binder.clearCallingIdentity();
8162 try {
8163 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8164 for (Phone phone : PhoneFactory.getPhones()) {
8165 Phone defaultPhone = phone.getImsPhone();
8166 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8167 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8168 ImsPhoneCallTracker imsPhoneCallTracker =
8169 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8170 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8171 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8172 + imsPhone.getMsisdn());
8173 }
8174 }
8175 } finally {
8176 Binder.restoreCallingIdentity(identity);
8177 }
8178 }
allenwtsu46dcc572020-01-08 18:24:03 +08008179
8180 /**
8181 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8182 *
8183 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8184 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8185 * before being read.
8186 */
8187 @Override
8188 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8189 isCompressed) {
8190 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8191 mApp, subId, "notifyRcsAutoConfigurationReceived");
8192 try {
8193 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8194 if (configBinder == null) {
8195 Rlog.e(LOG_TAG, "null result for getImsConfig");
8196 } else {
8197 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8198 }
8199 } catch (RemoteException e) {
8200 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8201 }
8202 }
zoey chene02881a2019-12-30 16:11:23 +08008203
8204 @Override
8205 public boolean isIccLockEnabled(int subId) {
8206 enforceReadPrivilegedPermission("isIccLockEnabled");
8207
8208 // Now that all security checks passes, perform the operation as ourselves.
8209 final long identity = Binder.clearCallingIdentity();
8210 try {
8211 Phone phone = getPhone(subId);
8212 if (phone != null && phone.getIccCard() != null) {
8213 return phone.getIccCard().getIccLockEnabled();
8214 } else {
8215 return false;
8216 }
8217 } finally {
8218 Binder.restoreCallingIdentity(identity);
8219 }
8220 }
8221
8222 /**
8223 * Set the ICC pin lock enabled or disabled.
8224 *
8225 * @return an integer representing the status of IccLock enabled or disabled in the following
8226 * three cases:
8227 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8228 * successfully.
8229 * - Positive number and zero for remaining password attempts.
8230 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8231 *
8232 */
8233 @Override
8234 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8235 enforceModifyPermission();
8236
8237 Phone phone = getPhone(subId);
8238 if (phone == null) {
8239 return 0;
8240 }
8241 // Now that all security checks passes, perform the operation as ourselves.
8242 final long identity = Binder.clearCallingIdentity();
8243 try {
8244 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8245 new Pair<Boolean, String>(enabled, password), phone, null);
8246 return attemptsRemaining;
8247
8248 } catch (Exception e) {
8249 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8250 } finally {
8251 Binder.restoreCallingIdentity(identity);
8252 }
8253 return 0;
8254 }
8255
8256 /**
8257 * Change the ICC password used in ICC pin lock.
8258 *
8259 * @return an integer representing the status of IccLock changed in the following three cases:
8260 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8261 * - Positive number and zero for remaining password attempts.
8262 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8263 *
8264 */
8265 @Override
8266 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8267 enforceModifyPermission();
8268
8269 Phone phone = getPhone(subId);
8270 if (phone == null) {
8271 return 0;
8272 }
8273 // Now that all security checks passes, perform the operation as ourselves.
8274 final long identity = Binder.clearCallingIdentity();
8275 try {
8276 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8277 new Pair<String, String>(oldPassword, newPassword), phone, null);
8278 return attemptsRemaining;
8279
8280 } catch (Exception e) {
8281 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8282 } finally {
8283 Binder.restoreCallingIdentity(identity);
8284 }
8285 return 0;
8286 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008287
8288 /**
8289 * Request for receiving user activity notification
8290 */
8291 @Override
8292 public void requestUserActivityNotification() {
8293 if (!mNotifyUserActivity.get()
8294 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8295 mNotifyUserActivity.set(true);
8296 }
8297 }
8298
8299 /**
8300 * Called when userActivity is signalled in the power manager.
8301 * This is safe to call from any thread, with any window manager locks held or not.
8302 */
8303 @Override
8304 public void userActivity() {
8305 // ***************************************
8306 // * Inherited from PhoneWindowManager *
8307 // ***************************************
8308 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8309 // WITH ITS LOCKS HELD.
8310 //
8311 // This code must be VERY careful about the locks
8312 // it acquires.
8313 // In fact, the current code acquires way too many,
8314 // and probably has lurking deadlocks.
8315
8316 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8317 throw new SecurityException("Only the OS may call notifyUserActivity()");
8318 }
8319
8320 if (mNotifyUserActivity.getAndSet(false)) {
8321 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8322 USER_ACTIVITY_NOTIFICATION_DELAY);
8323 }
8324 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008325}