blob: 4eb1788152f39fd502130a48a772eb09700ed0ed [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
changbetty363e8ac2019-12-06 18:16:37 +080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070038import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.net.Uri;
40import android.os.AsyncResult;
41import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080042import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.os.Bundle;
44import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070045import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.Looper;
47import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070048import android.os.Messenger;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070055import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070056import android.os.ShellCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070058import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070059import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070060import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070061import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080062import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070063import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090064import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080065import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080066import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070067import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070068import android.telephony.Annotation.ApnType;
sqian80370722020-01-29 15:02:51 -080069import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070070import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080071import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070072import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080073import android.telephony.CellIdentityCdma;
74import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070076import android.telephony.CellInfoGsm;
77import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070078import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070079import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070080import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080081import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070082import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080083import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070084import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080085import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080086import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070087import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080088import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080090import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080091import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080092import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070093import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070094import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080095import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080096import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000097import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070098import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070099import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800100import android.telephony.data.ApnSetting;
101import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700102import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800103import android.telephony.ims.ProvisioningManager;
Brad Ebinger774ba362019-10-22 17:36:18 -0700104import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700105import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800106import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700107import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800108import android.telephony.ims.aidl.IImsMmTelFeature;
109import android.telephony.ims.aidl.IImsRcsFeature;
110import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700111import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700112import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800113import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800114import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800115import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800116import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800118import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800120import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800121import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800122
Andrew Lee312e8172014-10-23 17:01:36 -0700123import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800124import com.android.ims.internal.IImsServiceFeatureCallback;
sqian80370722020-01-29 15:02:51 -0800125import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700126import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700127import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700128import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800129import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700130import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700131import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800132import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800134import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700135import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800136import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800138import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700139import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700140import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700141import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700143import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800144import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700145import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700146import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700147import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700148import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700149import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700150import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700151import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700152import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800153import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800154import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700155import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800156import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700157import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800158import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700159import com.android.internal.telephony.imsphone.ImsPhone;
160import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800161import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900162import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800164import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700165import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800166import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700167import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800168import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700169import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800170import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000171import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800172import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700173import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800174import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700175import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700176import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800177import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700178import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700179import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang050bb052020-01-13 23:33:09 -0800180import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800181
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700182import java.io.FileDescriptor;
183import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700184import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800185import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800186import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800187import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800188import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100189import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800190import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700191import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800192import java.util.Set;
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 zhaod698b842019-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 Nalluri8ff344d2019-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 chenf95ca592019-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;
sqian80370722020-01-29 15:02:51 -0800278 private static final int CMD_GET_CALL_FORWARDING = 83;
279 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
280 private static final int CMD_SET_CALL_FORWARDING = 85;
281 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
282 private static final int CMD_GET_CALL_WAITING = 87;
283 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
284 private static final int CMD_SET_CALL_WAITING = 89;
285 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700286
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800287 // Parameters of select command.
288 private static final int SELECT_COMMAND = 0xA4;
289 private static final int SELECT_P1 = 0x04;
290 private static final int SELECT_P2 = 0;
291 private static final int SELECT_P3 = 0x10;
292
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700293 /** The singleton instance. */
294 private static PhoneInterfaceManager sInstance;
295
Wink Saville3ab207e2014-11-20 13:07:20 -0800296 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800297 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800298 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700299 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800300 private AppOpsManager mAppOps;
301 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800302 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800303 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700304 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700305
Derek Tan97ebb422014-09-05 16:55:38 -0700306 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
307 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800308 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800309 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700310
Michelecea4cf22018-12-21 15:00:11 -0800311 // String to store multi SIM allowed
312 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
313
Derek Tan740e1672017-06-27 14:56:27 -0700314 // The AID of ISD-R.
315 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
316
yinxub1bed742017-04-17 11:45:04 -0700317 private NetworkScanRequestTracker mNetworkScanRequestTracker;
318
David Kelly5e06a7f2018-03-12 14:10:59 +0000319 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
320 private static final int MANUFACTURER_CODE_LENGTH = 8;
321
Derek Tan89e89d42014-07-08 17:00:10 -0700322 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700323 * Experiment flag to enable erase modem config on reset network, default value is false
324 */
325 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
326 "reset_network_erase_modem_config_enabled";
327
328 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700329 * A request object to use for transmitting data to an ICC.
330 */
331 private static final class IccAPDUArgument {
332 public int channel, cla, command, p1, p2, p3;
333 public String data;
334
335 public IccAPDUArgument(int channel, int cla, int command,
336 int p1, int p2, int p3, String data) {
337 this.channel = channel;
338 this.cla = cla;
339 this.command = command;
340 this.p1 = p1;
341 this.p2 = p2;
342 this.p3 = p3;
343 this.data = data;
344 }
345 }
346
347 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700348 * A request object to use for transmitting data to an ICC.
349 */
350 private static final class ManualNetworkSelectionArgument {
351 public OperatorInfo operatorInfo;
352 public boolean persistSelection;
353
354 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
355 this.operatorInfo = operatorInfo;
356 this.persistSelection = persistSelection;
357 }
358 }
359
360 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
362 * request after sending. The main thread will notify the request when it is complete.
363 */
364 private static final class MainThreadRequest {
365 /** The argument to use for the request */
366 public Object argument;
367 /** The result of the request that is run on the main thread */
368 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800369 // The subscriber id that this request applies to. Defaults to
370 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
371 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372
Nathan Harold92bed182018-10-12 18:16:49 -0700373 // In cases where subId is unavailable, the caller needs to specify the phone.
374 public Phone phone;
375
vagdeviaf9a5b92018-08-15 16:01:53 -0700376 public WorkSource workSource;
377
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700378 public MainThreadRequest(Object argument) {
379 this.argument = argument;
380 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800381
Nathan Harold92bed182018-10-12 18:16:49 -0700382 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
383 this.argument = argument;
384 if (phone != null) {
385 this.phone = phone;
386 }
387 this.workSource = workSource;
388 }
389
vagdeviaf9a5b92018-08-15 16:01:53 -0700390 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800391 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800392 if (subId != null) {
393 this.subId = subId;
394 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700395 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800396 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397 }
398
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800399 private static final class IncomingThirdPartyCallArgs {
400 public final ComponentName component;
401 public final String callId;
402 public final String callerDisplayName;
403
404 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
405 String callerDisplayName) {
406 this.component = component;
407 this.callId = callId;
408 this.callerDisplayName = callerDisplayName;
409 }
410 }
411
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700412 /**
413 * A handler that processes messages on the main thread in the phone process. Since many
414 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
415 * inbound binder threads to the main thread in the phone process. The Binder thread
416 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
417 * on, which will be notified when the operation completes and will contain the result of the
418 * request.
419 *
420 * <p>If a MainThreadRequest object is provided in the msg.obj field,
421 * note that request.result must be set to something non-null for the calling thread to
422 * unblock.
423 */
424 private final class MainThreadHandler extends Handler {
425 @Override
426 public void handleMessage(Message msg) {
427 MainThreadRequest request;
428 Message onCompleted;
429 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800430 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700431 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800432 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700433
434 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700435 case CMD_HANDLE_USSD_REQUEST: {
436 request = (MainThreadRequest) msg.obj;
437 final Phone phone = getPhoneFromRequest(request);
438 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
439 String ussdRequest = ussdObject.first;
440 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700441
Pengquan Menga1bb6272018-09-06 09:59:22 -0700442 if (!isUssdApiAllowed(request.subId)) {
443 // Carrier does not support use of this API, return failure.
444 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
445 UssdResponse response = new UssdResponse(ussdRequest, null);
446 Bundle returnData = new Bundle();
447 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
448 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700449
Pengquan Menga1bb6272018-09-06 09:59:22 -0700450 request.result = true;
451 notifyRequester(request);
452 return;
453 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700454
Pengquan Menga1bb6272018-09-06 09:59:22 -0700455 try {
456 request.result = phone != null
457 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
458 } catch (CallStateException cse) {
459 request.result = false;
460 }
461 // Wake up the requesting thread
462 notifyRequester(request);
463 break;
pkanwar32d516d2016-10-14 19:37:38 -0700464 }
465
Yorke Lee716f67e2015-06-17 15:39:16 -0700466 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700467 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700468 final Phone phone = getPhoneFromRequest(request);
469 request.result = phone != null ?
470 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
471 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700472 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700473 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700474 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700475 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700476
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700477 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700478 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700479 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800480 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700481 if (uiccCard == null) {
482 loge("iccTransmitApduLogicalChannel: No UICC");
483 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700484 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700485 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700486 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
487 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700488 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 iccArgument.channel, iccArgument.cla, iccArgument.command,
490 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700491 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700492 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700493 break;
494
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700495 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700496 ar = (AsyncResult) msg.obj;
497 request = (MainThreadRequest) ar.userObj;
498 if (ar.exception == null && ar.result != null) {
499 request.result = ar.result;
500 } else {
501 request.result = new IccIoResult(0x6F, 0, (byte[])null);
502 if (ar.result == null) {
503 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800504 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700505 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800506 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700507 } else {
508 loge("iccTransmitApduLogicalChannel: Unknown exception");
509 }
510 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700511 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700512 break;
513
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700514 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
515 request = (MainThreadRequest) msg.obj;
516 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800517 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700518 if (uiccCard == null) {
519 loge("iccTransmitApduBasicChannel: No UICC");
520 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700521 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700522 } else {
523 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
524 request);
525 uiccCard.iccTransmitApduBasicChannel(
526 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
527 iccArgument.p3, iccArgument.data, onCompleted);
528 }
529 break;
530
531 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
532 ar = (AsyncResult) msg.obj;
533 request = (MainThreadRequest) ar.userObj;
534 if (ar.exception == null && ar.result != null) {
535 request.result = ar.result;
536 } else {
537 request.result = new IccIoResult(0x6F, 0, (byte[])null);
538 if (ar.result == null) {
539 loge("iccTransmitApduBasicChannel: Empty response");
540 } else if (ar.exception instanceof CommandException) {
541 loge("iccTransmitApduBasicChannel: CommandException: " +
542 ar.exception);
543 } else {
544 loge("iccTransmitApduBasicChannel: Unknown exception");
545 }
546 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700547 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700548 break;
549
550 case CMD_EXCHANGE_SIM_IO:
551 request = (MainThreadRequest) msg.obj;
552 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800553 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700554 if (uiccCard == null) {
555 loge("iccExchangeSimIO: No UICC");
556 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700557 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 } else {
559 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
560 request);
561 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
562 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
563 iccArgument.data, onCompleted);
564 }
565 break;
566
567 case EVENT_EXCHANGE_SIM_IO_DONE:
568 ar = (AsyncResult) msg.obj;
569 request = (MainThreadRequest) ar.userObj;
570 if (ar.exception == null && ar.result != null) {
571 request.result = ar.result;
572 } else {
573 request.result = new IccIoResult(0x6f, 0, (byte[])null);
574 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700575 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700576 break;
577
Derek Tan4d5e5c12014-02-04 11:54:58 -0800578 case CMD_SEND_ENVELOPE:
579 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800580 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700581 if (uiccCard == null) {
582 loge("sendEnvelopeWithStatus: No UICC");
583 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700584 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700585 } else {
586 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
587 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
588 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800589 break;
590
591 case EVENT_SEND_ENVELOPE_DONE:
592 ar = (AsyncResult) msg.obj;
593 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700594 if (ar.exception == null && ar.result != null) {
595 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800596 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700597 request.result = new IccIoResult(0x6F, 0, (byte[])null);
598 if (ar.result == null) {
599 loge("sendEnvelopeWithStatus: Empty response");
600 } else if (ar.exception instanceof CommandException) {
601 loge("sendEnvelopeWithStatus: CommandException: " +
602 ar.exception);
603 } else {
604 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
605 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800606 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700607 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800608 break;
609
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 case CMD_OPEN_CHANNEL:
611 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800612 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800613 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700614 if (uiccCard == null) {
615 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800616 request.result = new IccOpenLogicalChannelResponse(-1,
617 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700618 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700619 } else {
620 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800621 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
622 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700623 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700624 break;
625
626 case EVENT_OPEN_CHANNEL_DONE:
627 ar = (AsyncResult) msg.obj;
628 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700629 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700630 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700631 int[] result = (int[]) ar.result;
632 int channelId = result[0];
633 byte[] selectResponse = null;
634 if (result.length > 1) {
635 selectResponse = new byte[result.length - 1];
636 for (int i = 1; i < result.length; ++i) {
637 selectResponse[i - 1] = (byte) result[i];
638 }
639 }
640 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700641 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700642 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 if (ar.result == null) {
644 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700645 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700646 if (ar.exception != null) {
647 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
648 }
649
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700650 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700651 if (ar.exception instanceof CommandException) {
652 CommandException.Error error =
653 ((CommandException) (ar.exception)).getCommandError();
654 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700655 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700656 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700657 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700658 }
659 }
660 openChannelResp = new IccOpenLogicalChannelResponse(
661 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700663 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700664 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700665 break;
666
667 case CMD_CLOSE_CHANNEL:
668 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800669 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700670 if (uiccCard == null) {
671 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900672 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700673 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700674 } else {
675 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
676 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
677 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 break;
679
680 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800681 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
682 break;
683
684 case CMD_NV_READ_ITEM:
685 request = (MainThreadRequest) msg.obj;
686 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800687 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
688 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800689 break;
690
691 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 ar = (AsyncResult) msg.obj;
693 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800694 if (ar.exception == null && ar.result != null) {
695 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800697 request.result = "";
698 if (ar.result == null) {
699 loge("nvReadItem: Empty response");
700 } else if (ar.exception instanceof CommandException) {
701 loge("nvReadItem: CommandException: " +
702 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700703 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800704 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700705 }
706 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700707 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700708 break;
709
Jake Hambye994d462014-02-03 13:10:13 -0800710 case CMD_NV_WRITE_ITEM:
711 request = (MainThreadRequest) msg.obj;
712 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
713 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800714 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700715 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800716 break;
717
718 case EVENT_NV_WRITE_ITEM_DONE:
719 handleNullReturnEvent(msg, "nvWriteItem");
720 break;
721
722 case CMD_NV_WRITE_CDMA_PRL:
723 request = (MainThreadRequest) msg.obj;
724 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800725 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800726 break;
727
728 case EVENT_NV_WRITE_CDMA_PRL_DONE:
729 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
730 break;
731
chen xu6dac5ab2018-10-26 17:39:23 -0700732 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800733 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700734 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800735 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800736 break;
737
chen xu6dac5ab2018-10-26 17:39:23 -0700738 case EVENT_RESET_MODEM_CONFIG_DONE:
739 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800740 break;
741
Jake Hamby7c27be32014-03-03 13:25:59 -0800742 case CMD_GET_PREFERRED_NETWORK_TYPE:
743 request = (MainThreadRequest) msg.obj;
744 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700745 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800746 break;
747
748 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
749 ar = (AsyncResult) msg.obj;
750 request = (MainThreadRequest) ar.userObj;
751 if (ar.exception == null && ar.result != null) {
752 request.result = ar.result; // Integer
753 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800754 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800755 if (ar.result == null) {
756 loge("getPreferredNetworkType: Empty response");
757 } else if (ar.exception instanceof CommandException) {
758 loge("getPreferredNetworkType: CommandException: " +
759 ar.exception);
760 } else {
761 loge("getPreferredNetworkType: Unknown exception");
762 }
763 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700764 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800765 break;
766
767 case CMD_SET_PREFERRED_NETWORK_TYPE:
768 request = (MainThreadRequest) msg.obj;
769 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
770 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700771 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800772 break;
773
774 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
775 handleNullReturnEvent(msg, "setPreferredNetworkType");
776 break;
777
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000778 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
779 request = (MainThreadRequest)msg.obj;
780 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800781 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000782 break;
783
784 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
785 ar = (AsyncResult)msg.obj;
786 request = (MainThreadRequest)ar.userObj;
787 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700788 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000789 break;
790
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800791 case CMD_SET_VOICEMAIL_NUMBER:
792 request = (MainThreadRequest) msg.obj;
793 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
794 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800795 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
796 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800797 break;
798
799 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
800 handleNullReturnEvent(msg, "setVoicemailNumber");
801 break;
802
Stuart Scott54788802015-03-30 13:18:01 -0700803 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
804 request = (MainThreadRequest) msg.obj;
805 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
806 request);
807 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
808 break;
809
810 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
811 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
812 break;
813
Shishir Agrawal302c8692015-06-19 13:49:39 -0700814 case CMD_PERFORM_NETWORK_SCAN:
815 request = (MainThreadRequest) msg.obj;
816 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
817 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
818 break;
819
sqian80370722020-01-29 15:02:51 -0800820 case CMD_GET_CALL_FORWARDING:
821 request = (MainThreadRequest) msg.obj;
822 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
823 int callForwardingReason = (Integer) request.argument;
824 getPhoneFromRequest(request).getCallForwardingOption(
825 callForwardingReason, onCompleted);
826 break;
827
828 case EVENT_GET_CALL_FORWARDING_DONE:
829 ar = (AsyncResult) msg.obj;
830 request = (MainThreadRequest) ar.userObj;
831 CallForwardingInfo callForwardingInfo = null;
832 if (ar.exception == null && ar.result != null) {
833 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
834 for (CallForwardInfo callForwardInfo : callForwardInfos) {
835 // Service Class is a bit mask per 3gpp 27.007. Search for
836 // any service for voice call.
837 if ((callForwardInfo.serviceClass
838 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
839 callForwardingInfo = new CallForwardingInfo(
840 callForwardInfo.serviceClass, callForwardInfo.reason,
841 callForwardInfo.number,
842 callForwardInfo.timeSeconds);
843 break;
844 }
845 }
846 // Didn't find a call forward info for voice call.
847 if (callForwardingInfo == null) {
848 callForwardingInfo = new CallForwardingInfo(
849 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
850 0 /* reason */, null /* number */, 0 /* timeout */);
851 }
852 } else {
853 if (ar.result == null) {
854 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
855 }
856 if (ar.exception != null) {
857 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
858 }
859 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
860 if (ar.exception instanceof CommandException) {
861 CommandException.Error error =
862 ((CommandException) (ar.exception)).getCommandError();
863 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
864 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
865 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
866 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
867 }
868 }
869 callForwardingInfo = new CallForwardingInfo(
870 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
871 }
872 request.result = callForwardingInfo;
873 notifyRequester(request);
874 break;
875
876 case CMD_SET_CALL_FORWARDING:
877 request = (MainThreadRequest) msg.obj;
878 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
879 CallForwardingInfo callForwardingInfoToSet =
880 (CallForwardingInfo) request.argument;
881 getPhoneFromRequest(request).setCallForwardingOption(
882 callForwardingInfoToSet.getStatus(),
883 callForwardingInfoToSet.getReason(),
884 callForwardingInfoToSet.getNumber(),
885 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
886 break;
887
888 case EVENT_SET_CALL_FORWARDING_DONE:
889 ar = (AsyncResult) msg.obj;
890 request = (MainThreadRequest) ar.userObj;
891 if (ar.exception == null) {
892 request.result = true;
893 } else {
894 request.result = false;
895 loge("setCallForwarding exception: " + ar.exception);
896 }
897 notifyRequester(request);
898 break;
899
900 case CMD_GET_CALL_WAITING:
901 request = (MainThreadRequest) msg.obj;
902 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
903 getPhoneFromRequest(request).getCallWaiting(onCompleted);
904 break;
905
906 case EVENT_GET_CALL_WAITING_DONE:
907 ar = (AsyncResult) msg.obj;
908 request = (MainThreadRequest) ar.userObj;
909 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
910 if (ar.exception == null && ar.result != null) {
911 ArrayList<Integer> callForwardResults = (ArrayList<Integer>) ar.result;
912 // Service Class is a bit mask per 3gpp 27.007.
913 // Search for any service for voice call.
914 if ((callForwardResults.get(1)
915 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
916 callForwardingStatus = callForwardResults.get(0) == 0
917 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
918 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
919 } else {
920 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
921 }
922 } else {
923 if (ar.result == null) {
924 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
925 }
926 if (ar.exception != null) {
927 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
928 }
929 if (ar.exception instanceof CommandException) {
930 CommandException.Error error =
931 ((CommandException) (ar.exception)).getCommandError();
932 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
933 callForwardingStatus =
934 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
935 }
936 }
937 }
938 request.result = callForwardingStatus;
939 notifyRequester(request);
940 break;
941
942 case CMD_SET_CALL_WAITING:
943 request = (MainThreadRequest) msg.obj;
944 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
945 boolean isEnable = (Boolean) request.argument;
946 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
947 break;
948
949 case EVENT_SET_CALL_WAITING_DONE:
950 ar = (AsyncResult) msg.obj;
951 request = (MainThreadRequest) ar.userObj;
952 if (ar.exception == null) {
953 request.result = true;
954 } else {
955 request.result = false;
956 loge("setCallWaiting exception: " + ar.exception);
957 }
958 notifyRequester(request);
959 break;
960
Shishir Agrawal302c8692015-06-19 13:49:39 -0700961 case EVENT_PERFORM_NETWORK_SCAN_DONE:
962 ar = (AsyncResult) msg.obj;
963 request = (MainThreadRequest) ar.userObj;
964 CellNetworkScanResult cellScanResult;
965 if (ar.exception == null && ar.result != null) {
966 cellScanResult = new CellNetworkScanResult(
967 CellNetworkScanResult.STATUS_SUCCESS,
968 (List<OperatorInfo>) ar.result);
969 } else {
970 if (ar.result == null) {
971 loge("getCellNetworkScanResults: Empty response");
972 }
973 if (ar.exception != null) {
974 loge("getCellNetworkScanResults: Exception: " + ar.exception);
975 }
976 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
977 if (ar.exception instanceof CommandException) {
978 CommandException.Error error =
979 ((CommandException) (ar.exception)).getCommandError();
980 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
981 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
982 } else if (error == CommandException.Error.GENERIC_FAILURE) {
983 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
984 }
985 }
986 cellScanResult = new CellNetworkScanResult(errorCode, null);
987 }
988 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700989 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700990 break;
991
992 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
993 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700994 ManualNetworkSelectionArgument selArg =
995 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700996 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
997 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700998 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
999 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001000 break;
1001
1002 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001003 ar = (AsyncResult) msg.obj;
1004 request = (MainThreadRequest) ar.userObj;
1005 if (ar.exception == null) {
1006 request.result = true;
1007 } else {
1008 request.result = false;
1009 loge("setNetworkSelectionModeManual " + ar.exception);
1010 }
1011 notifyRequester(request);
1012 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001013 break;
1014
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001015 case CMD_GET_MODEM_ACTIVITY_INFO:
1016 request = (MainThreadRequest) msg.obj;
1017 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001018 if (defaultPhone != null) {
1019 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
1020 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001021 break;
1022
1023 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1024 ar = (AsyncResult) msg.obj;
1025 request = (MainThreadRequest) ar.userObj;
1026 if (ar.exception == null && ar.result != null) {
1027 request.result = ar.result;
1028 } else {
1029 if (ar.result == null) {
1030 loge("queryModemActivityInfo: Empty response");
1031 } else if (ar.exception instanceof CommandException) {
1032 loge("queryModemActivityInfo: CommandException: " +
1033 ar.exception);
1034 } else {
1035 loge("queryModemActivityInfo: Unknown exception");
1036 }
1037 }
Amit Mahajand4766222016-01-28 15:28:28 -08001038 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
1039 if (request.result == null) {
Chen Xu13851032019-09-10 18:49:52 -07001040 request.result = new ModemActivityInfo(0, 0, 0, null, 0);
Amit Mahajand4766222016-01-28 15:28:28 -08001041 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001042 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001043 break;
1044
Meng Wang1a7c35a2016-05-05 20:56:15 -07001045 case CMD_SET_ALLOWED_CARRIERS:
1046 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001047 CarrierRestrictionRules argument =
1048 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001049 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001050 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001051 break;
1052
1053 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1054 ar = (AsyncResult) msg.obj;
1055 request = (MainThreadRequest) ar.userObj;
1056 if (ar.exception == null && ar.result != null) {
1057 request.result = ar.result;
1058 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001059 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1060 if (ar.exception instanceof CommandException) {
1061 loge("setAllowedCarriers: CommandException: " + ar.exception);
1062 CommandException.Error error =
1063 ((CommandException) (ar.exception)).getCommandError();
1064 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1065 request.result =
1066 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1067 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001068 } else {
1069 loge("setAllowedCarriers: Unknown exception");
1070 }
1071 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001072 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001073 break;
1074
1075 case CMD_GET_ALLOWED_CARRIERS:
1076 request = (MainThreadRequest) msg.obj;
1077 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001078 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001079 break;
1080
1081 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1082 ar = (AsyncResult) msg.obj;
1083 request = (MainThreadRequest) ar.userObj;
1084 if (ar.exception == null && ar.result != null) {
1085 request.result = ar.result;
1086 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001087 request.result = new IllegalStateException(
1088 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001089 if (ar.result == null) {
1090 loge("getAllowedCarriers: Empty response");
1091 } else if (ar.exception instanceof CommandException) {
1092 loge("getAllowedCarriers: CommandException: " +
1093 ar.exception);
1094 } else {
1095 loge("getAllowedCarriers: Unknown exception");
1096 }
1097 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001098 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001099 break;
1100
Nathan Haroldb3014052017-01-25 15:57:32 -08001101 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1102 ar = (AsyncResult) msg.obj;
1103 request = (MainThreadRequest) ar.userObj;
1104 if (ar.exception == null && ar.result != null) {
1105 request.result = ar.result;
1106 } else {
1107 request.result = new IllegalArgumentException(
1108 "Failed to retrieve Forbidden Plmns");
1109 if (ar.result == null) {
1110 loge("getForbiddenPlmns: Empty response");
1111 } else {
1112 loge("getForbiddenPlmns: Unknown exception");
1113 }
1114 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001115 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001116 break;
1117
1118 case CMD_GET_FORBIDDEN_PLMNS:
1119 request = (MainThreadRequest) msg.obj;
1120 uiccCard = getUiccCardFromRequest(request);
1121 if (uiccCard == null) {
1122 loge("getForbiddenPlmns() UiccCard is null");
1123 request.result = new IllegalArgumentException(
1124 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001125 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001126 break;
1127 }
1128 Integer appType = (Integer) request.argument;
1129 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1130 if (uiccApp == null) {
1131 loge("getForbiddenPlmns() no app with specified type -- "
1132 + appType);
1133 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001134 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001135 break;
1136 } else {
1137 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1138 + " specified type -- " + appType);
1139 }
1140 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1141 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1142 onCompleted);
1143 break;
1144
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001145 case CMD_SWITCH_SLOTS:
1146 request = (MainThreadRequest) msg.obj;
1147 int[] physicalSlots = (int[]) request.argument;
1148 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1149 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1150 break;
1151
1152 case EVENT_SWITCH_SLOTS_DONE:
1153 ar = (AsyncResult) msg.obj;
1154 request = (MainThreadRequest) ar.userObj;
1155 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001156 notifyRequester(request);
1157 break;
1158 case CMD_GET_NETWORK_SELECTION_MODE:
1159 request = (MainThreadRequest) msg.obj;
1160 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1161 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1162 break;
1163
1164 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1165 ar = (AsyncResult) msg.obj;
1166 request = (MainThreadRequest) ar.userObj;
1167 if (ar.exception != null) {
1168 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1169 } else {
1170 int mode = ((int[]) ar.result)[0];
1171 if (mode == 0) {
1172 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1173 } else {
1174 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1175 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001176 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001177 notifyRequester(request);
1178 break;
1179 case CMD_GET_CDMA_ROAMING_MODE:
1180 request = (MainThreadRequest) msg.obj;
1181 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1182 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1183 break;
1184 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1185 ar = (AsyncResult) msg.obj;
1186 request = (MainThreadRequest) ar.userObj;
1187 if (ar.exception != null) {
1188 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1189 } else {
1190 request.result = ((int[]) ar.result)[0];
1191 }
1192 notifyRequester(request);
1193 break;
1194 case CMD_SET_CDMA_ROAMING_MODE:
1195 request = (MainThreadRequest) msg.obj;
1196 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1197 int mode = (int) request.argument;
1198 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1199 break;
1200 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1201 ar = (AsyncResult) msg.obj;
1202 request = (MainThreadRequest) ar.userObj;
1203 request.result = ar.exception == null;
1204 notifyRequester(request);
1205 break;
1206 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1207 request = (MainThreadRequest) msg.obj;
1208 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1209 int subscriptionMode = (int) request.argument;
1210 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1211 break;
1212 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1213 ar = (AsyncResult) msg.obj;
1214 request = (MainThreadRequest) ar.userObj;
1215 request.result = ar.exception == null;
1216 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001217 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001218 case CMD_GET_ALL_CELL_INFO:
1219 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001220 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001221 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001222 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001223 case EVENT_GET_ALL_CELL_INFO_DONE:
1224 ar = (AsyncResult) msg.obj;
1225 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001226 // If a timeout occurs, the response will be null
1227 request.result = (ar.exception == null && ar.result != null)
1228 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001229 synchronized (request) {
1230 request.notifyAll();
1231 }
1232 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001233 case CMD_REQUEST_CELL_INFO_UPDATE:
1234 request = (MainThreadRequest) msg.obj;
1235 request.phone.requestCellInfoUpdate(request.workSource,
1236 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1237 break;
1238 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1239 ar = (AsyncResult) msg.obj;
1240 request = (MainThreadRequest) ar.userObj;
1241 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1242 try {
1243 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001244 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001245 cb.onError(
1246 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1247 ar.exception.getClass().getName(),
1248 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001249 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001250 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001251 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001252 } else {
1253 // use the result as returned
1254 cb.onCellInfo((List<CellInfo>) ar.result);
1255 }
1256 } catch (RemoteException re) {
1257 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1258 }
1259 break;
1260 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001261 request = (MainThreadRequest) msg.obj;
1262 WorkSource ws = (WorkSource) request.argument;
1263 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001264 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001265 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001266 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001267 ar = (AsyncResult) msg.obj;
1268 request = (MainThreadRequest) ar.userObj;
1269 if (ar.exception == null) {
1270 request.result = ar.result;
1271 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001272 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001273 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001274 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001275 }
1276
1277 synchronized (request) {
1278 request.notifyAll();
1279 }
1280 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001281 case CMD_MODEM_REBOOT:
1282 request = (MainThreadRequest) msg.obj;
1283 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001284 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001285 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001286 case EVENT_CMD_MODEM_REBOOT_DONE:
1287 handleNullReturnEvent(msg, "rebootModem");
1288 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001289 case CMD_REQUEST_ENABLE_MODEM:
1290 request = (MainThreadRequest) msg.obj;
1291 boolean enable = (boolean) request.argument;
1292 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001293 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001294 PhoneConfigurationManager.getInstance()
1295 .enablePhone(request.phone, enable, onCompleted);
1296 break;
1297 case EVENT_ENABLE_MODEM_DONE:
1298 ar = (AsyncResult) msg.obj;
1299 request = (MainThreadRequest) ar.userObj;
1300 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001301 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001302 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001303 if ((boolean) request.result) {
1304 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1305 updateModemStateMetrics();
1306 } else {
1307 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1308 + ar.exception);
1309 }
1310 notifyRequester(request);
1311 break;
1312 case CMD_GET_MODEM_STATUS:
1313 request = (MainThreadRequest) msg.obj;
1314 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1315 PhoneConfigurationManager.getInstance()
1316 .getPhoneStatusFromModem(request.phone, onCompleted);
1317 break;
1318 case EVENT_GET_MODEM_STATUS_DONE:
1319 ar = (AsyncResult) msg.obj;
1320 request = (MainThreadRequest) ar.userObj;
1321 int id = request.phone.getPhoneId();
1322 if (ar.exception == null && ar.result != null) {
1323 request.result = ar.result;
1324 //update the cache as modem status has changed
1325 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1326 (boolean) request.result);
1327 } else {
1328 // Return true if modem status cannot be retrieved. For most cases,
1329 // modem status is on. And for older version modems, GET_MODEM_STATUS
1330 // and disable modem are not supported. Modem is always on.
1331 // TODO: this should be fixed in R to support a third
1332 // status UNKNOWN b/131631629
1333 request.result = true;
1334 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1335 + ar.exception);
1336 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001337 notifyRequester(request);
1338 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001339 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1340 ar = (AsyncResult) msg.obj;
1341 request = (MainThreadRequest) ar.userObj;
1342 if (ar.exception == null && ar.result != null) {
1343 request.result = ar.result;
1344 } else {
1345 request.result = -1;
1346 loge("Failed to set Forbidden Plmns");
1347 if (ar.result == null) {
1348 loge("setForbidenPlmns: Empty response");
1349 } else if (ar.exception != null) {
1350 loge("setForbiddenPlmns: Exception: " + ar.exception);
1351 request.result = -1;
1352 } else {
1353 loge("setForbiddenPlmns: Unknown exception");
1354 }
1355 }
1356 notifyRequester(request);
1357 break;
1358 case CMD_SET_FORBIDDEN_PLMNS:
1359 request = (MainThreadRequest) msg.obj;
1360 uiccCard = getUiccCardFromRequest(request);
1361 if (uiccCard == null) {
1362 loge("setForbiddenPlmns: UiccCard is null");
1363 request.result = -1;
1364 notifyRequester(request);
1365 break;
1366 }
1367 Pair<Integer, List<String>> setFplmnsArgs =
1368 (Pair<Integer, List<String>>) request.argument;
1369 appType = setFplmnsArgs.first;
1370 List<String> fplmns = setFplmnsArgs.second;
1371 uiccApp = uiccCard.getApplicationByType(appType);
1372 if (uiccApp == null) {
1373 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1374 request.result = -1;
1375 loge("Failed to get UICC App");
1376 notifyRequester(request);
1377 } else {
1378 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1379 ((SIMRecords) uiccApp.getIccRecords())
1380 .setForbiddenPlmns(onCompleted, fplmns);
1381 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001382 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001383 case CMD_ERASE_MODEM_CONFIG:
1384 request = (MainThreadRequest) msg.obj;
1385 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1386 defaultPhone.eraseModemConfig(onCompleted);
1387 break;
1388 case EVENT_ERASE_MODEM_CONFIG_DONE:
1389 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001390 break;
zoey chenf95ca592019-12-30 16:11:23 +08001391
1392 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1393 request = (MainThreadRequest) msg.obj;
1394 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1395 Pair<String, String> changed = (Pair<String, String>) request.argument;
1396 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1397 changed.first, changed.second, onCompleted);
1398 break;
1399 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1400 ar = (AsyncResult) msg.obj;
1401 request = (MainThreadRequest) ar.userObj;
1402 if (ar.exception == null) {
1403 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1404 } else {
1405 request.result = msg.arg1;
1406 }
1407 notifyRequester(request);
1408 break;
1409
1410 case CMD_SET_ICC_LOCK_ENABLED:
1411 request = (MainThreadRequest) msg.obj;
1412 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1413 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1414 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1415 enabled.first, enabled.second, onCompleted);
1416 break;
1417 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1418 ar = (AsyncResult) msg.obj;
1419 request = (MainThreadRequest) ar.userObj;
1420 if (ar.exception == null) {
1421 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1422 } else {
1423 request.result = msg.arg1;
1424 }
1425 notifyRequester(request);
1426 break;
1427
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001428 default:
1429 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1430 break;
1431 }
1432 }
Jake Hambye994d462014-02-03 13:10:13 -08001433
Pengquan Menga1bb6272018-09-06 09:59:22 -07001434 private void notifyRequester(MainThreadRequest request) {
1435 synchronized (request) {
1436 request.notifyAll();
1437 }
1438 }
1439
Jake Hambye994d462014-02-03 13:10:13 -08001440 private void handleNullReturnEvent(Message msg, String command) {
1441 AsyncResult ar = (AsyncResult) msg.obj;
1442 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1443 if (ar.exception == null) {
1444 request.result = true;
1445 } else {
1446 request.result = false;
1447 if (ar.exception instanceof CommandException) {
1448 loge(command + ": CommandException: " + ar.exception);
1449 } else {
1450 loge(command + ": Unknown exception");
1451 }
1452 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001453 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001454 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001455 }
1456
1457 /**
1458 * Posts the specified command to be executed on the main thread,
1459 * waits for the request to complete, and returns the result.
1460 * @see #sendRequestAsync
1461 */
1462 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001463 return sendRequest(
1464 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001465 }
1466
1467 /**
1468 * Posts the specified command to be executed on the main thread,
1469 * waits for the request to complete, and returns the result.
1470 * @see #sendRequestAsync
1471 */
1472 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1473 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001474 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001475 }
1476
1477 /**
1478 * Posts the specified command to be executed on the main thread,
1479 * waits for the request to complete, and returns the result.
1480 * @see #sendRequestAsync
1481 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001482 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001483 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001484 }
1485
1486 /**
1487 * Posts the specified command to be executed on the main thread,
1488 * waits for the request to complete, and returns the result.
1489 * @see #sendRequestAsync
1490 */
Nathan Harold92bed182018-10-12 18:16:49 -07001491 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1492 return sendRequest(command, argument, subId, null, workSource);
1493 }
1494
1495 /**
1496 * Posts the specified command to be executed on the main thread,
1497 * waits for the request to complete, and returns the result.
1498 * @see #sendRequestAsync
1499 */
1500 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1501 return sendRequest(
1502 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1503 }
1504
1505 /**
1506 * Posts the specified command to be executed on the main thread,
1507 * waits for the request to complete, and returns the result.
1508 * @see #sendRequestAsync
1509 */
1510 private Object sendRequest(
1511 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001512 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1513 throw new RuntimeException("This method will deadlock if called from the main thread.");
1514 }
1515
Nathan Harold92bed182018-10-12 18:16:49 -07001516 MainThreadRequest request = null;
1517 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1518 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1519 } else if (phone != null) {
1520 request = new MainThreadRequest(argument, phone, workSource);
1521 } else {
1522 request = new MainThreadRequest(argument, subId, workSource);
1523 }
1524
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001525 Message msg = mMainThreadHandler.obtainMessage(command, request);
1526 msg.sendToTarget();
1527
1528 // Wait for the request to complete
1529 synchronized (request) {
1530 while (request.result == null) {
1531 try {
1532 request.wait();
1533 } catch (InterruptedException e) {
1534 // Do nothing, go back and wait until the request is complete
1535 }
1536 }
1537 }
1538 return request.result;
1539 }
1540
1541 /**
1542 * Asynchronous ("fire and forget") version of sendRequest():
1543 * Posts the specified command to be executed on the main thread, and
1544 * returns immediately.
1545 * @see #sendRequest
1546 */
1547 private void sendRequestAsync(int command) {
1548 mMainThreadHandler.sendEmptyMessage(command);
1549 }
1550
1551 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001552 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001553 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001554 */
1555 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001556 sendRequestAsync(command, argument, null, null);
1557 }
1558
1559 /**
1560 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1561 * @see {@link #sendRequest(int,Object)}
1562 */
1563 private void sendRequestAsync(
1564 int command, Object argument, Phone phone, WorkSource workSource) {
1565 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001566 Message msg = mMainThreadHandler.obtainMessage(command, request);
1567 msg.sendToTarget();
1568 }
1569
1570 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001571 * Initialize the singleton PhoneInterfaceManager instance.
1572 * This is only done once, at startup, from PhoneApp.onCreate().
1573 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001574 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001575 synchronized (PhoneInterfaceManager.class) {
1576 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001577 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001578 } else {
1579 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1580 }
1581 return sInstance;
1582 }
1583 }
1584
1585 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001586 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001587 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001588 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001589 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001590 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001591 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1592 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001593 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001594 mTelephonySharedPreferences =
1595 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001596 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001597 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001598
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001599 publish();
1600 }
1601
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001602 private Phone getDefaultPhone() {
1603 Phone thePhone = getPhone(getDefaultSubscription());
1604 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1605 }
1606
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001607 private void publish() {
1608 if (DBG) log("publish: " + this);
1609
1610 ServiceManager.addService("phone", this);
1611 }
1612
Stuart Scott584921c2015-01-15 17:10:34 -08001613 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001614 if (request.phone != null) {
1615 return request.phone;
1616 } else {
1617 return getPhoneFromSubId(request.subId);
1618 }
1619 }
1620
1621 private Phone getPhoneFromSubId(int subId) {
1622 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1623 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001624 }
1625
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001626 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1627 Phone phone = getPhoneFromRequest(request);
1628 return phone == null ? null :
1629 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1630 }
1631
Wink Saville36469e72014-06-11 15:17:00 -07001632 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001633 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001634 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001635 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001636
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001637 private void sendEraseModemConfig(Phone phone) {
1638 if (phone != null) {
1639 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1640 mApp, phone.getSubId(), "eraseModemConfig");
1641 final long identity = Binder.clearCallingIdentity();
1642 try {
1643 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1644 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1645 } finally {
1646 Binder.restoreCallingIdentity(identity);
1647 }
1648 }
1649 }
1650
Peter Wang050bb052020-01-13 23:33:09 -08001651 private boolean isImsAvailableOnDevice() {
1652 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1653 if (pm == null) {
1654 // For some reason package manger is not available.. This will fail internally anyway,
1655 // so do not throw error and allow.
1656 return true;
1657 }
1658 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1659 }
1660
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001661 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001662 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001663 }
1664
Wink Savilleb564aae2014-10-23 10:18:09 -07001665 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001666 if (DBG) log("dial: " + number);
1667 // No permission check needed here: This is just a wrapper around the
1668 // ACTION_DIAL intent, which is available to any app since it puts up
1669 // the UI before it does anything.
1670
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001671 final long identity = Binder.clearCallingIdentity();
1672 try {
1673 String url = createTelUrl(number);
1674 if (url == null) {
1675 return;
1676 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001677
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001678 // PENDING: should we just silently fail if phone is offhook or ringing?
1679 PhoneConstants.State state = mCM.getState(subId);
1680 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1681 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1682 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1683 mApp.startActivity(intent);
1684 }
1685 } finally {
1686 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001687 }
1688 }
1689
1690 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001691 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001692 }
1693
Wink Savilleb564aae2014-10-23 10:18:09 -07001694 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001695 if (DBG) log("call: " + number);
1696
1697 // This is just a wrapper around the ACTION_CALL intent, but we still
1698 // need to do a permission check since we're calling startActivity()
1699 // from the context of the phone app.
1700 enforceCallPermission();
1701
Jordan Liu1617b712019-07-10 15:06:26 -07001702 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001703 != AppOpsManager.MODE_ALLOWED) {
1704 return;
1705 }
1706
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001707 final long identity = Binder.clearCallingIdentity();
1708 try {
1709 String url = createTelUrl(number);
1710 if (url == null) {
1711 return;
1712 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001713
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001714 boolean isValid = false;
1715 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1716 if (slist != null) {
1717 for (SubscriptionInfo subInfoRecord : slist) {
1718 if (subInfoRecord.getSubscriptionId() == subId) {
1719 isValid = true;
1720 break;
1721 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001722 }
Wink Saville08874612014-08-31 19:19:58 -07001723 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001724 if (!isValid) {
1725 return;
1726 }
Wink Saville08874612014-08-31 19:19:58 -07001727
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001728 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1729 intent.putExtra(SUBSCRIPTION_KEY, subId);
1730 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1731 mApp.startActivity(intent);
1732 } finally {
1733 Binder.restoreCallingIdentity(identity);
1734 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001735 }
1736
Wink Savilleb564aae2014-10-23 10:18:09 -07001737 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001738 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001739 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1740 }
1741
Wink Savilleb564aae2014-10-23 10:18:09 -07001742 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001743 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001744 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1745 }
1746
Wink Savilleb564aae2014-10-23 10:18:09 -07001747 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001749
1750 final long identity = Binder.clearCallingIdentity();
1751 try {
1752 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1753 checkSimPin.start();
1754 return checkSimPin.unlockSim(null, pin);
1755 } finally {
1756 Binder.restoreCallingIdentity(identity);
1757 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758 }
1759
Wink Savilleb564aae2014-10-23 10:18:09 -07001760 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001761 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001762
1763 final long identity = Binder.clearCallingIdentity();
1764 try {
1765 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1766 checkSimPuk.start();
1767 return checkSimPuk.unlockSim(puk, pin);
1768 } finally {
1769 Binder.restoreCallingIdentity(identity);
1770 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001771 }
1772
1773 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001774 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001775 * a synchronous one.
1776 */
1777 private static class UnlockSim extends Thread {
1778
1779 private final IccCard mSimCard;
1780
1781 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001782 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1783 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001784
1785 // For replies from SimCard interface
1786 private Handler mHandler;
1787
1788 // For async handler to identify request type
1789 private static final int SUPPLY_PIN_COMPLETE = 100;
1790
1791 public UnlockSim(IccCard simCard) {
1792 mSimCard = simCard;
1793 }
1794
1795 @Override
1796 public void run() {
1797 Looper.prepare();
1798 synchronized (UnlockSim.this) {
1799 mHandler = new Handler() {
1800 @Override
1801 public void handleMessage(Message msg) {
1802 AsyncResult ar = (AsyncResult) msg.obj;
1803 switch (msg.what) {
1804 case SUPPLY_PIN_COMPLETE:
1805 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1806 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001807 mRetryCount = msg.arg1;
1808 if (ar.exception != null) {
1809 if (ar.exception instanceof CommandException &&
1810 ((CommandException)(ar.exception)).getCommandError()
1811 == CommandException.Error.PASSWORD_INCORRECT) {
1812 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1813 } else {
1814 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1815 }
1816 } else {
1817 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1818 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 mDone = true;
1820 UnlockSim.this.notifyAll();
1821 }
1822 break;
1823 }
1824 }
1825 };
1826 UnlockSim.this.notifyAll();
1827 }
1828 Looper.loop();
1829 }
1830
1831 /*
1832 * Use PIN or PUK to unlock SIM card
1833 *
1834 * If PUK is null, unlock SIM card with PIN
1835 *
1836 * If PUK is not null, unlock SIM card with PUK and set PIN code
1837 */
Wink Saville9de0f752013-10-22 19:04:03 -07001838 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001839
1840 while (mHandler == null) {
1841 try {
1842 wait();
1843 } catch (InterruptedException e) {
1844 Thread.currentThread().interrupt();
1845 }
1846 }
1847 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1848
1849 if (puk == null) {
1850 mSimCard.supplyPin(pin, callback);
1851 } else {
1852 mSimCard.supplyPuk(puk, pin, callback);
1853 }
1854
1855 while (!mDone) {
1856 try {
1857 Log.d(LOG_TAG, "wait for done");
1858 wait();
1859 } catch (InterruptedException e) {
1860 // Restore the interrupted status
1861 Thread.currentThread().interrupt();
1862 }
1863 }
1864 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001865 int[] resultArray = new int[2];
1866 resultArray[0] = mResult;
1867 resultArray[1] = mRetryCount;
1868 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001869 }
1870 }
1871
1872 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001873 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001874
1875 }
1876
Wink Savilleb564aae2014-10-23 10:18:09 -07001877 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001878 // No permission check needed here: this call is harmless, and it's
1879 // needed for the ServiceState.requestStateUpdate() call (which is
1880 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001881 final long identity = Binder.clearCallingIdentity();
1882 try {
1883 final Phone phone = getPhone(subId);
1884 if (phone != null) {
1885 phone.updateServiceLocation();
1886 }
1887 } finally {
1888 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001889 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 }
1891
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001892 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001893 @Override
1894 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001895 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001896 }
1897
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001898 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001899 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1900 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1901 callingFeatureId);
1902 }
1903
1904 @Deprecated
1905 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001906 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001907 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
1908 }
1909
1910 @Override
1911 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1912 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001913 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001914 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001915 return false;
1916 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001917
1918 final long identity = Binder.clearCallingIdentity();
1919 try {
1920 return isRadioOnForSubscriber(subId);
1921 } finally {
1922 Binder.restoreCallingIdentity(identity);
1923 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001924 }
1925
1926 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001927 final long identity = Binder.clearCallingIdentity();
1928 try {
1929 final Phone phone = getPhone(subId);
1930 if (phone != null) {
1931 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1932 } else {
1933 return false;
1934 }
1935 } finally {
1936 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001937 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 }
1939
1940 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001941 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 }
Wink Saville36469e72014-06-11 15:17:00 -07001943
Wink Savilleb564aae2014-10-23 10:18:09 -07001944 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001945 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001946
1947 final long identity = Binder.clearCallingIdentity();
1948 try {
1949 final Phone phone = getPhone(subId);
1950 if (phone != null) {
1951 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1952 }
1953 } finally {
1954 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001955 }
Wink Saville36469e72014-06-11 15:17:00 -07001956 }
1957
1958 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001959 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001960 }
1961
Wink Savilleb564aae2014-10-23 10:18:09 -07001962 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001963 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001964
1965 final long identity = Binder.clearCallingIdentity();
1966 try {
1967 final Phone phone = getPhone(subId);
1968 if (phone == null) {
1969 return false;
1970 }
1971 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1972 toggleRadioOnOffForSubscriber(subId);
1973 }
1974 return true;
1975 } finally {
1976 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001977 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001978 }
Wink Saville36469e72014-06-11 15:17:00 -07001979
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001980 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08001981 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001982 /*
1983 * If any of the Radios are available, it will need to be
1984 * shutdown. So return true if any Radio is available.
1985 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001986 final long identity = Binder.clearCallingIdentity();
1987 try {
1988 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1989 Phone phone = PhoneFactory.getPhone(i);
1990 if (phone != null && phone.isRadioAvailable()) return true;
1991 }
1992 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1993 return false;
1994 } finally {
1995 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001996 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001997 }
1998
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001999 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002000 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002001 enforceModifyPermission();
2002
2003 final long identity = Binder.clearCallingIdentity();
2004 try {
2005 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2006 logv("Shutting down Phone " + i);
2007 shutdownRadioUsingPhoneId(i);
2008 }
2009 } finally {
2010 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002011 }
2012 }
2013
2014 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002015 Phone phone = PhoneFactory.getPhone(phoneId);
2016 if (phone != null && phone.isRadioAvailable()) {
2017 phone.shutdownRadio();
2018 }
2019 }
2020
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002021 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002022 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002023
2024 final long identity = Binder.clearCallingIdentity();
2025 try {
2026 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2027 if (defaultPhone != null) {
2028 defaultPhone.setRadioPower(turnOn);
2029 return true;
2030 } else {
2031 loge("There's no default phone.");
2032 return false;
2033 }
2034 } finally {
2035 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002036 }
Wink Saville36469e72014-06-11 15:17:00 -07002037 }
2038
Wink Savilleb564aae2014-10-23 10:18:09 -07002039 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002040 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002041
2042 final long identity = Binder.clearCallingIdentity();
2043 try {
2044 final Phone phone = getPhone(subId);
2045 if (phone != null) {
2046 phone.setRadioPower(turnOn);
2047 return true;
2048 } else {
2049 return false;
2050 }
2051 } finally {
2052 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002053 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002054 }
2055
Wink Saville36469e72014-06-11 15:17:00 -07002056 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002057 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002058 public boolean enableDataConnectivity() {
2059 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002060
2061 final long identity = Binder.clearCallingIdentity();
2062 try {
2063 int subId = mSubscriptionController.getDefaultDataSubId();
2064 final Phone phone = getPhone(subId);
2065 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002066 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002067 return true;
2068 } else {
2069 return false;
2070 }
2071 } finally {
2072 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002073 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002074 }
2075
Wink Saville36469e72014-06-11 15:17:00 -07002076 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002077 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002078 public boolean disableDataConnectivity() {
2079 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002080
2081 final long identity = Binder.clearCallingIdentity();
2082 try {
2083 int subId = mSubscriptionController.getDefaultDataSubId();
2084 final Phone phone = getPhone(subId);
2085 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002086 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002087 return true;
2088 } else {
2089 return false;
2090 }
2091 } finally {
2092 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002093 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002094 }
2095
Sanket Padawe356d7632015-06-22 14:03:32 -07002096 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002097 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002098 final long identity = Binder.clearCallingIdentity();
2099 try {
2100 final Phone phone = getPhone(subId);
2101 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002102 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002103 } else {
2104 return false;
2105 }
2106 } finally {
2107 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002108 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002109 }
2110
2111 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002112 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002113 }
2114
pkanwarae03a6b2016-11-06 20:37:09 -08002115 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002116 enforceCallPermission();
2117
2118 final long identity = Binder.clearCallingIdentity();
2119 try {
2120 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2121 return;
2122 }
2123 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2124 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2125 } finally {
2126 Binder.restoreCallingIdentity(identity);
2127 }
pkanwar32d516d2016-10-14 19:37:38 -07002128 };
2129
Wink Savilleb564aae2014-10-23 10:18:09 -07002130 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002131 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002132
2133 final long identity = Binder.clearCallingIdentity();
2134 try {
2135 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2136 return false;
2137 }
2138 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2139 } finally {
2140 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002141 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002142 }
2143
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002144 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002145 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002146 }
2147
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002148 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002149 final long identity = Binder.clearCallingIdentity();
2150 try {
2151 Phone phone = PhoneFactory.getPhone(slotIndex);
2152 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2153 PhoneConstantConversions.convertCallState(phone.getState());
2154 } finally {
2155 Binder.restoreCallingIdentity(identity);
2156 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002157 }
2158
Sanket Padawe356d7632015-06-22 14:03:32 -07002159 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002160 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002161 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2162 }
2163
2164 @Override
2165 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002166 final long identity = Binder.clearCallingIdentity();
2167 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002168 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002169 if (phone != null) {
2170 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2171 } else {
2172 return PhoneConstantConversions.convertDataState(
2173 PhoneConstants.DataState.DISCONNECTED);
2174 }
2175 } finally {
2176 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002177 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002178 }
2179
Sanket Padawe356d7632015-06-22 14:03:32 -07002180 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002181 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002182 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2183 }
2184
2185 @Override
2186 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002187 final long identity = Binder.clearCallingIdentity();
2188 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002189 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002190 if (phone != null) {
2191 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2192 } else {
2193 return TelephonyManager.DATA_ACTIVITY_NONE;
2194 }
2195 } finally {
2196 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002197 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002198 }
2199
2200 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002201 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002202 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002203 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002204
2205 LocationAccessPolicy.LocationPermissionResult locationResult =
2206 LocationAccessPolicy.checkLocationPermission(mApp,
2207 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2208 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002209 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002210 .setCallingPid(Binder.getCallingPid())
2211 .setCallingUid(Binder.getCallingUid())
2212 .setMethod("getCellLocation")
2213 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2214 .build());
2215 switch (locationResult) {
2216 case DENIED_HARD:
2217 throw new SecurityException("Not allowed to access cell location");
2218 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002219 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2220 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002221 }
2222
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002223 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002224 final long identity = Binder.clearCallingIdentity();
2225 try {
2226 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002227 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002228 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002229 } finally {
2230 Binder.restoreCallingIdentity(identity);
2231 }
Svetoslav64fad262015-04-14 14:35:21 -07002232 }
2233
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002234 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002235 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2236 String callingFeatureId) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002237 if (!TextUtils.isEmpty(callingPackage)) {
2238 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002239 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2240 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002241 return "";
2242 }
2243 }
2244
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002245 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2246 // registered cell info, so return a NULL country instead.
2247 final long identity = Binder.clearCallingIdentity();
2248 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002249 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2250 // Get default phone in this case.
2251 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2252 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002253 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002254 // Todo: fix this when we can get the actual cellular network info when the device
2255 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002256 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002257 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2258 null)) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002259 return "";
2260 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002261 Phone phone = PhoneFactory.getPhone(phoneId);
2262 if (phone != null) {
2263 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002264 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002265 if (sst != null) {
2266 LocaleTracker lt = sst.getLocaleTracker();
2267 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002268 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2269 return lt.getCurrentCountry();
2270 } else if (emergencyNumberTracker != null) {
2271 return emergencyNumberTracker.getEmergencyCountryIso();
2272 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002273 }
2274 }
2275 }
2276 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002277 } finally {
2278 Binder.restoreCallingIdentity(identity);
2279 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002280 }
2281
2282 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002283 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002284 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002285 }
2286
Sanket Padawe356d7632015-06-22 14:03:32 -07002287 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002288 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002289 mApp.enforceCallingOrSelfPermission(
2290 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002291
2292 final long identity = Binder.clearCallingIdentity();
2293 try {
2294 final Phone phone = getPhone(subId);
2295 if (phone != null) {
2296 phone.enableLocationUpdates();
2297 }
2298 } finally {
2299 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002300 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301 }
2302
2303 @Override
2304 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002305 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002306 }
2307
Sanket Padawe356d7632015-06-22 14:03:32 -07002308 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002309 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002310 mApp.enforceCallingOrSelfPermission(
2311 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002312
2313 final long identity = Binder.clearCallingIdentity();
2314 try {
2315 final Phone phone = getPhone(subId);
2316 if (phone != null) {
2317 phone.disableLocationUpdates();
2318 }
2319 } finally {
2320 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002321 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002322 }
2323
Nathan Harold31d7ff32018-10-15 20:20:30 -07002324 /**
2325 * Returns the target SDK version number for a given package name.
2326 *
Nathan Haroldec184742019-07-10 17:04:16 -07002327 * This call MUST be invoked before clearing the calling UID.
2328 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002329 * @return target SDK if the package is found or INT_MAX.
2330 */
2331 private int getTargetSdk(String packageName) {
2332 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002333 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002334 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002335 if (ai != null) return ai.targetSdkVersion;
2336 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002337 loge("Failed to get package info for pkg="
2338 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002339 }
2340 return Integer.MAX_VALUE;
2341 }
2342
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002343 @Override
2344 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002345 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2346 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002347 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002348 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2349 throw new SecurityException(
2350 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2351 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002352
Jordan Liu1617b712019-07-10 15:06:26 -07002353 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2355 return null;
2356 }
Svetoslav64fad262015-04-14 14:35:21 -07002357
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002358 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002359
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002360 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002361 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002362
Nathan Haroldf180aac2018-06-01 18:43:55 -07002363 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2364 for (CellInfo ci : info) {
2365 if (ci instanceof CellInfoGsm) {
2366 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2367 } else if (ci instanceof CellInfoWcdma) {
2368 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2369 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002370 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002371 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002372 }
2373
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002374 private List<CellInfo> getCachedCellInfo() {
2375 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2376 for (Phone phone : PhoneFactory.getPhones()) {
2377 List<CellInfo> info = phone.getAllCellInfo();
2378 if (info != null) cellInfos.addAll(info);
2379 }
2380 return cellInfos;
2381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002382
2383 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002384 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002385 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002386 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002387
2388 LocationAccessPolicy.LocationPermissionResult locationResult =
2389 LocationAccessPolicy.checkLocationPermission(mApp,
2390 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2391 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002392 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002393 .setCallingPid(Binder.getCallingPid())
2394 .setCallingUid(Binder.getCallingUid())
2395 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002396 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002397 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2398 .build());
2399 switch (locationResult) {
2400 case DENIED_HARD:
2401 throw new SecurityException("Not allowed to access cell info");
2402 case DENIED_SOFT:
2403 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002404 }
2405
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002406 final int targetSdk = getTargetSdk(callingPackage);
2407 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2408 return getCachedCellInfo();
2409 }
2410
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002411 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002412 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002413 final long identity = Binder.clearCallingIdentity();
2414 try {
2415 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2416 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002417 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002418 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002419 if (info != null) cellInfos.addAll(info);
2420 }
2421 return cellInfos;
2422 } finally {
2423 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424 }
2425 }
2426
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002427 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002428 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2429 String callingFeatureId) {
2430 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2431 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002432 }
2433
2434 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002435 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2436 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002437 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002438 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002439 }
2440
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002441 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2442 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002443 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002444 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002445
2446 LocationAccessPolicy.LocationPermissionResult locationResult =
2447 LocationAccessPolicy.checkLocationPermission(mApp,
2448 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2449 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002450 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002451 .setCallingPid(Binder.getCallingPid())
2452 .setCallingUid(Binder.getCallingUid())
2453 .setMethod("requestCellInfoUpdate")
2454 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2455 .build());
2456 switch (locationResult) {
2457 case DENIED_HARD:
2458 throw new SecurityException("Not allowed to access cell info");
2459 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002460 try {
2461 cb.onCellInfo(new ArrayList<CellInfo>());
2462 } catch (RemoteException re) {
2463 // Drop without consequences
2464 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002465 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002466 }
2467
Nathan Harolda939a962019-05-09 10:13:47 -07002468
2469 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002470 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2471
2472 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2473 }
2474
2475 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002477 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002478 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002479
2480 final long identity = Binder.clearCallingIdentity();
2481 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002482 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002483 } finally {
2484 Binder.restoreCallingIdentity(identity);
2485 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002486 }
2487
Shishir Agrawala9f32182016-04-12 12:00:16 -07002488 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002489 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002490 Phone phone = PhoneFactory.getPhone(slotIndex);
2491 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002492 return null;
2493 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002494 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002495 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002496 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002497 return null;
2498 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002499
2500 final long identity = Binder.clearCallingIdentity();
2501 try {
2502 return phone.getImei();
2503 } finally {
2504 Binder.restoreCallingIdentity(identity);
2505 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002506 }
2507
2508 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002509 public String getTypeAllocationCodeForSlot(int slotIndex) {
2510 Phone phone = PhoneFactory.getPhone(slotIndex);
2511 String tac = null;
2512 if (phone != null) {
2513 String imei = phone.getImei();
2514 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2515 }
2516 return tac;
2517 }
2518
2519 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002520 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002521 Phone phone = PhoneFactory.getPhone(slotIndex);
2522 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002523 return null;
2524 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002525
Jeff Davidson913390f2018-02-23 17:11:49 -08002526 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002527 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002528 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002529 return null;
2530 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002531
2532 final long identity = Binder.clearCallingIdentity();
2533 try {
2534 return phone.getMeid();
2535 } finally {
2536 Binder.restoreCallingIdentity(identity);
2537 }
Jack Yu2af8d712017-03-15 17:14:14 -07002538 }
2539
2540 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002541 public String getManufacturerCodeForSlot(int slotIndex) {
2542 Phone phone = PhoneFactory.getPhone(slotIndex);
2543 String manufacturerCode = null;
2544 if (phone != null) {
2545 String meid = phone.getMeid();
2546 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2547 }
2548 return manufacturerCode;
2549 }
2550
2551 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002552 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2553 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002554 Phone phone = PhoneFactory.getPhone(slotIndex);
2555 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002556 return null;
2557 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002558 int subId = phone.getSubId();
2559 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002560 mApp, subId, callingPackage, callingFeatureId,
2561 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002562 return null;
2563 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002564
2565 final long identity = Binder.clearCallingIdentity();
2566 try {
2567 return phone.getDeviceSvn();
2568 } finally {
2569 Binder.restoreCallingIdentity(identity);
2570 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002571 }
2572
fionaxu43304da2017-11-27 22:51:16 -08002573 @Override
2574 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002575 final long identity = Binder.clearCallingIdentity();
2576 try {
2577 final Phone phone = getPhone(subId);
2578 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2579 } finally {
2580 Binder.restoreCallingIdentity(identity);
2581 }
fionaxu43304da2017-11-27 22:51:16 -08002582 }
2583
2584 @Override
2585 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002586 final long identity = Binder.clearCallingIdentity();
2587 try {
2588 final Phone phone = getPhone(subId);
2589 return phone == null ? null : phone.getCarrierName();
2590 } finally {
2591 Binder.restoreCallingIdentity(identity);
2592 }
fionaxu43304da2017-11-27 22:51:16 -08002593 }
2594
calvinpanffe225e2018-11-01 19:43:06 +08002595 @Override
chen xu0026ca62019-03-06 15:28:50 -08002596 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002597 final long identity = Binder.clearCallingIdentity();
2598 try {
2599 final Phone phone = getPhone(subId);
2600 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002601 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002602 } finally {
2603 Binder.restoreCallingIdentity(identity);
2604 }
2605 }
2606
2607 @Override
chen xu0026ca62019-03-06 15:28:50 -08002608 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002609 final long identity = Binder.clearCallingIdentity();
2610 try {
2611 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002612 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002613 } finally {
2614 Binder.restoreCallingIdentity(identity);
2615 }
2616 }
2617
chen xu651eec72018-11-11 19:03:44 -08002618 @Override
chen xu864e11c2018-12-06 22:10:03 -08002619 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2620 if (!isSubscriptionMccMnc) {
2621 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2622 }
chen xu651eec72018-11-11 19:03:44 -08002623 final Phone phone = PhoneFactory.getPhone(slotIndex);
2624 if (phone == null) {
2625 return TelephonyManager.UNKNOWN_CARRIER_ID;
2626 }
2627 final long identity = Binder.clearCallingIdentity();
2628 try {
2629 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2630 } finally {
2631 Binder.restoreCallingIdentity(identity);
2632 }
2633 }
2634
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002635 //
2636 // Internal helper methods.
2637 //
2638
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002639 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002640 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2641 *
2642 * @throws SecurityException if the caller does not have the required permission
2643 */
2644 private void enforceModifyPermission() {
2645 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2646 }
2647
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002648 /**
2649 * Make sure the caller is system.
2650 *
2651 * @throws SecurityException if the caller is not system.
2652 */
2653 private void enforceSystemCaller() {
2654 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2655 throw new SecurityException("Caller must be system");
2656 }
2657 }
2658
Shuo Qianf2b2df42019-11-13 17:43:31 -08002659 private void enforceActiveEmergencySessionPermission() {
2660 mApp.enforceCallingOrSelfPermission(
2661 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2662 }
2663
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002664 /**
2665 * Make sure the caller has the CALL_PHONE permission.
2666 *
2667 * @throws SecurityException if the caller does not have the required permission
2668 */
2669 private void enforceCallPermission() {
2670 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2671 }
2672
paulhu423b5f22019-08-23 19:17:33 +08002673 private void enforceSettingsPermission() {
2674 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002675 }
2676
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002677 private String createTelUrl(String number) {
2678 if (TextUtils.isEmpty(number)) {
2679 return null;
2680 }
2681
Jake Hambye994d462014-02-03 13:10:13 -08002682 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002683 }
2684
Ihab Awadf9e92732013-12-05 18:02:52 -08002685 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002686 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2687 }
2688
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002689 private static void logv(String msg) {
2690 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2691 }
2692
Ihab Awadf9e92732013-12-05 18:02:52 -08002693 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002694 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2695 }
2696
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002697 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002698 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002699 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002700 }
2701
Sanket Padawe356d7632015-06-22 14:03:32 -07002702 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002703 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002704 final long identity = Binder.clearCallingIdentity();
2705 try {
2706 final Phone phone = PhoneFactory.getPhone(slotIndex);
2707 if (phone == null) {
2708 return PhoneConstants.PHONE_TYPE_NONE;
2709 } else {
2710 return phone.getPhoneType();
2711 }
2712 } finally {
2713 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002714 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002715 }
2716
2717 /**
2718 * Returns the CDMA ERI icon index to display
2719 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002720 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002721 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2722 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2723 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002724 }
2725
Sanket Padawe356d7632015-06-22 14:03:32 -07002726 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002727 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2728 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002729 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002730 mApp, subId, callingPackage, callingFeatureId,
2731 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002732 return -1;
2733 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002734
2735 final long identity = Binder.clearCallingIdentity();
2736 try {
2737 final Phone phone = getPhone(subId);
2738 if (phone != null) {
2739 return phone.getCdmaEriIconIndex();
2740 } else {
2741 return -1;
2742 }
2743 } finally {
2744 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002745 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002746 }
2747
2748 /**
2749 * Returns the CDMA ERI icon mode,
2750 * 0 - ON
2751 * 1 - FLASHING
2752 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002753 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002754 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2755 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2756 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002757 }
2758
Sanket Padawe356d7632015-06-22 14:03:32 -07002759 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002760 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2761 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002762 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002763 mApp, subId, callingPackage, callingFeatureId,
2764 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002765 return -1;
2766 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002767
2768 final long identity = Binder.clearCallingIdentity();
2769 try {
2770 final Phone phone = getPhone(subId);
2771 if (phone != null) {
2772 return phone.getCdmaEriIconMode();
2773 } else {
2774 return -1;
2775 }
2776 } finally {
2777 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002778 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 }
2780
2781 /**
2782 * Returns the CDMA ERI text,
2783 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002784 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002785 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2786 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2787 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002788 }
2789
Sanket Padawe356d7632015-06-22 14:03:32 -07002790 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002791 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2792 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002793 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002794 mApp, subId, callingPackage, callingFeatureId,
2795 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002796 return null;
2797 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798
2799 final long identity = Binder.clearCallingIdentity();
2800 try {
2801 final Phone phone = getPhone(subId);
2802 if (phone != null) {
2803 return phone.getCdmaEriText();
2804 } else {
2805 return null;
2806 }
2807 } finally {
2808 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002809 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002810 }
2811
2812 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002813 * Returns the CDMA MDN.
2814 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002815 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002816 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2818 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002819
2820 final long identity = Binder.clearCallingIdentity();
2821 try {
2822 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002823 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002824 return phone.getLine1Number();
2825 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002826 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002827 return null;
2828 }
2829 } finally {
2830 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002831 }
2832 }
2833
2834 /**
2835 * Returns the CDMA MIN.
2836 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002837 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002838 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2840 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002841
2842 final long identity = Binder.clearCallingIdentity();
2843 try {
2844 final Phone phone = getPhone(subId);
2845 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2846 return phone.getCdmaMin();
2847 } else {
2848 return null;
2849 }
2850 } finally {
2851 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002852 }
2853 }
2854
Hall Liud892bec2018-11-30 14:51:45 -08002855 @Override
2856 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2857 INumberVerificationCallback callback, String callingPackage) {
2858 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2859 != PERMISSION_GRANTED) {
2860 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2861 }
2862 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2863
2864 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2865 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2866 throw new SecurityException("Calling package must be configured in the device config");
2867 }
2868
2869 if (range == null) {
2870 throw new NullPointerException("Range must be non-null");
2871 }
2872
2873 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002874 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002875
2876 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2877 }
2878
Junda Liuca05d5d2014-08-14 22:36:34 -07002879 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002880 * Returns true if CDMA provisioning needs to run.
2881 */
2882 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002883 final long identity = Binder.clearCallingIdentity();
2884 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002885 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002886 } finally {
2887 Binder.restoreCallingIdentity(identity);
2888 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002889 }
2890
2891 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002892 * Sets the voice mail number of a given subId.
2893 */
2894 @Override
2895 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08002896 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2897 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002898
2899 final long identity = Binder.clearCallingIdentity();
2900 try {
2901 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2902 new Pair<String, String>(alphaTag, number), new Integer(subId));
2903 return success;
2904 } finally {
2905 Binder.restoreCallingIdentity(identity);
2906 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002907 }
2908
Ta-wei Yen87c49842016-05-13 21:19:52 -07002909 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002910 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2911 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002912 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2913 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002914 if (!TextUtils.equals(callingPackage, systemDialer)) {
2915 throw new SecurityException("caller must be system dialer");
2916 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002917
2918 final long identity = Binder.clearCallingIdentity();
2919 try {
2920 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2921 if (phoneAccountHandle == null) {
2922 return null;
2923 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002924 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002925 } finally {
2926 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002927 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002928 }
2929
2930 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002931 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2932 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002933 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002934 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002935 mApp, subId, callingPackage, callingFeatureId,
2936 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002937 return null;
2938 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002939
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002940 final long identity = Binder.clearCallingIdentity();
2941 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002942 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002943 } finally {
2944 Binder.restoreCallingIdentity(identity);
2945 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002946 }
2947
2948 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002949 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2950 VisualVoicemailSmsFilterSettings settings) {
2951 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002952
2953 final long identity = Binder.clearCallingIdentity();
2954 try {
2955 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002956 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002957 } finally {
2958 Binder.restoreCallingIdentity(identity);
2959 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002960 }
2961
2962 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002963 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2964 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002965
2966 final long identity = Binder.clearCallingIdentity();
2967 try {
2968 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002969 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002970 } finally {
2971 Binder.restoreCallingIdentity(identity);
2972 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002973 }
2974
2975 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002976 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2977 String callingPackage, int subId) {
2978 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002979
2980 final long identity = Binder.clearCallingIdentity();
2981 try {
2982 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002983 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002984 } finally {
2985 Binder.restoreCallingIdentity(identity);
2986 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002987 }
2988
2989 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002990 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002991 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002992
2993 final long identity = Binder.clearCallingIdentity();
2994 try {
2995 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002996 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002997 } finally {
2998 Binder.restoreCallingIdentity(identity);
2999 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003000 }
3001
3002 @Override
3003 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
3004 String number, int port, String text, PendingIntent sentIntent) {
3005 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003006 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003007 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003008 SmsController smsController = PhoneFactory.getSmsController();
3009 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
3010 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003011 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003012
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003013 /**
fionaxu0152e512016-11-14 13:36:14 -08003014 * Sets the voice activation state of a given subId.
3015 */
3016 @Override
3017 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3019 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003020
3021 final long identity = Binder.clearCallingIdentity();
3022 try {
3023 final Phone phone = getPhone(subId);
3024 if (phone != null) {
3025 phone.setVoiceActivationState(activationState);
3026 } else {
3027 loge("setVoiceActivationState fails with invalid subId: " + subId);
3028 }
3029 } finally {
3030 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003031 }
3032 }
3033
3034 /**
3035 * Sets the data activation state of a given subId.
3036 */
3037 @Override
3038 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3040 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003041
3042 final long identity = Binder.clearCallingIdentity();
3043 try {
3044 final Phone phone = getPhone(subId);
3045 if (phone != null) {
3046 phone.setDataActivationState(activationState);
3047 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003048 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003049 }
3050 } finally {
3051 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003052 }
3053 }
3054
3055 /**
3056 * Returns the voice activation state of a given subId.
3057 */
3058 @Override
3059 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003060 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003061
fionaxu0152e512016-11-14 13:36:14 -08003062 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003063 final long identity = Binder.clearCallingIdentity();
3064 try {
3065 if (phone != null) {
3066 return phone.getVoiceActivationState();
3067 } else {
3068 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3069 }
3070 } finally {
3071 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003072 }
3073 }
3074
3075 /**
3076 * Returns the data activation state of a given subId.
3077 */
3078 @Override
3079 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003080 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003081
fionaxu0152e512016-11-14 13:36:14 -08003082 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003083 final long identity = Binder.clearCallingIdentity();
3084 try {
3085 if (phone != null) {
3086 return phone.getDataActivationState();
3087 } else {
3088 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3089 }
3090 } finally {
3091 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003092 }
3093 }
3094
3095 /**
Wink Saville36469e72014-06-11 15:17:00 -07003096 * Returns the unread count of voicemails for a subId
3097 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003098 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003099 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3100 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003101 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003102 mApp, subId, callingPackage, callingFeatureId,
3103 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003104 return 0;
3105 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003106 final long identity = Binder.clearCallingIdentity();
3107 try {
3108 final Phone phone = getPhone(subId);
3109 if (phone != null) {
3110 return phone.getVoiceMessageCount();
3111 } else {
3112 return 0;
3113 }
3114 } finally {
3115 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003116 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003117 }
3118
3119 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003120 * returns true, if the device is in a state where both voice and data
3121 * are supported simultaneously. This can change based on location or network condition.
3122 */
3123 @Override
3124 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003125 final long identity = Binder.clearCallingIdentity();
3126 try {
3127 final Phone phone = getPhone(subId);
3128 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3129 } finally {
3130 Binder.restoreCallingIdentity(identity);
3131 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003132 }
3133
3134 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003135 * Send the dialer code if called from the current default dialer or the caller has
3136 * carrier privilege.
3137 * @param inputCode The dialer code to send
3138 */
3139 @Override
3140 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003141 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003142 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003143 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3144 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003145 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003146 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003147 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003148 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003149
3150 final long identity = Binder.clearCallingIdentity();
3151 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003152 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003153 } finally {
3154 Binder.restoreCallingIdentity(identity);
3155 }
fionaxu235cc5e2017-03-06 22:25:57 -08003156 }
3157
Pengquan Menga1bb6272018-09-06 09:59:22 -07003158 @Override
3159 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003160 TelephonyPermissions
3161 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3162 mApp, subId, "getNetworkSelectionMode");
3163 final long identity = Binder.clearCallingIdentity();
3164 try {
3165 if (!isActiveSubscription(subId)) {
3166 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3167 }
3168 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3169 } finally {
3170 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003171 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003172 }
3173
Brad Ebinger35c841c2018-10-01 10:40:55 -07003174 @Override
Sarah Chin5f0ecd72019-12-06 10:24:18 -08003175 public PhoneCapability getPhoneCapability(int subId, String callingPackage,
3176 String callingFeatureId) {
3177 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3178 mApp, subId, callingPackage, callingFeatureId, "getPhoneCapability")) {
3179 return null;
3180 }
3181 final long identity = Binder.clearCallingIdentity();
3182 try {
3183 return mPhoneConfigurationManager.getStaticPhoneCapability();
3184 } finally {
3185 Binder.restoreCallingIdentity(identity);
3186 }
3187 }
3188
3189 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003190 public boolean isInEmergencySmsMode() {
3191 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3192 final long identity = Binder.clearCallingIdentity();
3193 try {
3194 for (Phone phone : PhoneFactory.getPhones()) {
3195 if (phone.isInEmergencySmsMode()) {
3196 return true;
3197 }
3198 }
3199 } finally {
3200 Binder.restoreCallingIdentity(identity);
3201 }
3202 return false;
3203 }
3204
shilu366312e2019-12-17 09:28:10 -08003205 /**
3206 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3207 * @param subId The subscription to use to check the configuration.
3208 * @param c The callback that will be used to send the result.
3209 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003210 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003211 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3212 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003213 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003214 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003215
Brad Ebinger77b832e2019-10-17 17:03:22 -07003216 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3217 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3218 "IMS not available on device.");
3219 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003220 final long token = Binder.clearCallingIdentity();
3221 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003222 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003223 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003224 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003225 } catch (ImsException e) {
3226 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003227 } finally {
3228 Binder.restoreCallingIdentity(token);
3229 }
3230 }
3231
shilu366312e2019-12-17 09:28:10 -08003232 /**
3233 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3234 * @param subId The subscription to use to check the configuration.
3235 * @param c The callback that will be used to send the result.
3236 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003237 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003238 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
shilu366312e2019-12-17 09:28:10 -08003239 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003240 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003241 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3242 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3243 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003244 final long token = Binder.clearCallingIdentity();
3245 try {
3246 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3247 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3248 .removeRegistrationCallbackForSubscription(c, subId);
3249 } catch (ImsException e) {
3250 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3251 + "is inactive, ignoring unregister.");
3252 // If the subscription is no longer active, just return, since the callback
3253 // will already have been removed internally.
3254 } finally {
3255 Binder.restoreCallingIdentity(token);
3256 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003257 }
3258
Brad Ebinger774ba362019-10-22 17:36:18 -07003259 /**
3260 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3261 */
3262 @Override
3263 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3264 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3265 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3266 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3267 "IMS not available on device.");
3268 }
3269 final long token = Binder.clearCallingIdentity();
3270 try {
3271 Phone phone = getPhone(subId);
3272 if (phone == null) {
3273 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3274 + subId + "'");
3275 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3276 }
3277 phone.getImsRegistrationState(regState -> {
3278 try {
3279 consumer.accept((regState == null)
3280 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3281 } catch (RemoteException e) {
3282 // Ignore if the remote process is no longer available to call back.
3283 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3284 }
3285 });
3286 } finally {
3287 Binder.restoreCallingIdentity(token);
3288 }
3289 }
3290
3291 /**
3292 * Get the transport type for the IMS service registration state.
3293 */
3294 @Override
3295 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
shilu366312e2019-12-17 09:28:10 -08003296 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger774ba362019-10-22 17:36:18 -07003297 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3298 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3299 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3300 "IMS not available on device.");
3301 }
3302 final long token = Binder.clearCallingIdentity();
3303 try {
3304 Phone phone = getPhone(subId);
3305 if (phone == null) {
3306 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3307 + subId + "'");
3308 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3309 }
3310 phone.getImsRegistrationTech(regTech -> {
3311 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3312 int regTechConverted = (regTech == null)
3313 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3314 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3315 regTechConverted);
3316 try {
3317 consumer.accept(regTechConverted);
3318 } catch (RemoteException e) {
3319 // Ignore if the remote process is no longer available to call back.
3320 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3321 }
3322 });
3323 } finally {
3324 Binder.restoreCallingIdentity(token);
3325 }
3326 }
3327
shilu366312e2019-12-17 09:28:10 -08003328 /**
3329 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3330 * @param subId The subscription to use to check the configuration.
3331 * @param c The callback that will be used to send the result.
3332 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003333 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003334 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3335 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003336 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003337 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003338 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3339 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3340 "IMS not available on device.");
3341 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003342 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3343 final long token = Binder.clearCallingIdentity();
3344 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003345 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003346 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003347 } catch (ImsException e) {
3348 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003349 } finally {
3350 Binder.restoreCallingIdentity(token);
3351 }
3352 }
3353
shilu366312e2019-12-17 09:28:10 -08003354 /**
3355 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3356 * @param subId The subscription to use to check the configuration.
3357 * @param c The callback that will be used to send the result.
3358 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003359 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003360 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
shilu366312e2019-12-17 09:28:10 -08003361 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003362 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003363 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3364 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3365 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003366
3367 final long token = Binder.clearCallingIdentity();
3368 try {
3369 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3370 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003371 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003372 } catch (ImsException e) {
3373 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3374 + "is inactive, ignoring unregister.");
3375 // If the subscription is no longer active, just return, since the callback
3376 // will already have been removed internally.
3377 } finally {
3378 Binder.restoreCallingIdentity(token);
3379 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003380 }
3381
3382 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003383 public boolean isCapable(int subId, int capability, int regTech) {
3384 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003385 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3386 final long token = Binder.clearCallingIdentity();
3387 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003388 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003389 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003390 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003391 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3392 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003393 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003394 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3395 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003396 } finally {
3397 Binder.restoreCallingIdentity(token);
3398 }
3399 }
3400
3401 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003402 public boolean isAvailable(int subId, int capability, int regTech) {
3403 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003404 final long token = Binder.clearCallingIdentity();
3405 try {
3406 Phone phone = getPhone(subId);
3407 if (phone == null) return false;
3408 return phone.isImsCapabilityAvailable(capability, regTech);
3409 } finally {
3410 Binder.restoreCallingIdentity(token);
3411 }
3412 }
3413
Brad Ebinger77b832e2019-10-17 17:03:22 -07003414 /**
3415 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3416 * subscription.
3417 * @param subId The subscription to use to check the configuration.
3418 * @param callback The callback that will be used to send the result.
3419 * @param capability The MmTelFeature capability that will be used to send the result.
3420 * @param transportType The transport type of the MmTelFeature capability.
3421 */
3422 @Override
3423 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3424 int transportType) {
3425 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3426 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3427 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3428 "IMS not available on device.");
3429 }
3430 final long token = Binder.clearCallingIdentity();
3431 try {
3432 int slotId = getSlotIndex(subId);
3433 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3434 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3435 + subId + "'");
3436 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3437 }
3438 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3439 transportType, aBoolean -> {
3440 try {
3441 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3442 } catch (RemoteException e) {
3443 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3444 + "running. Ignore");
3445 }
3446 });
3447 } finally {
3448 Binder.restoreCallingIdentity(token);
3449 }
3450 }
3451
shilu366312e2019-12-17 09:28:10 -08003452 /**
3453 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3454 * @param subId The subscription to use to check the configuration.
3455 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003456 @Override
3457 public boolean isAdvancedCallingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003458 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
3459 enforceReadPrivilegedPermission("isAdvancedCallingSettingEnabled");
3460
Brad Ebinger35c841c2018-10-01 10:40:55 -07003461 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3462 final long token = Binder.clearCallingIdentity();
3463 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003464 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003465 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003466 } catch (ImsException e) {
3467 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003468 } finally {
3469 Binder.restoreCallingIdentity(token);
3470 }
3471 }
3472
3473 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003474 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003476 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003477 final long identity = Binder.clearCallingIdentity();
3478 try {
3479 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003480 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003481 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003482 } catch (ImsException e) {
3483 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003484 } finally {
3485 Binder.restoreCallingIdentity(identity);
3486 }
3487 }
3488
shilu366312e2019-12-17 09:28:10 -08003489 /**
3490 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3491 * @param subId The subscription to use to check the configuration.
3492 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003493 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003494 public boolean isVtSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003495 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003496 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003497 final long identity = Binder.clearCallingIdentity();
3498 try {
3499 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003500 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3501 } catch (ImsException e) {
3502 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003503 } finally {
3504 Binder.restoreCallingIdentity(identity);
3505 }
3506 }
3507
3508 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003509 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003510 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003511 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003512 final long identity = Binder.clearCallingIdentity();
3513 try {
3514 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003515 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003516 } catch (ImsException e) {
3517 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003518 } finally {
3519 Binder.restoreCallingIdentity(identity);
3520 }
3521 }
3522
shilu366312e2019-12-17 09:28:10 -08003523 /**
3524 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3525 * @param subId The subscription to use to check the configuration.
3526 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003527 @Override
3528 public boolean isVoWiFiSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003529 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003530 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3531 final long identity = Binder.clearCallingIdentity();
3532 try {
3533 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003534 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003535 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003536 } catch (ImsException e) {
3537 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003538 } finally {
3539 Binder.restoreCallingIdentity(identity);
3540 }
3541 }
3542
3543 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003544 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003545 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003546 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003547 final long identity = Binder.clearCallingIdentity();
3548 try {
3549 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003550 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003551 } catch (ImsException e) {
3552 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003553 } finally {
3554 Binder.restoreCallingIdentity(identity);
3555 }
3556 }
3557
shilu366312e2019-12-17 09:28:10 -08003558 /**
3559 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3560 * @param subId The subscription to use to check the configuration.
3561 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003562 @Override
3563 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003564 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003565 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3566 final long identity = Binder.clearCallingIdentity();
3567 try {
3568 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003569 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003570 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003571 } catch (ImsException e) {
3572 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003573 } finally {
3574 Binder.restoreCallingIdentity(identity);
3575 }
3576 }
3577
3578 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003579 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003580 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003581 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003582 final long identity = Binder.clearCallingIdentity();
3583 try {
3584 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003585 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003586 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003587 } catch (ImsException e) {
3588 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003589 } finally {
3590 Binder.restoreCallingIdentity(identity);
3591 }
3592 }
3593
3594 @Override
3595 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3597 "setVoWiFiNonPersistent");
3598 final long identity = Binder.clearCallingIdentity();
3599 try {
3600 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003601 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003602 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003603 } catch (ImsException e) {
3604 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003605 } finally {
3606 Binder.restoreCallingIdentity(identity);
3607 }
3608 }
3609
shilu366312e2019-12-17 09:28:10 -08003610 /**
3611 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3612 * @param subId The subscription to use to check the configuration.
3613 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003614 @Override
3615 public int getVoWiFiModeSetting(int subId) {
shilu366312e2019-12-17 09:28:10 -08003616 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003617 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3618 final long identity = Binder.clearCallingIdentity();
3619 try {
3620 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003621 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003622 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003623 } catch (ImsException e) {
3624 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003625 } finally {
3626 Binder.restoreCallingIdentity(identity);
3627 }
3628 }
3629
3630 @Override
3631 public void setVoWiFiModeSetting(int subId, int mode) {
3632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3633 "setVoWiFiModeSetting");
3634 final long identity = Binder.clearCallingIdentity();
3635 try {
3636 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003637 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003638 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003639 } catch (ImsException e) {
3640 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003641 } finally {
3642 Binder.restoreCallingIdentity(identity);
3643 }
3644 }
3645
3646 @Override
3647 public int getVoWiFiRoamingModeSetting(int subId) {
3648 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3649 final long identity = Binder.clearCallingIdentity();
3650 try {
3651 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003652 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003653 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003654 } catch (ImsException e) {
3655 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003656 } finally {
3657 Binder.restoreCallingIdentity(identity);
3658 }
3659 }
3660
3661 @Override
3662 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3664 "setVoWiFiRoamingModeSetting");
3665 final long identity = Binder.clearCallingIdentity();
3666 try {
3667 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003668 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003669 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003670 } catch (ImsException e) {
3671 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003672 } finally {
3673 Binder.restoreCallingIdentity(identity);
3674 }
3675 }
3676
3677 @Override
3678 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3679 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3680 "setRttCapabilityEnabled");
3681 final long identity = Binder.clearCallingIdentity();
3682 try {
3683 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003684 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3685 } catch (ImsException e) {
3686 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003687 } finally {
3688 Binder.restoreCallingIdentity(identity);
3689 }
3690 }
3691
shilu366312e2019-12-17 09:28:10 -08003692 /**
3693 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3694 * @param subId The subscription to use to check the configuration.
3695 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003696 @Override
3697 public boolean isTtyOverVolteEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003698 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003699 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3700 final long identity = Binder.clearCallingIdentity();
3701 try {
3702 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003703 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003704 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003705 } catch (ImsException e) {
3706 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003707 } finally {
3708 Binder.restoreCallingIdentity(identity);
3709 }
3710 }
3711
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003712 @Override
3713 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3714 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3715 final long identity = Binder.clearCallingIdentity();
3716 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003717 if (!isImsAvailableOnDevice()) {
3718 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3719 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003720 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003721 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003722 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003723 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003724 } catch (ImsException e) {
3725 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003726 } finally {
3727 Binder.restoreCallingIdentity(identity);
3728 }
3729 }
3730
3731 @Override
3732 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3733 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3734 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003735 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3736 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3737 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003738 try {
3739 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003740 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003741 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003742 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003743 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3744 + "is inactive, ignoring unregister.");
3745 // If the subscription is no longer active, just return, since the callback will already
3746 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003747 } finally {
3748 Binder.restoreCallingIdentity(identity);
3749 }
3750 }
3751
allenwtsu99c623b2020-01-03 18:24:23 +08003752
3753 private void checkModifyPhoneStatePermission(int subId, String message) {
3754 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3755 message);
3756 }
3757
3758 private boolean isImsProvisioningRequired(int subId, int capability,
3759 boolean isMmtelCapability) {
3760 Phone phone = getPhone(subId);
3761 if (phone == null) {
3762 loge("phone instance null for subid " + subId);
3763 return false;
3764 }
3765 if (isMmtelCapability) {
3766 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3767 return false;
3768 }
3769 } else {
3770 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3771 return false;
3772 }
3773 }
3774 return true;
3775 }
3776
3777 @Override
3778 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3779 boolean isProvisioned) {
3780 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3781
3782 final long identity = Binder.clearCallingIdentity();
3783 try {
3784 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3785 if (!isImsProvisioningRequired(subId, capability, false)) {
3786 return;
3787 }
3788
3789 // this capability requires provisioning, route to the correct API.
3790 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3791 switch (capability) {
3792 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3793 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3794 ims.setEabProvisioned(isProvisioned);
3795 break;
3796 default: {
3797 throw new IllegalArgumentException("Tried to set provisioning for "
3798 + "rcs capability '" + capability + "', which does not require "
3799 + "provisioning.");
3800 }
3801 }
3802 } finally {
3803 Binder.restoreCallingIdentity(identity);
3804 }
3805
3806 }
3807
3808
3809 @Override
3810 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3811 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3812 final long identity = Binder.clearCallingIdentity();
3813 try {
3814 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3815 if (!isImsProvisioningRequired(subId, capability, false)) {
3816 return true;
3817 }
3818
3819 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3820 switch (capability) {
3821 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3822 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3823 return ims.isEabProvisionedOnDevice();
3824
3825 default: {
3826 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3827 + "capability '" + capability + "', which does not require "
3828 + "provisioning.");
3829 }
3830 }
3831
3832 } finally {
3833 Binder.restoreCallingIdentity(identity);
3834 }
3835 }
3836
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003837 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003838 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3839 boolean isProvisioned) {
3840 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3841 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3842 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3843 }
allenwtsu99c623b2020-01-03 18:24:23 +08003844 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003845 final long identity = Binder.clearCallingIdentity();
3846 try {
3847 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003848 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003849 return;
3850 }
3851
3852 // this capability requires provisioning, route to the correct API.
3853 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3854 switch (capability) {
3855 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3856 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3857 ims.setVolteProvisioned(isProvisioned);
3858 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3859 ims.setWfcProvisioned(isProvisioned);
3860 }
3861 break;
3862 }
3863 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3864 // There is currently no difference in VT provisioning type.
3865 ims.setVtProvisioned(isProvisioned);
3866 break;
3867 }
3868 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3869 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3870 // change the capability of the feature instead if needed.
3871 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3872 == isProvisioned) {
3873 // No change in provisioning.
3874 return;
3875 }
3876 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3877 try {
3878 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003879 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003880 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3881 + ", Exception" + e.getMessage());
3882 }
3883 break;
3884 }
3885 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003886 throw new IllegalArgumentException("Tried to set provisioning for "
3887 + "MmTel capability '" + capability + "', which does not require "
3888 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003889 }
3890 }
3891
3892 } finally {
3893 Binder.restoreCallingIdentity(identity);
3894 }
3895 }
3896
3897 @Override
3898 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3899 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3900 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3901 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3902 }
3903 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3904 final long identity = Binder.clearCallingIdentity();
3905 try {
3906 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003907 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003908 return true;
3909 }
3910
3911 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3912 switch (capability) {
3913 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3914 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3915 return ims.isVolteProvisionedOnDevice();
3916 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3917 return ims.isWfcProvisionedOnDevice();
3918 }
3919 // This should never happen, since we are checking tech above to make sure it
3920 // is either LTE or IWLAN.
3921 throw new IllegalArgumentException("Invalid radio technology for voice "
3922 + "capability.");
3923 }
3924 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3925 // There is currently no difference in VT provisioning type.
3926 return ims.isVtProvisionedOnDevice();
3927 }
3928 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3929 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3930 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3931 }
3932 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003933 throw new IllegalArgumentException(
3934 "Tried to get provisioning for MmTel capability '" + capability
3935 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003936 }
3937 }
3938
3939 } finally {
3940 Binder.restoreCallingIdentity(identity);
3941 }
3942 }
3943
3944 @Override
3945 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3946 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3947 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3948 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3949 }
3950 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3951 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3952 return (provisionedBits & capability) > 0;
3953 }
3954
3955 @Override
3956 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3957 boolean isProvisioned) {
3958 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3959 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3960 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3961 }
3962 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3963 "setProvisioningStatusForCapability");
3964 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3965 // If the current provisioning status for capability already matches isProvisioned,
3966 // do nothing.
3967 if (((provisionedBits & capability) > 0) == isProvisioned) {
3968 return;
3969 }
3970 if (isProvisioned) {
3971 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3972 } else {
3973 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3974 }
3975 }
3976
3977 /**
3978 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3979 * technology. The bitfield should mirror the bitfield defined by
3980 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3981 */
3982 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3983 String key = getMmTelProvisioningKey(subId, tech);
3984 // Default is no capabilities are provisioned.
3985 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3986 }
3987
3988 /**
3989 * Sets the MmTel capability provisioning bitfield (defined by
3990 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3991 * technology specified.
3992 *
3993 * Note: This is a synchronous command and should not be called on UI thread.
3994 */
3995 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3996 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3997 String key = getMmTelProvisioningKey(subId, tech);
3998 editor.putInt(key, newField);
3999 editor.commit();
4000 }
4001
4002 private static String getMmTelProvisioningKey(int subId, int tech) {
4003 // resulting key is provision_ims_mmtel_{subId}_{tech}
4004 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4005 }
4006
4007 /**
4008 * Query CarrierConfig to see if the specified capability requires provisioning for the
4009 * carrier associated with the subscription id.
4010 */
4011 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4012 int capability) {
4013 CarrierConfigManager configManager = new CarrierConfigManager(context);
4014 PersistableBundle c = configManager.getConfigForSubId(subId);
4015 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004016 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004017 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4018 false);
4019 boolean requireVoiceVtProvisioning = c.getBoolean(
4020 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4021
4022 // First check to make sure that the capability requires provisioning.
4023 switch (capability) {
4024 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4025 // intentional fallthrough
4026 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4027 if (requireVoiceVtProvisioning) {
4028 // Voice and Video requires provisioning
4029 return true;
4030 }
4031 break;
4032 }
4033 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4034 if (requireUtProvisioning) {
4035 // UT requires provisioning
4036 return true;
4037 }
4038 break;
4039 }
4040 }
4041 return false;
4042 }
4043
allenwtsu99c623b2020-01-03 18:24:23 +08004044 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4045 int capability) {
4046 CarrierConfigManager configManager = new CarrierConfigManager(context);
4047 PersistableBundle c = configManager.getConfigForSubId(subId);
4048
4049 boolean requireRcsProvisioning = c.getBoolean(
4050 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4051
4052 // First check to make sure that the capability requires provisioning.
4053 switch (capability) {
4054 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4055 // intentional fallthrough
4056 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4057 if (requireRcsProvisioning) {
4058 // OPTION or PRESENCE requires provisioning
4059 return true;
4060 }
4061 break;
4062 }
4063 }
4064 return false;
4065 }
4066
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004067 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004068 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004069 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4070 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4071 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004072 enforceReadPrivilegedPermission("getImsProvisioningInt");
4073 final long identity = Binder.clearCallingIdentity();
4074 try {
4075 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004076 int slotId = getSlotIndex(subId);
4077 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4078 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4079 + subId + "' for key:" + key);
4080 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4081 }
4082 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004083 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004084 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4085 + subId + "' for key:" + key);
4086 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004087 } finally {
4088 Binder.restoreCallingIdentity(identity);
4089 }
4090 }
4091
4092 @Override
4093 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004094 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4095 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4096 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004097 enforceReadPrivilegedPermission("getImsProvisioningString");
4098 final long identity = Binder.clearCallingIdentity();
4099 try {
4100 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004101 int slotId = getSlotIndex(subId);
4102 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4103 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4104 + subId + "' for key:" + key);
4105 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4106 }
4107 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004108 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004109 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4110 + subId + "' for key:" + key);
4111 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004112 } finally {
4113 Binder.restoreCallingIdentity(identity);
4114 }
4115 }
4116
4117 @Override
4118 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004119 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4120 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4121 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004122 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4123 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004124 final long identity = Binder.clearCallingIdentity();
4125 try {
4126 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004127 int slotId = getSlotIndex(subId);
4128 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4129 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4130 + subId + "' for key:" + key);
4131 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4132 }
4133 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004134 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004135 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4136 + "' for key:" + key);
4137 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004138 } finally {
4139 Binder.restoreCallingIdentity(identity);
4140 }
4141 }
4142
4143 @Override
4144 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004145 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4146 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4147 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004148 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4149 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004150 final long identity = Binder.clearCallingIdentity();
4151 try {
4152 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004153 int slotId = getSlotIndex(subId);
4154 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4155 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4156 + subId + "' for key:" + key);
4157 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4158 }
4159 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004160 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004161 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4162 + "' for key:" + key);
4163 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004164 } finally {
4165 Binder.restoreCallingIdentity(identity);
4166 }
4167 }
4168
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004169 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004170 int slotId = SubscriptionManager.getSlotIndex(subId);
4171 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004172 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4173 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004174 }
4175 return slotId;
4176 }
4177
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004178 private int getSlotIndex(int subId) {
4179 int slotId = SubscriptionManager.getSlotIndex(subId);
4180 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4181 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4182 }
4183 return slotId;
4184 }
4185
Wink Saville36469e72014-06-11 15:17:00 -07004186 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004187 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004188 */
4189 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004190 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4191 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004192 final int targetSdk = getTargetSdk(callingPackage);
4193 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004194 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004195 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004196 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004197 mApp, subId, callingPackage, callingFeatureId,
4198 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004199 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4200 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004201
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004202 final long identity = Binder.clearCallingIdentity();
4203 try {
4204 final Phone phone = getPhone(subId);
4205 if (phone != null) {
4206 return phone.getServiceState().getDataNetworkType();
4207 } else {
4208 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4209 }
4210 } finally {
4211 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004212 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004213 }
4214
4215 /**
4216 * Returns the data network type
4217 */
4218 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004219 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4220 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4221 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004222 }
4223
4224 /**
4225 * Returns the data network type for a subId
4226 */
4227 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004228 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4229 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004230 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004231 mApp, subId, callingPackage, callingFeatureId,
4232 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004233 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4234 }
4235
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004236 final long identity = Binder.clearCallingIdentity();
4237 try {
4238 final Phone phone = getPhone(subId);
4239 if (phone != null) {
4240 return phone.getServiceState().getDataNetworkType();
4241 } else {
4242 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4243 }
4244 } finally {
4245 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004246 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004247 }
4248
4249 /**
Wink Saville36469e72014-06-11 15:17:00 -07004250 * Returns the Voice network type for a subId
4251 */
4252 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004253 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4254 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004255 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004256 mApp, subId, callingPackage, callingFeatureId,
4257 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004258 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4259 }
4260
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004261 final long identity = Binder.clearCallingIdentity();
4262 try {
4263 final Phone phone = getPhone(subId);
4264 if (phone != null) {
4265 return phone.getServiceState().getVoiceNetworkType();
4266 } else {
4267 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4268 }
4269 } finally {
4270 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004271 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004272 }
4273
4274 /**
4275 * @return true if a ICC card is present
4276 */
4277 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004278 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004279 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4280 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004281 }
4282
4283 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004284 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004285 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004286 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004287 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004288 final long identity = Binder.clearCallingIdentity();
4289 try {
4290 final Phone phone = PhoneFactory.getPhone(slotIndex);
4291 if (phone != null) {
4292 return phone.getIccCard().hasIccCard();
4293 } else {
4294 return false;
4295 }
4296 } finally {
4297 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004298 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004299 }
4300
4301 /**
4302 * Return if the current radio is LTE on CDMA. This
4303 * is a tri-state return value as for a period of time
4304 * the mode may be unknown.
4305 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004306 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004307 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004308 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004309 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004310 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004311 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4312 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4313 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004314 }
4315
Sanket Padawe356d7632015-06-22 14:03:32 -07004316 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004317 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4318 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004319 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004320 mApp, subId, callingPackage, callingFeatureId,
4321 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004322 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4323 }
4324
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004325 final long identity = Binder.clearCallingIdentity();
4326 try {
4327 final Phone phone = getPhone(subId);
4328 if (phone == null) {
4329 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4330 } else {
4331 return phone.getLteOnCdmaMode();
4332 }
4333 } finally {
4334 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004335 }
Wink Saville36469e72014-06-11 15:17:00 -07004336 }
4337
Wink Saville36469e72014-06-11 15:17:00 -07004338 /**
4339 * {@hide}
4340 * Returns Default subId, 0 in the case of single standby.
4341 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004342 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004343 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004344 }
4345
Shishir Agrawala9f32182016-04-12 12:00:16 -07004346 private int getSlotForDefaultSubscription() {
4347 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4348 }
4349
Wink Savilleb564aae2014-10-23 10:18:09 -07004350 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004351 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004352 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004353
Pengquan Menge92a50d2018-09-21 15:54:48 -07004354 private boolean isActiveSubscription(int subId) {
4355 return mSubscriptionController.isActiveSubId(subId);
4356 }
4357
Ihab Awadf2177b72013-11-25 13:33:23 -08004358 /**
4359 * @see android.telephony.TelephonyManager.WifiCallingChoices
4360 */
4361 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004362 final long identity = Binder.clearCallingIdentity();
4363 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004364 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004365 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4366 getWhenToMakeWifiCallsDefaultPreference());
4367 } finally {
4368 Binder.restoreCallingIdentity(identity);
4369 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004370 }
4371
4372 /**
4373 * @see android.telephony.TelephonyManager.WifiCallingChoices
4374 */
4375 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004376 final long identity = Binder.clearCallingIdentity();
4377 try {
4378 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004379 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004380 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4381 } finally {
4382 Binder.restoreCallingIdentity(identity);
4383 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004384 }
4385
Sailesh Nepald1e68152013-12-12 19:08:02 -08004386 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004387 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004388 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004389 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004390
Jordan Liu4c733742019-02-28 12:03:40 -08004391 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4392 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4393 if (phoneId == -1) {
4394 throw new IllegalArgumentException("Given slot index: " + slotIndex
4395 + " does not correspond to an active phone");
4396 }
4397 return PhoneFactory.getPhone(phoneId);
4398 }
4399
Shishir Agrawal566b7612013-10-28 14:41:00 -07004400 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004401 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4402 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004403 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4404 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004405 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004406 if (DBG) {
4407 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4408 }
4409 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4410 p2);
4411 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004412
Jordan Liu4c733742019-02-28 12:03:40 -08004413
4414 @Override
4415 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4416 int slotIndex, String callingPackage, String aid, int p2) {
4417 enforceModifyPermission();
4418 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4419 if (DBG) {
4420 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4421 }
4422 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4423 callingPackage, aid, p2);
4424 }
4425
4426 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4427 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004428 final long identity = Binder.clearCallingIdentity();
4429 try {
4430 if (TextUtils.equals(ISDR_AID, aid)) {
4431 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004432 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4433 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004434 if (bestComponent == null
4435 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4436 loge("The calling package is not allowed to access ISD-R.");
4437 throw new SecurityException(
4438 "The calling package is not allowed to access ISD-R.");
4439 }
Derek Tan740e1672017-06-27 14:56:27 -07004440 }
Derek Tan740e1672017-06-27 14:56:27 -07004441
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004442 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004443 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4444 null /* workSource */);
4445 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004446 return response;
4447 } finally {
4448 Binder.restoreCallingIdentity(identity);
4449 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004450 }
4451
4452 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004453 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4455 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004456 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4457 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4458 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004459
Jordan Liu4c733742019-02-28 12:03:40 -08004460 @Override
4461 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4462 enforceModifyPermission();
4463 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4464 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4465 channel);
4466 }
4467
4468 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004469 final long identity = Binder.clearCallingIdentity();
4470 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004471 if (channel < 0) {
4472 return false;
4473 }
Jordan Liu4c733742019-02-28 12:03:40 -08004474 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4475 null /* workSource */);
4476 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004477 return success;
4478 } finally {
4479 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004480 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004481 }
4482
4483 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004484 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004485 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004486 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4487 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004488 if (DBG) {
4489 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4490 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4491 + p3 + " data=" + data);
4492 }
4493 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4494 command, p1, p2, p3, data);
4495 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004496
Jordan Liu4c733742019-02-28 12:03:40 -08004497 @Override
4498 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4499 int command, int p1, int p2, int p3, String data) {
4500 enforceModifyPermission();
4501 if (DBG) {
4502 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4503 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4504 + p3 + " data=" + data);
4505 }
4506 return iccTransmitApduLogicalChannelWithPermission(
4507 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4508 data);
4509 }
4510
4511 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4512 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004513 final long identity = Binder.clearCallingIdentity();
4514 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004515 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004516 return "";
4517 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004518
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004519 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004520 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4521 null /* workSource */);
4522 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004523
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004524 // Append the returned status code to the end of the response payload.
4525 String s = Integer.toHexString(
4526 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4527 if (response.payload != null) {
4528 s = IccUtils.bytesToHexString(response.payload) + s;
4529 }
4530 return s;
4531 } finally {
4532 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004533 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004534 }
Jake Hambye994d462014-02-03 13:10:13 -08004535
Evan Charltonc66da362014-05-16 14:06:40 -07004536 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004537 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4538 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004539 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4540 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004541 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004542 if (DBG) {
4543 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4544 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4545 }
4546 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4547 cla, command, p1, p2, p3, data);
4548 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004549
Jordan Liu4c733742019-02-28 12:03:40 -08004550 @Override
4551 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4552 int command, int p1, int p2, int p3, String data) {
4553 enforceModifyPermission();
4554 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4555 if (DBG) {
4556 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4557 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4558 + " data=" + data);
4559 }
4560
4561 return iccTransmitApduBasicChannelWithPermission(
4562 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4563 p2, p3, data);
4564 }
4565
4566 // open APDU basic channel assuming the caller has sufficient permissions
4567 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4568 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004569 final long identity = Binder.clearCallingIdentity();
4570 try {
4571 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4572 && TextUtils.equals(ISDR_AID, data)) {
4573 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004574 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4575 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004576 if (bestComponent == null
4577 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4578 loge("The calling package is not allowed to select ISD-R.");
4579 throw new SecurityException(
4580 "The calling package is not allowed to select ISD-R.");
4581 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004582 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004583
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004584 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004585 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4586 null /* workSource */);
4587 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004588
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004589 // Append the returned status code to the end of the response payload.
4590 String s = Integer.toHexString(
4591 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4592 if (response.payload != null) {
4593 s = IccUtils.bytesToHexString(response.payload) + s;
4594 }
4595 return s;
4596 } finally {
4597 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004598 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004599 }
4600
4601 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004602 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004603 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004604 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4605 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004606
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004607 final long identity = Binder.clearCallingIdentity();
4608 try {
4609 if (DBG) {
4610 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4611 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4612 }
4613
4614 IccIoResult response =
4615 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4616 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4617 subId);
4618
4619 if (DBG) {
4620 log("Exchange SIM_IO [R]" + response);
4621 }
4622
4623 byte[] result = null;
4624 int length = 2;
4625 if (response.payload != null) {
4626 length = 2 + response.payload.length;
4627 result = new byte[length];
4628 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4629 } else {
4630 result = new byte[length];
4631 }
4632
4633 result[length - 1] = (byte) response.sw2;
4634 result[length - 2] = (byte) response.sw1;
4635 return result;
4636 } finally {
4637 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004638 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004639 }
4640
Nathan Haroldb3014052017-01-25 15:57:32 -08004641 /**
4642 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4643 * on a particular subscription
4644 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004645 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4646 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004647 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004648 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004649 return null;
4650 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004651
4652 final long identity = Binder.clearCallingIdentity();
4653 try {
4654 if (appType != TelephonyManager.APPTYPE_USIM
4655 && appType != TelephonyManager.APPTYPE_SIM) {
4656 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4657 return null;
4658 }
4659 Object response = sendRequest(
4660 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4661 if (response instanceof String[]) {
4662 return (String[]) response;
4663 }
yincheng zhaod698b842019-09-06 17:06:54 -07004664 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004665 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004666 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004667 } finally {
4668 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004669 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004670 }
4671
yincheng zhaod698b842019-09-06 17:06:54 -07004672 /**
4673 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4674 * subscription.
4675 *
4676 * @param subId the id of the subscription.
4677 * @param appType the uicc app type, must be USIM or SIM.
4678 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4679 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004680 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004681 * @return number of fplmns that is successfully written to the SIM.
4682 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004683 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4684 String callingFeatureId) {
4685 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4686 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004687 if (DBG) logv("no permissions for setForbiddenplmns");
4688 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4689 }
4690 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4691 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4692 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4693 }
4694 if (fplmns == null) {
4695 throw new IllegalArgumentException("Fplmn List provided is null");
4696 }
4697 for (String fplmn : fplmns) {
4698 if (!CellIdentity.isValidPlmn(fplmn)) {
4699 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4700 }
4701 }
4702 final long identity = Binder.clearCallingIdentity();
4703 try {
4704 Object response = sendRequest(
4705 CMD_SET_FORBIDDEN_PLMNS,
4706 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4707 subId);
4708 return (int) response;
4709 } finally {
4710 Binder.restoreCallingIdentity(identity);
4711 }
4712 }
4713
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004714 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004715 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004716 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4717 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004718
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004719 final long identity = Binder.clearCallingIdentity();
4720 try {
4721 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4722 if (response.payload == null) {
4723 return "";
4724 }
Evan Charltonc66da362014-05-16 14:06:40 -07004725
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004726 // Append the returned status code to the end of the response payload.
4727 String s = Integer.toHexString(
4728 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4729 s = IccUtils.bytesToHexString(response.payload) + s;
4730 return s;
4731 } finally {
4732 Binder.restoreCallingIdentity(identity);
4733 }
Evan Charltonc66da362014-05-16 14:06:40 -07004734 }
4735
Jake Hambye994d462014-02-03 13:10:13 -08004736 /**
4737 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4738 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4739 *
4740 * @param itemID the ID of the item to read
4741 * @return the NV item as a String, or null on error.
4742 */
4743 @Override
4744 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004745 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004746 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4747 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004748
4749 final long identity = Binder.clearCallingIdentity();
4750 try {
4751 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004752 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004753 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4754 return value;
4755 } finally {
4756 Binder.restoreCallingIdentity(identity);
4757 }
Jake Hambye994d462014-02-03 13:10:13 -08004758 }
4759
4760 /**
4761 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4762 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4763 *
4764 * @param itemID the ID of the item to read
4765 * @param itemValue the value to write, as a String
4766 * @return true on success; false on any failure
4767 */
4768 @Override
4769 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004770 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4772 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004773
4774 final long identity = Binder.clearCallingIdentity();
4775 try {
4776 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4777 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004778 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004779 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4780 return success;
4781 } finally {
4782 Binder.restoreCallingIdentity(identity);
4783 }
Jake Hambye994d462014-02-03 13:10:13 -08004784 }
4785
4786 /**
4787 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4788 * Used for device configuration by some CDMA operators.
4789 *
4790 * @param preferredRoamingList byte array containing the new PRL
4791 * @return true on success; false on any failure
4792 */
4793 @Override
4794 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4796 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004797
4798 final long identity = Binder.clearCallingIdentity();
4799 try {
4800 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4801 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4802 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4803 return success;
4804 } finally {
4805 Binder.restoreCallingIdentity(identity);
4806 }
Jake Hambye994d462014-02-03 13:10:13 -08004807 }
4808
4809 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004810 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004811 * Used for device configuration by some CDMA operators.
4812 *
chen xu6dac5ab2018-10-26 17:39:23 -07004813 * @param slotIndex - device slot.
4814 *
Jake Hambye994d462014-02-03 13:10:13 -08004815 * @return true on success; false on any failure
4816 */
4817 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004818 public boolean resetModemConfig(int slotIndex) {
4819 Phone phone = PhoneFactory.getPhone(slotIndex);
4820 if (phone != null) {
4821 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4822 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004823
chen xu6dac5ab2018-10-26 17:39:23 -07004824 final long identity = Binder.clearCallingIdentity();
4825 try {
4826 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4827 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4828 return success;
4829 } finally {
4830 Binder.restoreCallingIdentity(identity);
4831 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004832 }
chen xu6dac5ab2018-10-26 17:39:23 -07004833 return false;
4834 }
4835
4836 /**
4837 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4838 *
4839 * @param slotIndex - device slot.
4840 *
4841 * @return true on success; false on any failure
4842 */
4843 @Override
4844 public boolean rebootModem(int slotIndex) {
4845 Phone phone = PhoneFactory.getPhone(slotIndex);
4846 if (phone != null) {
4847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4848 mApp, phone.getSubId(), "rebootModem");
4849
4850 final long identity = Binder.clearCallingIdentity();
4851 try {
4852 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4853 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4854 return success;
4855 } finally {
4856 Binder.restoreCallingIdentity(identity);
4857 }
4858 }
4859 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004860 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004861
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004862 public String[] getPcscfAddress(String apnType, String callingPackage,
4863 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004864 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004865 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4866 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004867 return new String[0];
4868 }
4869
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004870 final long identity = Binder.clearCallingIdentity();
4871 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004872 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004873 } finally {
4874 Binder.restoreCallingIdentity(identity);
4875 }
Wink Saville36469e72014-06-11 15:17:00 -07004876 }
4877
Brad Ebinger51f743a2017-01-23 13:50:20 -08004878 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004879 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4880 * {@link #disableIms(int)}.
4881 * @param slotIndex device slot.
4882 */
4883 public void resetIms(int slotIndex) {
4884 enforceModifyPermission();
4885
4886 final long identity = Binder.clearCallingIdentity();
4887 try {
4888 if (mImsResolver == null) {
4889 // may happen if the does not support IMS.
4890 return;
4891 }
4892 mImsResolver.disableIms(slotIndex);
4893 mImsResolver.enableIms(slotIndex);
4894 } finally {
4895 Binder.restoreCallingIdentity(identity);
4896 }
4897 }
4898
4899 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004900 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4901 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004902 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004903 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004904 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004905
4906 final long identity = Binder.clearCallingIdentity();
4907 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004908 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004909 // may happen if the device does not support IMS.
4910 return;
4911 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004912 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004913 } finally {
4914 Binder.restoreCallingIdentity(identity);
4915 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004916 }
4917
4918 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004919 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4920 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004921 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004922 public void disableIms(int slotId) {
4923 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004924
4925 final long identity = Binder.clearCallingIdentity();
4926 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004927 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004928 // may happen if the device does not support IMS.
4929 return;
4930 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004931 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004932 } finally {
4933 Binder.restoreCallingIdentity(identity);
4934 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004935 }
4936
4937 /**
4938 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4939 * feature or {@link null} if the service is not available. If the feature is available, the
4940 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4941 */
4942 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004943 IImsServiceFeatureCallback callback) {
4944 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004945
4946 final long identity = Binder.clearCallingIdentity();
4947 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004948 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004949 // may happen if the device does not support IMS.
4950 return null;
4951 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004952 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004953 } finally {
4954 Binder.restoreCallingIdentity(identity);
4955 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004956 }
4957
4958 /**
4959 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4960 * feature during emergency calling or {@link null} if the service is not available. If the
4961 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4962 * listener for feature updates.
4963 */
4964 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4965 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004966
4967 final long identity = Binder.clearCallingIdentity();
4968 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004969 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004970 // may happen if the device does not support IMS.
4971 return null;
4972 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004973 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974 } finally {
4975 Binder.restoreCallingIdentity(identity);
4976 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004977 }
4978
Brad Ebinger5f64b052017-12-14 14:26:15 -08004979 /**
4980 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004981 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004982 */
4983 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4984 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004985
4986 final long identity = Binder.clearCallingIdentity();
4987 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004988 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004989 // may happen if the device does not support IMS.
4990 return null;
4991 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004992 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004993 } finally {
4994 Binder.restoreCallingIdentity(identity);
4995 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004996 }
4997
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004998 /**
4999 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005000 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005001 */
5002 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5003 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004
5005 final long identity = Binder.clearCallingIdentity();
5006 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005007 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005008 // may happen if the device does not support IMS.
5009 return null;
5010 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005011 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005012 } finally {
5013 Binder.restoreCallingIdentity(identity);
5014 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005015 }
5016
Brad Ebinger884c07b2018-02-15 16:17:40 -08005017 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005018 * Sets the ImsService Package Name that Telephony will bind to.
5019 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005020 * @param slotIndex the slot ID that the ImsService should bind for.
5021 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005022 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005023 * @param featureTypes An integer array of feature types associated with a packageName.
5024 * @param packageName The name of the package that the current configuration will be replaced
5025 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005026 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005027 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005028 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5029 int[] featureTypes, String packageName) {
5030 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5031 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005032 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5033 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005034 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005035
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005036 final long identity = Binder.clearCallingIdentity();
5037 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005038 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005039 // may happen if the device does not support IMS.
5040 return false;
5041 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005042 Map<Integer, String> featureConfig = new HashMap<>();
5043 for (int featureType : featureTypes) {
5044 featureConfig.put(featureType, packageName);
5045 }
5046 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5047 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005048 } finally {
5049 Binder.restoreCallingIdentity(identity);
5050 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005051 }
5052
5053 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005054 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005055 *
5056 * @param slotId The slot that the ImsService is associated with.
5057 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5058 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005059 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005060 * @return the package name of the ImsService configuration.
5061 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005062 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5063 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005064 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005065 TelephonyPermissions
5066 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5067 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5068 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005069
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005070 final long identity = Binder.clearCallingIdentity();
5071 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005072 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005073 // may happen if the device does not support IMS.
5074 return "";
5075 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005076 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005077 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5078 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005079 } finally {
5080 Binder.restoreCallingIdentity(identity);
5081 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005082 }
5083
Brad Ebinger77b832e2019-10-17 17:03:22 -07005084 /**
5085 * Get the MmTelFeature state associated with the requested subscription id.
5086 * @param subId The subscription that the MmTelFeature is associated with.
5087 * @param callback A callback with an integer containing the
5088 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5089 */
5090 @Override
5091 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5092 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5093 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5094 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5095 "IMS not available on device.");
5096 }
5097 final long token = Binder.clearCallingIdentity();
5098 try {
5099 int slotId = getSlotIndex(subId);
5100 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5101 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5102 + subId + "'");
5103 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5104 }
5105 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5106 try {
5107 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5108 } catch (RemoteException e) {
5109 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5110 + "Ignore");
5111 }
5112 });
5113 } finally {
5114 Binder.restoreCallingIdentity(token);
5115 }
5116 }
5117
Wink Saville36469e72014-06-11 15:17:00 -07005118 public void setImsRegistrationState(boolean registered) {
5119 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005120
5121 final long identity = Binder.clearCallingIdentity();
5122 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005123 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005124 } finally {
5125 Binder.restoreCallingIdentity(identity);
5126 }
Wink Saville36469e72014-06-11 15:17:00 -07005127 }
5128
5129 /**
Stuart Scott54788802015-03-30 13:18:01 -07005130 * Set the network selection mode to automatic.
5131 *
5132 */
5133 @Override
5134 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005135 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5136 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005137
5138 final long identity = Binder.clearCallingIdentity();
5139 try {
shilufc958392020-01-20 11:36:01 -08005140 if (!isActiveSubscription(subId)) {
5141 return;
5142 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005143 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5144 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5145 } finally {
5146 Binder.restoreCallingIdentity(identity);
5147 }
Stuart Scott54788802015-03-30 13:18:01 -07005148 }
5149
Pengquan Mengea84e042018-09-20 14:57:26 -07005150 /**
5151 * Ask the radio to connect to the input network and change selection mode to manual.
5152 *
5153 * @param subId the id of the subscription.
5154 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5155 * the operator to attach to.
5156 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5157 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5158 * normal network selection next time.
5159 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005160 */
5161 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005162 public boolean setNetworkSelectionModeManual(
5163 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005164 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5165 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005166
5167 if (!isActiveSubscription(subId)) {
5168 return false;
5169 }
5170
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005171 final long identity = Binder.clearCallingIdentity();
5172 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005173 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005174 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005175 if (DBG) {
5176 log("setNetworkSelectionModeManual: subId: " + subId
5177 + " operator: " + operatorInfo);
5178 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005179 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5180 } finally {
5181 Binder.restoreCallingIdentity(identity);
5182 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005183 }
5184
5185 /**
5186 * Scans for available networks.
5187 */
5188 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005189 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5190 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005191 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5192 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005193 LocationAccessPolicy.LocationPermissionResult locationResult =
5194 LocationAccessPolicy.checkLocationPermission(mApp,
5195 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5196 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005197 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005198 .setCallingPid(Binder.getCallingPid())
5199 .setCallingUid(Binder.getCallingUid())
5200 .setMethod("getCellNetworkScanResults")
5201 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5202 .build());
5203 switch (locationResult) {
5204 case DENIED_HARD:
5205 throw new SecurityException("Not allowed to access scan results -- location");
5206 case DENIED_SOFT:
5207 return null;
5208 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005209
Pengquan Menga1bb6272018-09-06 09:59:22 -07005210 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005211 try {
5212 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005213 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005214 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005215 } finally {
5216 Binder.restoreCallingIdentity(identity);
5217 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005218 }
5219
5220 /**
sqian80370722020-01-29 15:02:51 -08005221 * Get the call forwarding info, given the call forwarding reason.
5222 */
5223 @Override
5224 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5225 enforceReadPrivilegedPermission("getCallForwarding");
5226 long identity = Binder.clearCallingIdentity();
5227 try {
5228 if (DBG) {
5229 log("getCallForwarding: subId " + subId
5230 + " callForwardingReason" + callForwardingReason);
5231 }
5232 return (CallForwardingInfo) sendRequest(
5233 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5234 } finally {
5235 Binder.restoreCallingIdentity(identity);
5236 }
5237 }
5238
5239 /**
5240 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5241 * reason, the number to forward, and the timeout before the forwarding is attempted.
5242 */
5243 @Override
5244 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5245 enforceModifyPermission();
5246 long identity = Binder.clearCallingIdentity();
5247 try {
5248 if (DBG) {
5249 log("setCallForwarding: subId " + subId
5250 + " callForwardingInfo" + callForwardingInfo);
5251 }
5252 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5253 } finally {
5254 Binder.restoreCallingIdentity(identity);
5255 }
5256 }
5257
5258 /**
5259 * Get the call forwarding info, given the call forwarding reason.
5260 */
5261 @Override
5262 public int getCallWaitingStatus(int subId) {
5263 enforceReadPrivilegedPermission("getCallForwarding");
5264 long identity = Binder.clearCallingIdentity();
5265 try {
5266 if (DBG) log("getCallWaitingStatus: subId " + subId);
5267 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5268 } finally {
5269 Binder.restoreCallingIdentity(identity);
5270 }
5271 }
5272
5273 /**
5274 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5275 * reason, the number to forward, and the timeout before the forwarding is attempted.
5276 */
5277 @Override
5278 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5279 enforceModifyPermission();
5280 long identity = Binder.clearCallingIdentity();
5281 try {
5282 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5283 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5284 } finally {
5285 Binder.restoreCallingIdentity(identity);
5286 }
5287 }
5288
5289 /**
yinxub1bed742017-04-17 11:45:04 -07005290 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005291 *
yinxub1bed742017-04-17 11:45:04 -07005292 * @param subId id of the subscription
5293 * @param request contains the radio access networks with bands/channels to scan
5294 * @param messenger callback messenger for scan results or errors
5295 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005296 * @return the id of the requested scan which can be used to stop the scan.
5297 */
5298 @Override
5299 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005300 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005301 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5302 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005303 LocationAccessPolicy.LocationPermissionResult locationResult =
5304 LocationAccessPolicy.checkLocationPermission(mApp,
5305 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5306 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005307 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005308 .setCallingPid(Binder.getCallingPid())
5309 .setCallingUid(Binder.getCallingUid())
5310 .setMethod("requestNetworkScan")
5311 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5312 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005313 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005314 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005315 if (e != null) {
5316 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5317 throw e;
5318 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005319 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005320 return TelephonyScanManager.INVALID_SCAN_ID;
5321 }
5322 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005323 }
Hall Liu912dfd32019-04-25 14:02:26 -07005324 int callingUid = Binder.getCallingUid();
5325 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005326 final long identity = Binder.clearCallingIdentity();
5327 try {
5328 return mNetworkScanRequestTracker.startNetworkScan(
5329 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005330 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005331 } finally {
5332 Binder.restoreCallingIdentity(identity);
5333 }
yinxu504e1392017-04-12 16:03:22 -07005334 }
5335
Hall Liub2ac8ef2019-02-28 15:56:23 -08005336 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005337 NetworkScanRequest request, int subId) {
5338 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5339 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5340 boolean hasNetworkScanPermission =
5341 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5342 == PERMISSION_GRANTED;
5343
5344 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5345 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5346 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005347 }
5348
5349 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5350 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005351 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5352 return new SecurityException("Specific channels must not be"
5353 + " scanned without location access.");
5354 }
5355 }
5356 }
5357
Hall Liub2ac8ef2019-02-28 15:56:23 -08005358 return null;
5359 }
5360
yinxu504e1392017-04-12 16:03:22 -07005361 /**
5362 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005363 *
5364 * @param subId id of the subscription
5365 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005366 */
5367 @Override
5368 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5370 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005371
Hall Liu912dfd32019-04-25 14:02:26 -07005372 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005373 final long identity = Binder.clearCallingIdentity();
5374 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005375 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005376 } finally {
5377 Binder.restoreCallingIdentity(identity);
5378 }
yinxu504e1392017-04-12 16:03:22 -07005379 }
5380
5381 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005382 * Get the calculated preferred network type.
5383 * Used for debugging incorrect network type.
5384 *
5385 * @return the preferred network type, defined in RILConstants.java.
5386 */
5387 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005388 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005389 final Phone defaultPhone = getDefaultPhone();
5390 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005391 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005392 return RILConstants.PREFERRED_NETWORK_MODE;
5393 }
5394
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005395 final long identity = Binder.clearCallingIdentity();
5396 try {
5397 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005398 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005399 } finally {
5400 Binder.restoreCallingIdentity(identity);
5401 }
Junda Liu84d15a22014-07-02 11:21:04 -07005402 }
5403
5404 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005405 * Get the preferred network type.
5406 * Used for device configuration by some CDMA operators.
5407 *
5408 * @return the preferred network type, defined in RILConstants.java.
5409 */
5410 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005411 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005412 TelephonyPermissions
5413 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5414 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005415
5416 final long identity = Binder.clearCallingIdentity();
5417 try {
5418 if (DBG) log("getPreferredNetworkType");
5419 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5420 int networkType = (result != null ? result[0] : -1);
5421 if (DBG) log("getPreferredNetworkType: " + networkType);
5422 return networkType;
5423 } finally {
5424 Binder.restoreCallingIdentity(identity);
5425 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005426 }
5427
5428 /**
5429 * Set the preferred network type.
5430 * Used for device configuration by some CDMA operators.
5431 *
5432 * @param networkType the preferred network type, defined in RILConstants.java.
5433 * @return true on success; false on any failure.
5434 */
5435 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005436 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005437 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5438 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005439
5440 final long identity = Binder.clearCallingIdentity();
5441 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005442 Settings.Global.putInt(mApp.getContentResolver(),
5443 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5444 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005445 } finally {
5446 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005447 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005448 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005449
5450 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005451 * Get the allowed network types that store in the telephony provider.
5452 *
5453 * @param subId the id of the subscription.
5454 * @return allowedNetworkTypes the allowed network types.
5455 */
5456 @Override
5457 public long getAllowedNetworkTypes(int subId) {
5458 TelephonyPermissions
5459 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5460 mApp, subId, "getAllowedNetworkTypes");
5461
5462 final long identity = Binder.clearCallingIdentity();
5463 try {
5464 return SubscriptionManager.getLongSubscriptionProperty(
5465 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5466 } finally {
5467 Binder.restoreCallingIdentity(identity);
5468 }
5469 }
5470
5471 /**
5472 * Set the allowed network types.
5473 *
5474 * @param subId the id of the subscription.
5475 * @param allowedNetworkTypes the allowed network types.
5476 * @return true on success; false on any failure.
5477 */
5478 @Override
5479 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5480 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5481 mApp, subId, "setAllowedNetworkTypes");
5482 final long identity = Binder.clearCallingIdentity();
5483 try {
5484 SubscriptionManager.setSubscriptionProperty(subId,
5485 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5486 String.valueOf(allowedNetworkTypes));
5487 return setPreferredNetworkTypesInternal(subId);
5488 } finally {
5489 Binder.restoreCallingIdentity(identity);
5490 }
5491 }
5492
5493 private boolean setPreferredNetworkTypesInternal(int subId) {
5494 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5495 Settings.Global.getInt(mApp.getContentResolver(),
5496 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5497 RILConstants.PREFERRED_NETWORK_MODE));
5498 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5499 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5500 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5501 (int) (networkTypeBitMask & allowedNetworkTypes));
5502
5503 if (DBG) {
5504 log("setPreferredNetworkTypesInternal: subId " + subId
5505 + " networkTypes " + networkTypeBitMask
5506 + " allowedNetworkTypes " + allowedNetworkTypes
5507 + " networkMode " + networkMode);
5508 }
5509
5510 Boolean success = (Boolean) sendRequest(
5511 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5512 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5513 return success;
5514 }
5515
5516 /**
Miaoa84611c2019-03-15 09:21:10 +08005517 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005518 *
Miaoa84611c2019-03-15 09:21:10 +08005519 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005520 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005521 * @hide
5522 */
5523 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005524 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005525 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005526 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005527 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005528 try {
Miaoa84611c2019-03-15 09:21:10 +08005529 if (phone != null) {
5530 return phone.hasMatchedTetherApnSetting();
5531 } else {
5532 return false;
5533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005534 } finally {
5535 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005536 }
Junda Liu475951f2014-11-07 16:45:03 -08005537 }
5538
5539 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005540 * Set mobile data enabled
5541 * Used by the user through settings etc to turn on/off mobile data
5542 *
5543 * @param enable {@code true} turn turn data on, else {@code false}
5544 */
5545 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005546 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005547 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5548 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005549
5550 final long identity = Binder.clearCallingIdentity();
5551 try {
5552 int phoneId = mSubscriptionController.getPhoneId(subId);
5553 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5554 Phone phone = PhoneFactory.getPhone(phoneId);
5555 if (phone != null) {
5556 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005557 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005558 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005559 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005560 }
5561 } finally {
5562 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005563 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005564 }
5565
5566 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005567 * Enable or disable always reporting signal strength changes from radio.
5568 *
5569 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5570 */
5571 @Override
5572 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5573 enforceModifyPermission();
5574 enforceSystemCaller();
5575
5576 final long identity = Binder.clearCallingIdentity();
5577 final Phone phone = getPhone(subId);
5578 try {
5579 if (phone != null) {
5580 if (DBG) {
5581 log("setAlwaysReportSignalStrength: subId=" + subId
5582 + " isEnable=" + isEnable);
5583 }
5584 phone.setAlwaysReportSignalStrength(isEnable);
5585 } else {
5586 loge("setAlwaysReportSignalStrength: no phone found for subId="
5587 + subId);
5588 }
5589 } finally {
5590 Binder.restoreCallingIdentity(identity);
5591 }
5592 }
5593
5594 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005595 * Get the user enabled state of Mobile Data.
5596 *
5597 * TODO: remove and use isUserDataEnabled.
5598 * This can't be removed now because some vendor codes
5599 * calls through ITelephony directly while they should
5600 * use TelephonyManager.
5601 *
5602 * @return true on enabled
5603 */
5604 @Override
5605 public boolean getDataEnabled(int subId) {
5606 return isUserDataEnabled(subId);
5607 }
5608
5609 /**
5610 * Get whether mobile data is enabled per user setting.
5611 *
5612 * There are other factors deciding whether mobile data is actually enabled, but they are
5613 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005614 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005615 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005616 *
5617 * @return {@code true} if data is enabled else {@code false}
5618 */
5619 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005620 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005621 try {
5622 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5623 null);
5624 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5626 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005627 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005628
5629 final long identity = Binder.clearCallingIdentity();
5630 try {
5631 int phoneId = mSubscriptionController.getPhoneId(subId);
5632 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5633 Phone phone = PhoneFactory.getPhone(phoneId);
5634 if (phone != null) {
5635 boolean retVal = phone.isUserDataEnabled();
5636 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5637 return retVal;
5638 } else {
5639 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5640 return false;
5641 }
5642 } finally {
5643 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005644 }
5645 }
5646
5647 /**
Shuo Qian985d1232020-01-08 14:30:06 -08005648 * Checks if the device is capable of mobile data by considering whether whether the
5649 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5650 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005651 *
Shuo Qian985d1232020-01-08 14:30:06 -08005652 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005653 */
5654 @Override
5655 public boolean isDataEnabled(int subId) {
Shuo Qian985d1232020-01-08 14:30:06 -08005656 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005657
5658 final long identity = Binder.clearCallingIdentity();
5659 try {
5660 int phoneId = mSubscriptionController.getPhoneId(subId);
5661 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5662 Phone phone = PhoneFactory.getPhone(phoneId);
5663 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005664 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005665 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5666 return retVal;
5667 } else {
5668 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5669 return false;
5670 }
5671 } finally {
5672 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005673 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005674 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005675
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005676 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5677 Phone phone) {
5678 //load access rules from carrier configs, and check those as well: b/139133814
5679 SubscriptionController subController = SubscriptionController.getInstance();
5680 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5681 || subController == null) return privilegeFromSim;
5682
5683 int uid = Binder.getCallingUid();
5684 PackageManager pkgMgr = phone.getContext().getPackageManager();
5685 String[] packages = pkgMgr.getPackagesForUid(uid);
5686
5687 final long identity = Binder.clearCallingIdentity();
5688 try {
5689 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5690 SubscriptionManager subManager = (SubscriptionManager)
5691 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5692 for (String pkg : packages) {
5693 if (subManager.canManageSubscription(subInfo, pkg)) {
5694 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5695 }
5696 }
5697 return privilegeFromSim;
5698 } finally {
5699 Binder.restoreCallingIdentity(identity);
5700 }
5701 }
5702
5703 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5704 String pkgName) {
5705 //load access rules from carrier configs, and check those as well: b/139133814
5706 SubscriptionController subController = SubscriptionController.getInstance();
5707 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5708 || subController == null) return privilegeFromSim;
5709
5710 final long identity = Binder.clearCallingIdentity();
5711 try {
5712 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5713 SubscriptionManager subManager = (SubscriptionManager)
5714 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5715 return subManager.canManageSubscription(subInfo, pkgName)
5716 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5717 } finally {
5718 Binder.restoreCallingIdentity(identity);
5719 }
5720 }
5721
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005722 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005723 public int getCarrierPrivilegeStatus(int subId) {
5724 final Phone phone = getPhone(subId);
5725 if (phone == null) {
5726 loge("getCarrierPrivilegeStatus: Invalid subId");
5727 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5728 }
5729 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005730 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005731 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005732 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5733 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005734
5735 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5736 card.getCarrierPrivilegeStatusForCurrentTransaction(
5737 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005738 }
Junda Liu29340342014-07-10 15:23:27 -07005739
5740 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005741 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005742 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005743 final Phone phone = getPhone(subId);
5744 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005745 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005746 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5747 }
5748 UiccProfile profile =
5749 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5750 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005751 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005752 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5753 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005754 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005755 profile.getCarrierPrivilegeStatusForUid(
5756 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005757 }
5758
5759 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005760 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5761 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005762 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005763 }
5764
5765 int phoneId = SubscriptionManager.getPhoneId(subId);
5766 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005767 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005768 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005769 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5770 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005771 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5772 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5773 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005774 }
5775
5776 @Override
5777 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005778 if (TextUtils.isEmpty(pkgName))
5779 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005780 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5781 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5782 UiccCard card = UiccController.getInstance().getUiccCard(i);
5783 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005784 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005785 continue;
5786 }
5787
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005788 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5789 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5790 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005791 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5792 break;
5793 }
5794 }
5795
5796 return result;
Junda Liu29340342014-07-10 15:23:27 -07005797 }
Derek Tan89e89d42014-07-08 17:00:10 -07005798
5799 @Override
Junda Liue64de782015-04-16 17:19:16 -07005800 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5801 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5802 loge("phoneId " + phoneId + " is not valid.");
5803 return null;
5804 }
5805 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005806 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005807 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005808 return null ;
5809 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005810 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005811 }
5812
Amith Yamasani6e118872016-02-19 12:53:51 -08005813 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005814 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005815 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005816 List<String> privilegedPackages = new ArrayList<>();
5817 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005818 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5819 // has UICC in that slot.
5820 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005821 if (card.hasCarrierPrivilegeRules()) {
5822 if (packages == null) {
5823 // Only check packages in user 0 for now
5824 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005825 PackageManager.MATCH_DISABLED_COMPONENTS
5826 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005827 | PackageManager.GET_SIGNING_CERTIFICATES,
5828 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005829 }
5830 for (int p = packages.size() - 1; p >= 0; p--) {
5831 PackageInfo pkgInfo = packages.get(p);
5832 if (pkgInfo != null && pkgInfo.packageName != null
5833 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005834 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005835 privilegedPackages.add(pkgInfo.packageName);
5836 }
5837 }
5838 }
5839 }
5840 return privilegedPackages;
5841 }
5842
chen xuf7e9fe82019-05-09 19:31:02 -07005843 @Override
5844 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005845 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5846
5847 final long identity = Binder.clearCallingIdentity();
5848
chen xuf7e9fe82019-05-09 19:31:02 -07005849 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005850 try {
5851 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5852 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5853 }
5854 } finally {
5855 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005856 }
5857 return privilegedPackages;
5858 }
5859
Wink Savilleb564aae2014-10-23 10:18:09 -07005860 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005861 final Phone phone = getPhone(subId);
5862 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005863 if (card == null) {
5864 loge("getIccId: No UICC");
5865 return null;
5866 }
5867 String iccId = card.getIccId();
5868 if (TextUtils.isEmpty(iccId)) {
5869 loge("getIccId: ICC ID is null or empty.");
5870 return null;
5871 }
5872 return iccId;
5873 }
5874
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005875 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005876 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5877 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08005878 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005879 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005880
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005881 final long identity = Binder.clearCallingIdentity();
5882 try {
5883 final String iccId = getIccId(subId);
5884 final Phone phone = getPhone(subId);
5885 if (phone == null) {
5886 return false;
5887 }
5888 final String subscriberId = phone.getSubscriberId();
5889
5890 if (DBG_MERGE) {
5891 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5892 + subscriberId + " to " + number);
5893 }
5894
5895 if (TextUtils.isEmpty(iccId)) {
5896 return false;
5897 }
5898
5899 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5900
5901 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5902 if (alphaTag == null) {
5903 editor.remove(alphaTagPrefKey);
5904 } else {
5905 editor.putString(alphaTagPrefKey, alphaTag);
5906 }
5907
5908 // Record both the line number and IMSI for this ICCID, since we need to
5909 // track all merged IMSIs based on line number
5910 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5911 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5912 if (number == null) {
5913 editor.remove(numberPrefKey);
5914 editor.remove(subscriberPrefKey);
5915 } else {
5916 editor.putString(numberPrefKey, number);
5917 editor.putString(subscriberPrefKey, subscriberId);
5918 }
5919
5920 editor.commit();
5921 return true;
5922 } finally {
5923 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005924 }
Derek Tan7226c842014-07-02 17:42:23 -07005925 }
5926
5927 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005928 public String getLine1NumberForDisplay(int subId, String callingPackage,
5929 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005930 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005931 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005932 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005933 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005934 return null;
5935 }
Derek Tan97ebb422014-09-05 16:55:38 -07005936
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005937 final long identity = Binder.clearCallingIdentity();
5938 try {
5939 String iccId = getIccId(subId);
5940 if (iccId != null) {
5941 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5942 if (DBG_MERGE) {
5943 log("getLine1NumberForDisplay returning "
5944 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5945 }
5946 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005947 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005948 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5949 return null;
5950 } finally {
5951 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005952 }
Derek Tan7226c842014-07-02 17:42:23 -07005953 }
5954
5955 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005956 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5957 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005958 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005959 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005960 return null;
5961 }
Derek Tan97ebb422014-09-05 16:55:38 -07005962
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005963 final long identity = Binder.clearCallingIdentity();
5964 try {
5965 String iccId = getIccId(subId);
5966 if (iccId != null) {
5967 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5968 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5969 }
5970 return null;
5971 } finally {
5972 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005973 }
Derek Tan7226c842014-07-02 17:42:23 -07005974 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005975
5976 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005977 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5978 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005979 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5980 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005981 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005982 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005983 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005984 return null;
5985 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005986
Jordan Liub49b04b2019-05-06 14:45:15 -07005987 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5988 // the process, where TelephonyManager was instantiated.
5989 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005990 final long identity = Binder.clearCallingIdentity();
5991 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005992 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993 final TelephonyManager tele = TelephonyManager.from(context);
5994 final SubscriptionManager sub = SubscriptionManager.from(context);
5995
5996 // Figure out what subscribers are currently active
5997 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005998
Jordan Liub49b04b2019-05-06 14:45:15 -07005999 // Only consider subs which match the current subId
6000 // This logic can be simplified. See b/131189269 for progress.
6001 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006002 activeSubscriberIds.add(tele.getSubscriberId(subId));
6003 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006004
6005 // First pass, find a number override for an active subscriber
6006 String mergeNumber = null;
6007 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6008 for (String key : prefs.keySet()) {
6009 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6010 final String subscriberId = (String) prefs.get(key);
6011 if (activeSubscriberIds.contains(subscriberId)) {
6012 final String iccId = key.substring(
6013 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6014 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6015 mergeNumber = (String) prefs.get(numberKey);
6016 if (DBG_MERGE) {
6017 Slog.d(LOG_TAG, "Found line number " + mergeNumber
6018 + " for active subscriber " + subscriberId);
6019 }
6020 if (!TextUtils.isEmpty(mergeNumber)) {
6021 break;
6022 }
6023 }
6024 }
6025 }
6026
6027 // Shortcut when no active merged subscribers
6028 if (TextUtils.isEmpty(mergeNumber)) {
6029 return null;
6030 }
6031
6032 // Second pass, find all subscribers under that line override
6033 final ArraySet<String> result = new ArraySet<>();
6034 for (String key : prefs.keySet()) {
6035 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6036 final String number = (String) prefs.get(key);
6037 if (mergeNumber.equals(number)) {
6038 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6039 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6040 final String subscriberId = (String) prefs.get(subscriberKey);
6041 if (!TextUtils.isEmpty(subscriberId)) {
6042 result.add(subscriberId);
6043 }
6044 }
6045 }
6046 }
6047
6048 final String[] resultArray = result.toArray(new String[result.size()]);
6049 Arrays.sort(resultArray);
6050 if (DBG_MERGE) {
6051 Slog.d(LOG_TAG,
6052 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6053 }
6054 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006055 } finally {
6056 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006057 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006058 }
6059
6060 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07006061 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
6062 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
6063
6064 final long identity = Binder.clearCallingIdentity();
6065 try {
6066 final TelephonyManager telephonyManager = mApp.getSystemService(
6067 TelephonyManager.class);
6068 String subscriberId = telephonyManager.getSubscriberId(subId);
6069 if (subscriberId == null) {
6070 if (DBG) {
6071 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
6072 + subId);
6073 }
6074 return null;
6075 }
6076
6077 final SubscriptionInfo info = SubscriptionController.getInstance()
6078 .getSubscriptionInfo(subId);
6079 final ParcelUuid groupUuid = info.getGroupUuid();
6080 // If it doesn't belong to any group, return just subscriberId of itself.
6081 if (groupUuid == null) {
6082 return new String[]{subscriberId};
6083 }
6084
6085 // Get all subscriberIds from the group.
6086 final List<String> mergedSubscriberIds = new ArrayList<>();
6087 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006088 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
6089 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07006090 for (SubscriptionInfo subInfo : groupInfos) {
6091 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6092 if (subscriberId != null) {
6093 mergedSubscriberIds.add(subscriberId);
6094 }
6095 }
6096
6097 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6098 } finally {
6099 Binder.restoreCallingIdentity(identity);
6100
6101 }
6102 }
6103
6104 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006105 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006106 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006107 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006108
6109 final long identity = Binder.clearCallingIdentity();
6110 try {
6111 final Phone phone = getPhone(subId);
6112 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6113 } finally {
6114 Binder.restoreCallingIdentity(identity);
6115 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006116 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006117
6118 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006119 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006120 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6121 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006122 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6123 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006124
6125 final long identity = Binder.clearCallingIdentity();
6126 try {
6127 final Phone phone = getPhone(subId);
6128 if (phone == null) {
6129 return false;
6130 }
6131 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6132 cdmaNonRoamingList);
6133 } finally {
6134 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006135 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006136 }
6137
6138 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006139 @Deprecated
6140 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6141 enforceModifyPermission();
6142
6143 int returnValue = 0;
6144 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006145 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006146 if(result.exception == null) {
6147 if (result.result != null) {
6148 byte[] responseData = (byte[])(result.result);
6149 if(responseData.length > oemResp.length) {
6150 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6151 responseData.length + "bytes. Buffer Size is " +
6152 oemResp.length + "bytes.");
6153 }
6154 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6155 returnValue = responseData.length;
6156 }
6157 } else {
6158 CommandException ex = (CommandException) result.exception;
6159 returnValue = ex.getCommandError().ordinal();
6160 if(returnValue > 0) returnValue *= -1;
6161 }
6162 } catch (RuntimeException e) {
6163 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6164 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6165 if(returnValue > 0) returnValue *= -1;
6166 }
6167
6168 return returnValue;
6169 }
6170
6171 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006172 public void setRadioCapability(RadioAccessFamily[] rafs) {
6173 try {
6174 ProxyController.getInstance().setRadioCapability(rafs);
6175 } catch (RuntimeException e) {
6176 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6177 }
6178 }
6179
6180 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006181 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006182 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006183 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006184 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006185 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006186 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006187 final long identity = Binder.clearCallingIdentity();
6188 try {
chen xub97461a2018-10-26 14:17:57 -07006189 TelephonyPermissions
6190 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6191 mApp, phone.getSubId(), "getRadioAccessFamily");
6192 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006193 } finally {
6194 Binder.restoreCallingIdentity(identity);
6195 }
chen xub97461a2018-10-26 14:17:57 -07006196 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006197 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006198
6199 @Override
6200 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006201 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006202 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006203
6204 final long identity = Binder.clearCallingIdentity();
6205 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006206 ImsManager.getInstance(defaultPhone.getContext(),
6207 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006208 } finally {
6209 Binder.restoreCallingIdentity(identity);
6210 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006211 }
6212
6213 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006214 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006215 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006216 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6217 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006218 return false;
6219 }
Svet Ganovb320e182015-04-16 12:30:10 -07006220
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006221 final long identity = Binder.clearCallingIdentity();
6222 try {
6223 // Check the user preference and the system-level IMS setting. Even if the user has
6224 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6225 // In the long run, we may instead need to check if there exists a connection service
6226 // which can support video calling.
6227 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006228 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006229 return imsManager.isVtEnabledByPlatform()
6230 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6231 && imsManager.isVtEnabledByUser();
6232 } finally {
6233 Binder.restoreCallingIdentity(identity);
6234 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006235 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006236
Andrew Leea1239f22015-03-02 17:44:07 -08006237 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006238 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6239 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006240 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006241 mApp, subId, callingPackage, callingFeatureId,
6242 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006243 return false;
6244 }
6245
6246 final long identity = Binder.clearCallingIdentity();
6247 try {
6248 CarrierConfigManager configManager =
6249 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006250 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006251 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6252 } finally {
6253 Binder.restoreCallingIdentity(identity);
6254 }
Andrew Leea1239f22015-03-02 17:44:07 -08006255 }
6256
6257 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006258 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006259 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006260 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006261 return false;
6262 }
6263
6264 final long identity = Binder.clearCallingIdentity();
6265 try {
6266 CarrierConfigManager configManager =
6267 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006268 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006269 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6270 } finally {
6271 Binder.restoreCallingIdentity(identity);
6272 }
Andrew Leea1239f22015-03-02 17:44:07 -08006273 }
6274
Andrew Lee9431b832015-03-09 18:46:45 -07006275 @Override
6276 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006277 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006278 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006279 }
6280
6281 @Override
6282 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006283 final long identity = Binder.clearCallingIdentity();
6284 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006285 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006286 } finally {
6287 Binder.restoreCallingIdentity(identity);
6288 }
Andrew Lee9431b832015-03-09 18:46:45 -07006289 }
6290
Hall Liuf6668912018-10-31 17:05:23 -07006291 /**
6292 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6293 * support for the feature and device firmware support.
6294 *
6295 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6296 */
6297 @Override
6298 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006299 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006300 final Phone phone = getPhone(subscriptionId);
6301 if (phone == null) {
6302 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6303 return false;
6304 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006305 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006306 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006307 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6308 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006309 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006310 return isCarrierSupported && isDeviceSupported;
6311 } finally {
6312 Binder.restoreCallingIdentity(identity);
6313 }
Hall Liu98187582018-01-22 19:15:32 -08006314 }
6315
Hall Liuf6668912018-10-31 17:05:23 -07006316 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006317 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6318 * RTT setting, will return true if the device and carrier both support RTT.
6319 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006320 */
6321 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006322 final long identity = Binder.clearCallingIdentity();
6323 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006324 boolean isRttSupported = isRttSupported(subscriptionId);
6325 boolean isUserRttSettingOn = Settings.Secure.getInt(
6326 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6327 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6328 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6329 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006330 } finally {
6331 Binder.restoreCallingIdentity(identity);
6332 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006333 }
6334
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006335 @Deprecated
6336 @Override
6337 public String getDeviceId(String callingPackage) {
6338 return getDeviceIdWithFeature(callingPackage, null);
6339 }
6340
Sanket Padawe7310cc72015-01-14 09:53:20 -08006341 /**
6342 * Returns the unique device ID of phone, for example, the IMEI for
6343 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6344 *
6345 * <p>Requires Permission:
6346 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6347 */
6348 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006349 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006350 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006351 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006352 return null;
6353 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006354 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006355 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006356 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006357 return null;
6358 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006359
6360 final long identity = Binder.clearCallingIdentity();
6361 try {
6362 return phone.getDeviceId();
6363 } finally {
6364 Binder.restoreCallingIdentity(identity);
6365 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006366 }
6367
Ping Sunc67b7c22016-03-02 19:16:45 +08006368 /**
6369 * {@hide}
6370 * Returns the IMS Registration Status on a particular subid
6371 *
6372 * @param subId
6373 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006374 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006375 Phone phone = getPhone(subId);
6376 if (phone != null) {
6377 return phone.isImsRegistered();
6378 } else {
6379 return false;
6380 }
6381 }
6382
Santos Cordon7a1885b2015-02-03 11:15:19 -08006383 @Override
6384 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006385 final long identity = Binder.clearCallingIdentity();
6386 try {
6387 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6388 } finally {
6389 Binder.restoreCallingIdentity(identity);
6390 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006391 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006392
Tyler Gunnf70ed162019-04-03 15:28:53 -07006393 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006394 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006395 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006396 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006397 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006398 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6399 }
6400 final long identity = Binder.clearCallingIdentity();
6401 try {
6402 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6403 } finally {
6404 Binder.restoreCallingIdentity(identity);
6405 }
6406 }
6407
6408 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006409 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6410 final long identity = Binder.clearCallingIdentity();
6411 try {
6412 Phone phone = getPhone(subscriptionId);
6413 if (phone == null) {
6414 return null;
6415 }
6416 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6417 } finally {
6418 Binder.restoreCallingIdentity(identity);
6419 }
6420 }
6421
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006422 /**
6423 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006424 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006425 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006426 final long identity = Binder.clearCallingIdentity();
6427 try {
6428 Phone phone = getPhone(subId);
6429 if (phone != null) {
6430 return phone.isWifiCallingEnabled();
6431 } else {
6432 return false;
6433 }
6434 } finally {
6435 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006436 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006437 }
6438
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006439 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006440 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006441 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006442 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006443 final long identity = Binder.clearCallingIdentity();
6444 try {
6445 Phone phone = getPhone(subId);
6446 if (phone != null) {
6447 return phone.isVideoEnabled();
6448 } else {
6449 return false;
6450 }
6451 } finally {
6452 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006453 }
6454 }
6455
6456 /**
6457 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6458 * defined in {@link ImsRegistrationImplBase}.
6459 */
6460 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006461 final long identity = Binder.clearCallingIdentity();
6462 try {
6463 Phone phone = getPhone(subId);
6464 if (phone != null) {
6465 return phone.getImsRegistrationTech();
6466 } else {
6467 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6468 }
6469 } finally {
6470 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006471 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006472 }
6473
Stuart Scott8eef64f2015-04-08 15:13:54 -07006474 @Override
6475 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006476 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006477 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6478 return;
6479 }
6480
Svet Ganovcc087f82015-05-12 20:35:54 -07006481 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006482
Svet Ganovcc087f82015-05-12 20:35:54 -07006483 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006484 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6485 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006486 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006487 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006488 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006489 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6490 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006491 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006492 // There has been issues when Sms raw table somehow stores orphan
6493 // fragments. They lead to garbled message when new fragments come
6494 // in and combined with those stale ones. In case this happens again,
6495 // user can reset all network settings which will clean up this table.
6496 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006497 // Clean up IMS settings as well here.
6498 int slotId = getSlotIndex(subId);
6499 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6500 ImsManager.getInstance(mApp, slotId).factoryReset();
6501 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006502
6503 // Erase modem config if erase modem on network setting is enabled.
6504 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6505 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6506 if (configValue != null && Boolean.parseBoolean(configValue)) {
6507 sendEraseModemConfig(getDefaultPhone());
6508 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006509 } finally {
6510 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006511 }
6512 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006513
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006514 private void cleanUpSmsRawTable(Context context) {
6515 ContentResolver resolver = context.getContentResolver();
6516 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6517 resolver.delete(uri, null, null);
6518 }
6519
Narayan Kamath1c496c22015-04-16 14:40:19 +01006520 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006521 public String getSimLocaleForSubscriber(int subId) {
6522 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6523 final Phone phone = getPhone(subId);
6524 if (phone == null) {
6525 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006526 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006527 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006528 final long identity = Binder.clearCallingIdentity();
6529 try {
chen xu5d3637b2019-01-21 23:31:38 -08006530 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006531 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08006532 if (info == null) {
6533 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6534 return null;
6535 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006536 // Try and fetch the locale from the carrier properties or from the SIM language
6537 // preferences (EF-PL and EF-LI)...
6538 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006539 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006540 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6541 if (localeFromDefaultSim != null) {
6542 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6543 if (DBG) log("Using locale from subId: " + subId + " locale: "
6544 + localeFromDefaultSim);
6545 return localeFromDefaultSim.toLanguageTag();
6546 } else {
6547 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006548 }
6549 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006550
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006551 // The SIM language preferences only store a language (e.g. fr = French), not an
6552 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6553 // the SIM and carrier preferences does not include a country we add the country
6554 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006555 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006556 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006557 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006558 return mccLocale.toLanguageTag();
6559 }
6560
6561 if (DBG) log("No locale found - returning null");
6562 return null;
6563 } finally {
6564 Binder.restoreCallingIdentity(identity);
6565 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006566 }
6567
6568 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006569 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6570 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006571 }
6572
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006573 /**
6574 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6575 */
6576 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006577 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6578 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006579 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006580
Chenjie Yu1ba97252018-01-11 18:16:20 -08006581 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006582 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006583
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006584 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006585 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6586 * representing the state of the modem.
6587 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006588 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6589 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006590 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006591 */
6592 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006593 public void requestModemActivityInfo(ResultReceiver result) {
6594 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006595 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006596
6597 final long identity = Binder.clearCallingIdentity();
6598 try {
6599 ModemActivityInfo ret = null;
6600 synchronized (mLastModemActivityInfo) {
6601 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6602 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006603 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006604 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006605 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xu13851032019-09-10 18:49:52 -07006606 int[] txTimeMs = info.getTransmitTimeMillis();
6607 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006608 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xu13851032019-09-10 18:49:52 -07006609 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006610 }
6611 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006612 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6613 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006614 mLastModemActivityInfo.setIdleTimeMillis(
6615 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xu13851032019-09-10 18:49:52 -07006616 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6617 mLastModemActivityInfo.setReceiveTimeMillis(
6618 info.getReceiveTimeMillis() + mLastModemActivityInfo
6619 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006620 }
Chen Xu13851032019-09-10 18:49:52 -07006621
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006622 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6623 mLastModemActivityInfo.getSleepTimeMillis(),
6624 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xu13851032019-09-10 18:49:52 -07006625 mLastModemActivityInfo.getTransmitTimeMillis(),
6626 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006627 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006628 Bundle bundle = new Bundle();
6629 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6630 result.send(0, bundle);
6631 } finally {
6632 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006633 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006634 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006635
Siddharth Rayb8114062018-06-17 15:02:38 -07006636 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6637 // less than total activity duration.
6638 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6639 if (info == null) {
6640 return false;
6641 }
6642 int activityDurationMs =
6643 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6644 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006645 int[] txTimeMs = info.getTransmitTimeMillis();
6646 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6647 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006648 }
6649 return (info.isValid()
6650 && (info.getSleepTimeMillis() <= activityDurationMs)
6651 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006652 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006653 && (totalTxTimeMs <= activityDurationMs));
6654 }
6655
Jack Yu85bd38a2015-11-09 11:34:32 -08006656 /**
6657 * {@hide}
6658 * Returns the service state information on specified subscription.
6659 */
6660 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006661 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6662 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006663 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006664 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006665 return null;
6666 }
6667
Hall Liuf19c44f2018-11-27 14:38:17 -08006668 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6669 LocationAccessPolicy.checkLocationPermission(mApp,
6670 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6671 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006672 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006673 .setCallingPid(Binder.getCallingPid())
6674 .setCallingUid(Binder.getCallingUid())
6675 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006676 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006677 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6678 .build());
6679
6680 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6681 LocationAccessPolicy.checkLocationPermission(mApp,
6682 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6683 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006684 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006685 .setCallingPid(Binder.getCallingPid())
6686 .setCallingUid(Binder.getCallingUid())
6687 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006688 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006689 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6690 .build());
6691 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6692 boolean hasFinePermission =
6693 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6694 boolean hasCoarsePermission =
6695 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6696
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006697 final long identity = Binder.clearCallingIdentity();
6698 try {
6699 final Phone phone = getPhone(subId);
6700 if (phone == null) {
6701 return null;
6702 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006703
Hall Liuf19c44f2018-11-27 14:38:17 -08006704 ServiceState ss = phone.getServiceState();
6705
6706 // Scrub out the location info in ServiceState depending on what level of access
6707 // the caller has.
6708 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006709 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6710 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006711 } finally {
6712 Binder.restoreCallingIdentity(identity);
6713 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006714 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006715
6716 /**
6717 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6718 *
6719 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6720 * voicemail ringtone.
6721 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6722 * PhoneAccount.
6723 */
6724 @Override
6725 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006726 final long identity = Binder.clearCallingIdentity();
6727 try {
6728 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6729 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006730 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006731 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006732
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006733 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6734 } finally {
6735 Binder.restoreCallingIdentity(identity);
6736 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006737 }
6738
6739 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006740 * Sets the per-account voicemail ringtone.
6741 *
6742 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6743 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6744 *
6745 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6746 * voicemail ringtone.
6747 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6748 * PhoneAccount.
6749 */
6750 @Override
6751 public void setVoicemailRingtoneUri(String callingPackage,
6752 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006753 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006754 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006755 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6756 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006757 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6758 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6759 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006760 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006761
6762 final long identity = Binder.clearCallingIdentity();
6763 try {
6764 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6765 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006766 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006767 }
6768 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6769 } finally {
6770 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006771 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006772 }
6773
6774 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006775 * Returns whether vibration is set for voicemail notification in Phone settings.
6776 *
6777 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6778 * voicemail vibration setting.
6779 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6780 */
6781 @Override
6782 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006783 final long identity = Binder.clearCallingIdentity();
6784 try {
6785 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6786 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006787 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006788 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006789
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006790 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6791 } finally {
6792 Binder.restoreCallingIdentity(identity);
6793 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006794 }
6795
Youhan Wange64578a2016-05-02 15:32:42 -07006796 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006797 * Sets the per-account voicemail vibration.
6798 *
6799 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6800 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6801 *
6802 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6803 * voicemail vibration setting.
6804 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6805 * specific PhoneAccount.
6806 */
6807 @Override
6808 public void setVoicemailVibrationEnabled(String callingPackage,
6809 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006810 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006811 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006812 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6813 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006814 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6815 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6816 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006817 }
6818
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006819 final long identity = Binder.clearCallingIdentity();
6820 try {
6821 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6822 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006823 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006824 }
6825 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6826 } finally {
6827 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006828 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006829 }
6830
6831 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006832 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6833 *
6834 * @throws SecurityException if the caller does not have the required permission
6835 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006836 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006837 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006838 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006839 }
6840
6841 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006842 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6843 * permission.
6844 *
6845 * @throws SecurityException if the caller does not have the required permission
6846 */
6847 private void enforceSendSmsPermission() {
6848 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6849 }
6850
6851 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006852 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006853 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006854 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006855 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006856 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006857 final long identity = Binder.clearCallingIdentity();
6858 try {
6859 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006860 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006861 if (componentName == null) {
6862 throw new SecurityException(
6863 "Caller not current active visual voicemail package[null]");
6864 }
6865 String vvmPackage = componentName.getPackageName();
6866 if (!callingPackage.equals(vvmPackage)) {
6867 throw new SecurityException("Caller not current active visual voicemail package["
6868 + vvmPackage + "]");
6869 }
6870 } finally {
6871 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006872 }
6873 }
6874
6875 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006876 * Return the application ID for the app type.
6877 *
6878 * @param subId the subscription ID that this request applies to.
6879 * @param appType the uicc app type.
6880 * @return Application ID for specificied app type, or null if no uicc.
6881 */
6882 @Override
6883 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006884 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006885 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006886
6887 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006888 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006889 if (phone == null) {
6890 return null;
6891 }
6892 String aid = null;
6893 try {
6894 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6895 .getApplicationByType(appType).getAid();
6896 } catch (Exception e) {
6897 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6898 }
6899 return aid;
6900 } finally {
6901 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006902 }
Youhan Wange64578a2016-05-02 15:32:42 -07006903 }
6904
Youhan Wang4001d252016-05-11 10:29:41 -07006905 /**
6906 * Return the Electronic Serial Number.
6907 *
6908 * @param subId the subscription ID that this request applies to.
6909 * @return ESN or null if error.
6910 */
6911 @Override
6912 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006913 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006914 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006915
6916 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006917 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006918 if (phone == null) {
6919 return null;
6920 }
6921 String esn = null;
6922 try {
6923 esn = phone.getEsn();
6924 } catch (Exception e) {
6925 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6926 }
6927 return esn;
6928 } finally {
6929 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006930 }
Youhan Wang4001d252016-05-11 10:29:41 -07006931 }
6932
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006933 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006934 * Return the Preferred Roaming List Version.
6935 *
6936 * @param subId the subscription ID that this request applies to.
6937 * @return PRLVersion or null if error.
6938 */
6939 @Override
6940 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006941 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006942 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006943
6944 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006945 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006946 if (phone == null) {
6947 return null;
6948 }
6949 String cdmaPrlVersion = null;
6950 try {
6951 cdmaPrlVersion = phone.getCdmaPrlVersion();
6952 } catch (Exception e) {
6953 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6954 }
6955 return cdmaPrlVersion;
6956 } finally {
6957 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006958 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006959 }
6960
6961 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006962 * Get snapshot of Telephony histograms
6963 * @return List of Telephony histograms
6964 * @hide
6965 */
6966 @Override
6967 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006968 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6969 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006970
6971 final long identity = Binder.clearCallingIdentity();
6972 try {
6973 return RIL.getTelephonyRILTimingHistograms();
6974 } finally {
6975 Binder.restoreCallingIdentity(identity);
6976 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006977 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006978
6979 /**
6980 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006981 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6982 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006983 * Require system privileges. In the future we may add this to carrier APIs.
6984 *
Michele Berionne482f8202018-11-27 18:57:59 -08006985 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006986 */
6987 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006988 @TelephonyManager.SetCarrierRestrictionResult
6989 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006990 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006991 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006992
Michele Berionne482f8202018-11-27 18:57:59 -08006993 if (carrierRestrictionRules == null) {
6994 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006995 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006996
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006997 final long identity = Binder.clearCallingIdentity();
6998 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006999 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007000 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007001 } finally {
7002 Binder.restoreCallingIdentity(identity);
7003 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007004 }
7005
7006 /**
7007 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007008 * Get the allowed carrier list and the excluded carrier list, including the priority between
7009 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007010 * Require system privileges. In the future we may add this to carrier APIs.
7011 *
Michele Berionne482f8202018-11-27 18:57:59 -08007012 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007013 */
7014 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007015 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007016 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007017 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007018
7019 final long identity = Binder.clearCallingIdentity();
7020 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007021 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7022 if (response instanceof CarrierRestrictionRules) {
7023 return (CarrierRestrictionRules) response;
7024 }
7025 // Response is an Exception of some kind,
7026 // which is signalled to the user as a NULL retval
7027 return null;
7028 } catch (Exception e) {
7029 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7030 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007031 } finally {
7032 Binder.restoreCallingIdentity(identity);
7033 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007034 }
7035
fionaxu59545b42016-05-25 15:53:37 -07007036 /**
7037 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7038 * @param subId the subscription ID that this action applies to.
7039 * @param enabled control enable or disable metered apns.
7040 * {@hide}
7041 */
7042 @Override
7043 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7044 enforceModifyPermission();
7045 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007046
7047 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007048 if (phone == null) {
7049 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7050 return;
7051 }
7052 try {
7053 phone.carrierActionSetMeteredApnsEnabled(enabled);
7054 } catch (Exception e) {
7055 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007056 } finally {
7057 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007058 }
7059 }
7060
7061 /**
7062 * Action set from carrier signalling broadcast receivers to enable/disable radio
7063 * @param subId the subscription ID that this action applies to.
7064 * @param enabled control enable or disable radio.
7065 * {@hide}
7066 */
7067 @Override
7068 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7069 enforceModifyPermission();
7070 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007071
7072 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007073 if (phone == null) {
7074 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7075 return;
7076 }
7077 try {
7078 phone.carrierActionSetRadioEnabled(enabled);
7079 } catch (Exception e) {
7080 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007081 } finally {
7082 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007083 }
7084 }
7085
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007086 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007087 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7088 * network status based on which carrier apps could apply actions accordingly,
7089 * enable/disable default url handler for example.
7090 *
7091 * @param subId the subscription ID that this action applies to.
7092 * @param report control start/stop reporting the default network status.
7093 * {@hide}
7094 */
7095 @Override
7096 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7097 enforceModifyPermission();
7098 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007099
7100 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007101 if (phone == null) {
7102 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7103 return;
7104 }
7105 try {
7106 phone.carrierActionReportDefaultNetworkStatus(report);
7107 } catch (Exception e) {
7108 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007109 } finally {
7110 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007111 }
7112 }
7113
7114 /**
fionaxud9622282017-07-17 17:51:30 -07007115 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7116 * @param subId the subscription ID that this action applies to.
7117 * {@hide}
7118 */
7119 @Override
7120 public void carrierActionResetAll(int subId) {
7121 enforceModifyPermission();
7122 final Phone phone = getPhone(subId);
7123 if (phone == null) {
7124 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7125 return;
7126 }
7127 try {
7128 phone.carrierActionResetAll();
7129 } catch (Exception e) {
7130 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7131 }
7132 }
7133
7134 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007135 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7136 * bug report is being generated.
7137 */
7138 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007139 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007140 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7141 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007142 writer.println("Permission Denial: can't dump Phone from pid="
7143 + Binder.getCallingPid()
7144 + ", uid=" + Binder.getCallingUid()
7145 + "without permission "
7146 + android.Manifest.permission.DUMP);
7147 return;
7148 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007149 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007150 }
Jack Yueb89b242016-06-22 13:27:47 -07007151
Brad Ebingerdac2f002018-04-03 15:17:52 -07007152 @Override
7153 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
7154 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
7155 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01007156 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
7157 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007158 }
7159
Jack Yueb89b242016-06-22 13:27:47 -07007160 /**
Jack Yu84291ec2017-05-26 16:07:50 -07007161 * Get aggregated video call data usage since boot.
7162 *
7163 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
7164 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07007165 * {@hide}
7166 */
7167 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07007168 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07007169 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
7170 null);
7171
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007172 final long identity = Binder.clearCallingIdentity();
7173 try {
7174 // NetworkStatsService keeps tracking the active network interface and identity. It
7175 // records the delta with the corresponding network identity.
7176 // We just return the total video call data usage snapshot since boot.
7177 Phone phone = getPhone(subId);
7178 if (phone != null) {
7179 return phone.getVtDataUsage(perUidStats);
7180 }
7181 return null;
7182 } finally {
7183 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07007184 }
Jack Yueb89b242016-06-22 13:27:47 -07007185 }
Jack Yu75ab2952016-07-08 14:29:33 -07007186
7187 /**
7188 * Policy control of data connection. Usually used when data limit is passed.
7189 * @param enabled True if enabling the data, otherwise disabling.
7190 * @param subId Subscription index
7191 * {@hide}
7192 */
7193 @Override
7194 public void setPolicyDataEnabled(boolean enabled, int subId) {
7195 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007196
7197 final long identity = Binder.clearCallingIdentity();
7198 try {
7199 Phone phone = getPhone(subId);
7200 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007201 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007202 }
7203 } finally {
7204 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007205 }
7206 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007207
7208 /**
7209 * Get Client request stats
7210 * @return List of Client Request Stats
7211 * @hide
7212 */
7213 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007214 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7215 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007216 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007217 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007218 return null;
7219 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007220 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007221
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007222 final long identity = Binder.clearCallingIdentity();
7223 try {
7224 if (phone != null) {
7225 return phone.getClientRequestStats();
7226 }
7227
7228 return null;
7229 } finally {
7230 Binder.restoreCallingIdentity(identity);
7231 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007232 }
7233
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007234 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007235 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007236 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007237 }
Jack Yueb4124c2017-02-16 15:32:43 -08007238
7239 /**
Grace Chen70990072017-03-24 17:21:30 -07007240 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007241 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007242 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007243 * @param state State of SIM (power down, power up, pass through)
7244 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7245 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7246 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007247 *
7248 **/
7249 @Override
Grace Chen70990072017-03-24 17:21:30 -07007250 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007251 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007252 Phone phone = PhoneFactory.getPhone(slotIndex);
7253
vagdeviaf9a5b92018-08-15 16:01:53 -07007254 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7255
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007256 final long identity = Binder.clearCallingIdentity();
7257 try {
7258 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007259 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007260 }
7261 } finally {
7262 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007263 }
7264 }
Shuo Qiandd210312017-04-12 22:11:33 +00007265
Tyler Gunn65d45c22017-06-05 11:22:26 -07007266 private boolean isUssdApiAllowed(int subId) {
7267 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007268 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007269 if (configManager == null) {
7270 return false;
7271 }
7272 PersistableBundle pb = configManager.getConfigForSubId(subId);
7273 if (pb == null) {
7274 return false;
7275 }
7276 return pb.getBoolean(
7277 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7278 }
7279
Shuo Qiandd210312017-04-12 22:11:33 +00007280 /**
7281 * Check if phone is in emergency callback mode
7282 * @return true if phone is in emergency callback mode
7283 * @param subId sub id
7284 */
goneil9c5f4872017-12-05 14:07:56 -08007285 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007286 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007287 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007288 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007289
7290 final long identity = Binder.clearCallingIdentity();
7291 try {
7292 if (phone != null) {
7293 return phone.isInEcm();
7294 } else {
7295 return false;
7296 }
7297 } finally {
7298 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007299 }
7300 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007301
7302 /**
7303 * Get the current signal strength information for the given subscription.
7304 * Because this information is not updated when the device is in a low power state
7305 * it should not be relied-upon to be current.
7306 * @param subId Subscription index
7307 * @return the most recent cached signal strength info from the modem
7308 */
7309 @Override
7310 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007311 final long identity = Binder.clearCallingIdentity();
7312 try {
7313 Phone p = getPhone(subId);
7314 if (p == null) {
7315 return null;
7316 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007317
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007318 return p.getSignalStrength();
7319 } finally {
7320 Binder.restoreCallingIdentity(identity);
7321 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007322 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007323
Pengquan Meng77b7f132018-08-22 14:49:57 -07007324 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007325 * Get the current modem radio state for the given slot.
7326 * @param slotIndex slot index.
7327 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007328 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007329 * @return the current radio power state from the modem
7330 */
7331 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007332 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007333 Phone phone = PhoneFactory.getPhone(slotIndex);
7334 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007335 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7336 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007337 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7338 }
7339
7340 final long identity = Binder.clearCallingIdentity();
7341 try {
7342 return phone.getRadioPowerState();
7343 } finally {
7344 Binder.restoreCallingIdentity(identity);
7345 }
7346 }
7347 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7348 }
7349
7350 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007351 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7352 *
7353 * <p>Requires one of the following permissions:
7354 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7355 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7356 * privileges.
7357 *
7358 * @param subId subscription id
7359 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7360 * {@code false}.
7361 */
7362 @Override
7363 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007364 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7365 null /* message */);
7366
Pengquan Menga1bb6272018-09-06 09:59:22 -07007367 boolean isEnabled = false;
7368 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007369 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007370 Phone phone = getPhone(subId);
7371 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007372 } catch (Exception e) {
7373 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7374 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007375 } finally {
7376 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007377 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007378 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007379 }
7380
7381
7382 /**
7383 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7384 *
7385 * <p> Requires permission:
7386 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7387 * privileges.
7388 *
7389 * @param subId subscription id
7390 * @param isEnabled {@code true} means enable, {@code false} means disable.
7391 */
7392 @Override
7393 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007394 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7395 mApp, subId, "setDataRoamingEnabled");
7396
Pengquan Menga1bb6272018-09-06 09:59:22 -07007397 final long identity = Binder.clearCallingIdentity();
7398 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007399 Phone phone = getPhone(subId);
7400 if (phone != null) {
7401 phone.setDataRoamingEnabled(isEnabled);
7402 }
7403 } finally {
7404 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007405 }
7406 }
7407
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007408 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007409 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007410 TelephonyPermissions
7411 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007412 mApp, subId, "isManualNetworkSelectionAllowed");
7413
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007414 boolean isAllowed = true;
7415 final long identity = Binder.clearCallingIdentity();
7416 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007417 Phone phone = getPhone(subId);
7418 if (phone != null) {
7419 isAllowed = phone.isCspPlmnEnabled();
7420 }
7421 } finally {
7422 Binder.restoreCallingIdentity(identity);
7423 }
7424 return isAllowed;
7425 }
7426
7427 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007428 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007429 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007430 try {
7431 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007432 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007433 } catch (SecurityException e) {
7434 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7435 // has carrier privileges on an active UICC
7436 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7437 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007438 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007439 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007440 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007441
7442 final long identity = Binder.clearCallingIdentity();
7443 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007444 UiccController uiccController = UiccController.getInstance();
7445 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007446 if (hasReadPermission) {
7447 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007448 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007449
7450 // Remove private info if the caller doesn't have access
7451 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7452 for (UiccCardInfo cardInfo : cardInfos) {
7453 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7454 // is available
7455 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7456 if (card == null || card.getUiccProfile() == null) {
7457 // assume no access if the card or profile is unavailable
7458 filteredInfos.add(cardInfo.getUnprivileged());
7459 continue;
7460 }
7461 UiccProfile profile = card.getUiccProfile();
7462 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7463 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7464 filteredInfos.add(cardInfo);
7465 } else {
7466 filteredInfos.add(cardInfo.getUnprivileged());
7467 }
7468 }
7469 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007470 } finally {
7471 Binder.restoreCallingIdentity(identity);
7472 }
7473 }
7474
7475 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007476 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007477 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007478
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007479 final long identity = Binder.clearCallingIdentity();
7480 try {
7481 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7482 if (slots == null) {
7483 Rlog.i(LOG_TAG, "slots is null.");
7484 return null;
7485 }
7486
7487 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7488 for (int i = 0; i < slots.length; i++) {
7489 UiccSlot slot = slots[i];
7490 if (slot == null) {
7491 continue;
7492 }
7493
Jordan Liu7be7e652019-05-06 18:55:02 +00007494 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007495 UiccCard card = slot.getUiccCard();
7496 if (card != null) {
7497 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007498 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007499 cardId = slot.getEid();
7500 if (TextUtils.isEmpty(cardId)) {
7501 cardId = slot.getIccId();
7502 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007503 }
7504
Jordan Liu857451f2019-05-09 16:35:35 -07007505 if (cardId != null) {
7506 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7507 // if cardId is an EID, it's all digits so this is fine
7508 cardId = IccUtils.stripTrailingFs(cardId);
7509 }
7510
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007511 int cardState = 0;
7512 switch (slot.getCardState()) {
7513 case CARDSTATE_ABSENT:
7514 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7515 break;
7516 case CARDSTATE_PRESENT:
7517 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7518 break;
7519 case CARDSTATE_ERROR:
7520 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7521 break;
7522 case CARDSTATE_RESTRICTED:
7523 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7524 break;
7525 default:
7526 break;
7527
7528 }
7529
7530 infos[i] = new UiccSlotInfo(
7531 slot.isActive(),
7532 slot.isEuicc(),
7533 cardId,
7534 cardState,
7535 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007536 slot.isExtendedApduSupported(),
7537 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007538 }
7539 return infos;
7540 } finally {
7541 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007542 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007543 }
7544
7545 @Override
7546 public boolean switchSlots(int[] physicalSlots) {
7547 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007548
7549 final long identity = Binder.clearCallingIdentity();
7550 try {
7551 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7552 } finally {
7553 Binder.restoreCallingIdentity(identity);
7554 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007555 }
Jack Yu4c988042018-02-27 15:30:01 -08007556
7557 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007558 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007559 final long identity = Binder.clearCallingIdentity();
7560 try {
7561 return UiccController.getInstance().getCardIdForDefaultEuicc();
7562 } finally {
7563 Binder.restoreCallingIdentity(identity);
7564 }
7565 }
7566
7567 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007568 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7569 enforceModifyPermission();
7570 final Phone phone = getPhone(subId);
7571 if (phone == null) {
7572 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7573 return;
7574 }
7575
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007576 final long identity = Binder.clearCallingIdentity();
7577 try {
7578 phone.setRadioIndicationUpdateMode(filters, mode);
7579 } finally {
7580 Binder.restoreCallingIdentity(identity);
7581 }
Jack Yu4c988042018-02-27 15:30:01 -08007582 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007583
7584 /**
goneil47ffb6e2018-04-06 15:40:58 -07007585 * A test API to reload the UICC profile.
7586 *
7587 * <p>Requires that the calling app has permission
7588 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7589 * @hide
7590 */
7591 @Override
7592 public void refreshUiccProfile(int subId) {
7593 enforceModifyPermission();
7594
7595 final long identity = Binder.clearCallingIdentity();
7596 try {
7597 Phone phone = getPhone(subId);
7598 if (phone == null) {
7599 return;
7600 }
7601 UiccCard uiccCard = phone.getUiccCard();
7602 if (uiccCard == null) {
7603 return;
7604 }
7605 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7606 if (uiccProfile == null) {
7607 return;
7608 }
7609 uiccProfile.refresh();
7610 } finally {
7611 Binder.restoreCallingIdentity(identity);
7612 }
7613 }
7614
7615 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007616 * Returns false if the mobile data is disabled by default, otherwise return true.
7617 */
7618 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007619 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007620 }
7621
7622 /**
7623 * Returns true if the data roaming is enabled by default, i.e the system property
7624 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7625 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7626 */
7627 private boolean getDefaultDataRoamingEnabled(int subId) {
7628 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007629 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007630 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007631 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7632 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7633 return isDataRoamingEnabled;
7634 }
7635
7636 /**
7637 * Returns the default network type for the given {@code subId}, if the default network type is
7638 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7639 */
7640 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007641 List<Integer> list = TelephonyProperties.default_network();
7642 int phoneId = mSubscriptionController.getPhoneId(subId);
7643 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7644 return list.get(phoneId);
7645 }
7646 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007647 }
fionaxua13278b2018-03-21 00:08:13 -07007648
7649 @Override
7650 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007651 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007652 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007653
7654 final long identity = Binder.clearCallingIdentity();
7655 try {
7656 final Phone phone = getPhone(subId);
7657 if (phone == null) {
7658 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7659 return;
7660 }
chen xueaba88a2019-03-15 13:15:10 -07007661 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7662 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007663 } finally {
7664 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007665 }
fionaxua13278b2018-03-21 00:08:13 -07007666 }
7667
7668 @Override
7669 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007670 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007671
7672 final long identity = Binder.clearCallingIdentity();
7673 try {
7674 final Phone phone = getPhone(subId);
7675 if (phone == null) {
7676 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7677 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7678 }
7679 return phone.getCarrierIdListVersion();
7680 } finally {
7681 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007682 }
fionaxua13278b2018-03-21 00:08:13 -07007683 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007684
7685 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007686 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7687 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007688 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007689 mApp, subId, callingPackage, callingFeatureId,
7690 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007691 return -1;
7692 }
7693
7694 final long identity = Binder.clearCallingIdentity();
7695 try {
7696 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7697 } finally {
7698 Binder.restoreCallingIdentity(identity);
7699 }
7700 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007701
7702 @Override
7703 public int getCdmaRoamingMode(int subId) {
7704 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7705 mApp, subId, "getCdmaRoamingMode");
7706
7707 final long identity = Binder.clearCallingIdentity();
7708 try {
7709 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7710 } finally {
7711 Binder.restoreCallingIdentity(identity);
7712 }
7713 }
7714
7715 @Override
7716 public boolean setCdmaRoamingMode(int subId, int mode) {
7717 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7718 mApp, subId, "setCdmaRoamingMode");
7719
7720 final long identity = Binder.clearCallingIdentity();
7721 try {
7722 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7723 } finally {
7724 Binder.restoreCallingIdentity(identity);
7725 }
7726 }
7727
7728 @Override
7729 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7731 mApp, subId, "setCdmaSubscriptionMode");
7732
7733 final long identity = Binder.clearCallingIdentity();
7734 try {
7735 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7736 } finally {
7737 Binder.restoreCallingIdentity(identity);
7738 }
7739 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007740
sqianc5eccab2018-10-19 18:46:41 -07007741 @Override
sqian8c685422019-02-22 15:55:18 -08007742 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007743 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007744 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007745 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7746 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007747 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7748 }
7749 final long identity = Binder.clearCallingIdentity();
7750 try {
sqian854d44b2018-12-12 16:48:18 -08007751 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7752 for (Phone phone: PhoneFactory.getPhones()) {
7753 if (phone.getEmergencyNumberTracker() != null
7754 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7755 emergencyNumberListInternal.put(
7756 phone.getSubId(),
7757 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7758 }
sqian11b7a0e2018-12-05 18:48:28 -08007759 }
sqian854d44b2018-12-12 16:48:18 -08007760 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007761 } finally {
7762 Binder.restoreCallingIdentity(identity);
7763 }
sqianc5eccab2018-10-19 18:46:41 -07007764 }
7765
7766 @Override
sqian8c685422019-02-22 15:55:18 -08007767 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007768 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007769 if (!exactMatch) {
7770 TelephonyPermissions
7771 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007772 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007773 }
7774 final long identity = Binder.clearCallingIdentity();
7775 try {
sqian854d44b2018-12-12 16:48:18 -08007776 for (Phone phone: PhoneFactory.getPhones()) {
7777 if (phone.getEmergencyNumberTracker() != null
7778 && phone.getEmergencyNumberTracker() != null) {
7779 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7780 number, exactMatch)) {
7781 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007782 }
7783 }
sqian11b7a0e2018-12-05 18:48:28 -08007784 }
7785 return false;
7786 } finally {
7787 Binder.restoreCallingIdentity(identity);
7788 }
7789 }
7790
sqianf4ca7ed2019-01-15 18:32:07 -08007791 /**
7792 * Update emergency number list for test mode.
7793 */
7794 @Override
7795 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7796 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7797 "updateEmergencyNumberListTestMode");
7798
7799 final long identity = Binder.clearCallingIdentity();
7800 try {
7801 for (Phone phone: PhoneFactory.getPhones()) {
7802 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7803 if (tracker != null) {
7804 tracker.executeEmergencyNumberTestModeCommand(action, num);
7805 }
7806 }
7807 } finally {
7808 Binder.restoreCallingIdentity(identity);
7809 }
7810 }
7811
7812 /**
7813 * Get the full emergency number list for test mode.
7814 */
7815 @Override
7816 public List<String> getEmergencyNumberListTestMode() {
7817 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7818 "getEmergencyNumberListTestMode");
7819
7820 final long identity = Binder.clearCallingIdentity();
7821 try {
7822 Set<String> emergencyNumbers = new HashSet<>();
7823 for (Phone phone: PhoneFactory.getPhones()) {
7824 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7825 if (tracker != null) {
7826 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7827 emergencyNumbers.add(num.getNumber());
7828 }
7829 }
7830 }
7831 return new ArrayList<>(emergencyNumbers);
7832 } finally {
7833 Binder.restoreCallingIdentity(identity);
7834 }
7835 }
7836
chen xud6b45bd2018-10-30 22:27:10 -07007837 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007838 public int getEmergencyNumberDbVersion(int subId) {
7839 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7840
7841 final long identity = Binder.clearCallingIdentity();
7842 try {
7843 final Phone phone = getPhone(subId);
7844 if (phone == null) {
7845 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7846 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7847 }
7848 return phone.getEmergencyNumberDbVersion();
7849 } finally {
7850 Binder.restoreCallingIdentity(identity);
7851 }
7852 }
7853
7854 @Override
7855 public void notifyOtaEmergencyNumberDbInstalled() {
7856 enforceModifyPermission();
7857
7858 final long identity = Binder.clearCallingIdentity();
7859 try {
7860 for (Phone phone: PhoneFactory.getPhones()) {
7861 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7862 if (tracker != null) {
7863 tracker.updateOtaEmergencyNumberDatabase();
7864 }
7865 }
7866 } finally {
7867 Binder.restoreCallingIdentity(identity);
7868 }
7869 }
7870
7871 @Override
7872 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7873 enforceActiveEmergencySessionPermission();
7874
7875 final long identity = Binder.clearCallingIdentity();
7876 try {
7877 for (Phone phone: PhoneFactory.getPhones()) {
7878 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7879 if (tracker != null) {
7880 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7881 }
7882 }
7883 } finally {
7884 Binder.restoreCallingIdentity(identity);
7885 }
7886 }
7887
7888 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007889 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7890 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7891 Phone phone = getPhone(subId);
7892 if (phone == null) {
7893 return null;
7894 }
7895 final long identity = Binder.clearCallingIdentity();
7896 try {
7897 UiccProfile profile = UiccController.getInstance()
7898 .getUiccProfileForPhone(phone.getPhoneId());
7899 if (profile != null) {
7900 return profile.getCertsFromCarrierPrivilegeAccessRules();
7901 }
7902 } finally {
7903 Binder.restoreCallingIdentity(identity);
7904 }
7905 return null;
7906 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007907
7908 /**
7909 * Enable or disable a modem stack.
7910 */
7911 @Override
7912 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7913 enforceModifyPermission();
7914
7915 final long identity = Binder.clearCallingIdentity();
7916 try {
7917 Phone phone = PhoneFactory.getPhone(slotIndex);
7918 if (phone == null) {
7919 return false;
7920 } else {
7921 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7922 }
7923 } finally {
7924 Binder.restoreCallingIdentity(identity);
7925 }
7926 }
Michelecea4cf22018-12-21 15:00:11 -08007927
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007928 /**
7929 * Whether a modem stack is enabled or not.
7930 */
7931 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007932 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7933 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007934 Phone phone = PhoneFactory.getPhone(slotIndex);
7935 if (phone == null) return false;
7936
7937 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007938 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7939 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007940 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7941 }
7942
7943 final long identity = Binder.clearCallingIdentity();
7944 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007945 try {
7946 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7947 } catch (NoSuchElementException ex) {
7948 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7949 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007950 } finally {
7951 Binder.restoreCallingIdentity(identity);
7952 }
7953 }
7954
Michelecea4cf22018-12-21 15:00:11 -08007955 @Override
Michele0ea7d782019-03-19 14:58:42 -07007956 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007957 enforceModifyPermission();
7958
7959 final long identity = Binder.clearCallingIdentity();
7960 try {
7961 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007962 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007963 .commit();
7964 } finally {
7965 Binder.restoreCallingIdentity(identity);
7966 }
7967 }
7968
7969 @Override
Michele0ea7d782019-03-19 14:58:42 -07007970 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007971 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007972 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007973 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7974 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007975 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007976 }
Michelecea4cf22018-12-21 15:00:11 -08007977
7978 final long identity = Binder.clearCallingIdentity();
7979 try {
Michele0ea7d782019-03-19 14:58:42 -07007980 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007981 } finally {
7982 Binder.restoreCallingIdentity(identity);
7983 }
7984 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007985
Michele0ea7d782019-03-19 14:58:42 -07007986 @TelephonyManager.IsMultiSimSupportedResult
7987 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007988 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7989 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7990 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007991 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7992 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007993 }
7994 // Check if the hardware supports multisim functionality. If usage of multisim is not
7995 // supported by the modem, indicate that it is restricted.
7996 PhoneCapability staticCapability =
7997 mPhoneConfigurationManager.getStaticPhoneCapability();
7998 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007999 loge("isMultiSimSupportedInternal: no static configuration available");
8000 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008001 }
Sarah Chin5f0ecd72019-12-06 10:24:18 -08008002 if (staticCapability.getLogicalModemUuids().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008003 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8004 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008005 }
8006 // Check if support of multiple SIMs is restricted by carrier
8007 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008008 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008009 }
8010
Michele0ea7d782019-03-19 14:58:42 -07008011 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008012 }
8013
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008014 /**
8015 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008016 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8017 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8018 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008019 * @param numOfSims number of active sims we want to switch to
8020 */
8021 @Override
8022 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008023 if (numOfSims == 1) {
8024 enforceModifyPermission();
8025 } else {
8026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8027 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8028 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008029 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008030
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008031 try {
Michele30b57b22019-03-01 12:01:14 -08008032 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008033 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008034 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8035 return;
8036 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008037 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8038 } finally {
8039 Binder.restoreCallingIdentity(identity);
8040 }
8041 }
8042
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008043 @Override
8044 public boolean isApplicationOnUicc(int subId, int appType) {
8045 enforceReadPrivilegedPermission("isApplicationOnUicc");
8046 Phone phone = getPhone(subId);
8047 if (phone == null) {
8048 return false;
8049 }
8050 final long identity = Binder.clearCallingIdentity();
8051 try {
8052 UiccCard uiccCard = phone.getUiccCard();
8053 if (uiccCard == null) {
8054 return false;
8055 }
8056 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8057 if (uiccProfile == null) {
8058 return false;
8059 }
8060 if (TelephonyManager.APPTYPE_SIM <= appType
8061 && appType <= TelephonyManager.APPTYPE_ISIM) {
8062 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8063 }
8064 return false;
8065 } finally {
8066 Binder.restoreCallingIdentity(identity);
8067 }
8068 }
8069
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008070 /**
chen xub4baa772019-04-03 10:23:41 -07008071 * Get whether making changes to modem configurations will trigger reboot.
8072 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008073 */
8074 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008075 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8076 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008077 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008078 mApp, subId, callingPackage, callingFeatureId,
8079 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008080 return false;
8081 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008082 final long identity = Binder.clearCallingIdentity();
8083 try {
8084 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8085 } finally {
8086 Binder.restoreCallingIdentity(identity);
8087 }
8088 }
8089
Nathan Harold29f5f052019-02-15 13:41:57 -08008090 private void updateModemStateMetrics() {
8091 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8092 // TODO: check the state for each modem if the api is ready.
8093 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8094 }
8095
Pengquan Meng3889a572019-01-23 11:16:29 -08008096 @Override
8097 public int[] getSlotsMapping() {
8098 enforceReadPrivilegedPermission("getSlotsMapping");
8099
8100 final long identity = Binder.clearCallingIdentity();
8101 try {
8102 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8103 // All logical slots should have a mapping to a physical slot.
8104 int[] logicalSlotsMapping = new int[phoneCount];
8105 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8106 for (int i = 0; i < slotInfos.length; i++) {
8107 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8108 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8109 }
8110 }
8111 return logicalSlotsMapping;
8112 } finally {
8113 Binder.restoreCallingIdentity(identity);
8114 }
8115 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008116
8117 /**
8118 * Get the IRadio HAL Version
8119 */
8120 @Override
8121 public int getRadioHalVersion() {
8122 Phone phone = getDefaultPhone();
8123 if (phone == null) return -1;
8124 HalVersion hv = phone.getHalVersion();
8125 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8126 return hv.major * 100 + hv.minor;
8127 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008128
8129 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008130 * Get the current calling package name.
8131 * @return the current calling package name
8132 */
8133 @Override
8134 public String getCurrentPackageName() {
8135 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8136 }
8137
8138 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008139 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8140 * corresponding network requests on a subId.
8141 *
8142 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008143 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008144 * 2) APN is un-metered for this subscription, or
8145 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbetty97defcf2019-12-24 15:40:37 +08008146 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008147 *
8148 * @return whether data is allowed for a apn type.
8149 *
8150 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008151 */
8152 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008153 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008154 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8155 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008156
8157 // Now that all security checks passes, perform the operation as ourselves.
8158 final long identity = Binder.clearCallingIdentity();
8159 try {
8160 Phone phone = getPhone(subId);
8161 if (phone == null) return false;
8162
Jack Yu41407ee2019-05-13 16:54:09 -07008163 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008164 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8165 } finally {
8166 Binder.restoreCallingIdentity(identity);
8167 }
8168 }
8169
8170 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008171 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008172 enforceReadPrivilegedPermission("isApnMetered");
8173
8174 // Now that all security checks passes, perform the operation as ourselves.
8175 final long identity = Binder.clearCallingIdentity();
8176 try {
8177 Phone phone = getPhone(subId);
8178 if (phone == null) return true; // By default return true.
8179
Jack Yu41407ee2019-05-13 16:54:09 -07008180 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008181 } finally {
8182 Binder.restoreCallingIdentity(identity);
8183 }
8184 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008185
8186 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008187 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8188 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8189 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8190 if (iccRecords == null) {
8191 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8192 return false;
8193 }
8194 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8195 }
8196
8197 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07008198 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008199 if (callingPackage == null) {
8200 callingPackage = getCurrentPackageName();
8201 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008202 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8203 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
8204 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
8205 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8206 }
8207 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8208 Intent intent = new Intent();
8209 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8210 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8211 // Bring up choose default SMS subscription dialog right now
8212 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8213 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8214 mApp.startActivity(intent);
8215 }
chen xud5ca2d52019-05-28 15:20:57 -07008216
8217 @Override
8218 public String getMmsUAProfUrl(int subId) {
8219 //TODO investigate if this API should require proper permission check in R b/133791609
8220 final long identity = Binder.clearCallingIdentity();
8221 try {
8222 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8223 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8224 } finally {
8225 Binder.restoreCallingIdentity(identity);
8226 }
8227 }
8228
8229 @Override
8230 public String getMmsUserAgent(int subId) {
8231 //TODO investigate if this API should require proper permission check in R b/133791609
8232 final long identity = Binder.clearCallingIdentity();
8233 try {
8234 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8235 .getString(com.android.internal.R.string.config_mms_user_agent);
8236 } finally {
8237 Binder.restoreCallingIdentity(identity);
8238 }
8239 }
Jack Yub07d4972019-05-28 16:12:25 -07008240
8241 @Override
8242 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8243 enforceModifyPermission();
8244
8245 // Now that all security checks passes, perform the operation as ourselves.
8246 final long identity = Binder.clearCallingIdentity();
8247 try {
8248 Phone phone = getPhone(subId);
8249 if (phone == null) return false;
8250
8251 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8252 } finally {
8253 Binder.restoreCallingIdentity(identity);
8254 }
8255 }
8256
8257 @Override
8258 public boolean isDataAllowedInVoiceCall(int subId) {
8259 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8260
8261 // Now that all security checks passes, perform the operation as ourselves.
8262 final long identity = Binder.clearCallingIdentity();
8263 try {
8264 Phone phone = getPhone(subId);
8265 if (phone == null) return false;
8266
8267 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8268 } finally {
8269 Binder.restoreCallingIdentity(identity);
8270 }
8271 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008272
changbetty97defcf2019-12-24 15:40:37 +08008273 @Override
8274 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8275 enforceModifyPermission();
8276
8277 // Now that all security checks passes, perform the operation as ourselves.
8278 final long identity = Binder.clearCallingIdentity();
8279 try {
8280 Phone phone = getPhone(subId);
8281 if (phone == null) return false;
8282
8283 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8284 } finally {
8285 Binder.restoreCallingIdentity(identity);
8286 }
8287 }
8288
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008289 /**
8290 * Updates whether conference event pacakge handling is enabled.
8291 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8292 * otherwise.
8293 */
8294 @Override
8295 public void setCepEnabled(boolean isCepEnabled) {
8296 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8297
8298 final long identity = Binder.clearCallingIdentity();
8299 try {
8300 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8301 for (Phone phone : PhoneFactory.getPhones()) {
8302 Phone defaultPhone = phone.getImsPhone();
8303 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8304 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8305 ImsPhoneCallTracker imsPhoneCallTracker =
8306 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8307 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8308 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8309 + imsPhone.getMsisdn());
8310 }
8311 }
8312 } finally {
8313 Binder.restoreCallingIdentity(identity);
8314 }
8315 }
allenwtsu46dcc572020-01-08 18:24:03 +08008316
8317 /**
8318 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8319 *
8320 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8321 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8322 * before being read.
8323 */
8324 @Override
8325 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8326 isCompressed) {
8327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8328 mApp, subId, "notifyRcsAutoConfigurationReceived");
8329 try {
8330 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8331 if (configBinder == null) {
8332 Rlog.e(LOG_TAG, "null result for getImsConfig");
8333 } else {
8334 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8335 }
8336 } catch (RemoteException e) {
8337 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8338 }
8339 }
zoey chenf95ca592019-12-30 16:11:23 +08008340
8341 @Override
8342 public boolean isIccLockEnabled(int subId) {
8343 enforceReadPrivilegedPermission("isIccLockEnabled");
8344
8345 // Now that all security checks passes, perform the operation as ourselves.
8346 final long identity = Binder.clearCallingIdentity();
8347 try {
8348 Phone phone = getPhone(subId);
8349 if (phone != null && phone.getIccCard() != null) {
8350 return phone.getIccCard().getIccLockEnabled();
8351 } else {
8352 return false;
8353 }
8354 } finally {
8355 Binder.restoreCallingIdentity(identity);
8356 }
8357 }
8358
8359 /**
8360 * Set the ICC pin lock enabled or disabled..
8361 *
8362 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8363 * 0 or a positive integer as the attempts remaining value.
8364 *
8365 */
8366 @Override
8367 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8368 enforceModifyPermission();
8369
8370 Phone phone = getPhone(subId);
8371 if (phone == null) {
8372 return 0;
8373 }
8374 // Now that all security checks passes, perform the operation as ourselves.
8375 final long identity = Binder.clearCallingIdentity();
8376 try {
8377 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8378 new Pair<Boolean, String>(enabled, password), phone, null);
8379 return attemptsRemaining;
8380
8381 } catch (Exception e) {
8382 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8383 } finally {
8384 Binder.restoreCallingIdentity(identity);
8385 }
8386 return 0;
8387 }
8388
8389 /**
8390 * Change the ICC password used in ICC pin lock.
8391 *
8392 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8393 * 0 or a positive integer as the attempts remaining value.
8394 *
8395 */
8396 @Override
8397 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8398 enforceModifyPermission();
8399
8400 Phone phone = getPhone(subId);
8401 if (phone == null) {
8402 return 0;
8403 }
8404 // Now that all security checks passes, perform the operation as ourselves.
8405 final long identity = Binder.clearCallingIdentity();
8406 try {
8407 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8408 new Pair<String, String>(oldPassword, newPassword), phone, null);
8409 return attemptsRemaining;
8410
8411 } catch (Exception e) {
8412 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8413 } finally {
8414 Binder.restoreCallingIdentity(identity);
8415 }
8416 return 0;
8417 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008418}