blob: c5512eaf0db6dbd3461e08e6679110bdbdf9000b [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) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800911 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -0800912 // Service Class is a bit mask per 3gpp 27.007.
913 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800914 if (callForwardResults.length > 1
915 && ((callForwardResults[1]
916 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
917 callForwardingStatus = callForwardResults[0] == 0
sqian80370722020-01-29 15:02:51 -0800918 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
919 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
920 } else {
921 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
922 }
923 } else {
924 if (ar.result == null) {
925 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
926 }
927 if (ar.exception != null) {
928 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
929 }
930 if (ar.exception instanceof CommandException) {
931 CommandException.Error error =
932 ((CommandException) (ar.exception)).getCommandError();
933 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
934 callForwardingStatus =
935 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
936 }
937 }
938 }
939 request.result = callForwardingStatus;
940 notifyRequester(request);
941 break;
942
943 case CMD_SET_CALL_WAITING:
944 request = (MainThreadRequest) msg.obj;
945 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
946 boolean isEnable = (Boolean) request.argument;
947 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
948 break;
949
950 case EVENT_SET_CALL_WAITING_DONE:
951 ar = (AsyncResult) msg.obj;
952 request = (MainThreadRequest) ar.userObj;
953 if (ar.exception == null) {
954 request.result = true;
955 } else {
956 request.result = false;
957 loge("setCallWaiting exception: " + ar.exception);
958 }
959 notifyRequester(request);
960 break;
961
Shishir Agrawal302c8692015-06-19 13:49:39 -0700962 case EVENT_PERFORM_NETWORK_SCAN_DONE:
963 ar = (AsyncResult) msg.obj;
964 request = (MainThreadRequest) ar.userObj;
965 CellNetworkScanResult cellScanResult;
966 if (ar.exception == null && ar.result != null) {
967 cellScanResult = new CellNetworkScanResult(
968 CellNetworkScanResult.STATUS_SUCCESS,
969 (List<OperatorInfo>) ar.result);
970 } else {
971 if (ar.result == null) {
972 loge("getCellNetworkScanResults: Empty response");
973 }
974 if (ar.exception != null) {
975 loge("getCellNetworkScanResults: Exception: " + ar.exception);
976 }
977 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
978 if (ar.exception instanceof CommandException) {
979 CommandException.Error error =
980 ((CommandException) (ar.exception)).getCommandError();
981 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
982 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
983 } else if (error == CommandException.Error.GENERIC_FAILURE) {
984 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
985 }
986 }
987 cellScanResult = new CellNetworkScanResult(errorCode, null);
988 }
989 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700990 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700991 break;
992
993 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
994 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700995 ManualNetworkSelectionArgument selArg =
996 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700997 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
998 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700999 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1000 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001001 break;
1002
1003 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001004 ar = (AsyncResult) msg.obj;
1005 request = (MainThreadRequest) ar.userObj;
1006 if (ar.exception == null) {
1007 request.result = true;
1008 } else {
1009 request.result = false;
1010 loge("setNetworkSelectionModeManual " + ar.exception);
1011 }
1012 notifyRequester(request);
1013 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001014 break;
1015
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001016 case CMD_GET_MODEM_ACTIVITY_INFO:
1017 request = (MainThreadRequest) msg.obj;
1018 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001019 if (defaultPhone != null) {
1020 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
1021 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001022 break;
1023
1024 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1025 ar = (AsyncResult) msg.obj;
1026 request = (MainThreadRequest) ar.userObj;
1027 if (ar.exception == null && ar.result != null) {
1028 request.result = ar.result;
1029 } else {
1030 if (ar.result == null) {
1031 loge("queryModemActivityInfo: Empty response");
1032 } else if (ar.exception instanceof CommandException) {
1033 loge("queryModemActivityInfo: CommandException: " +
1034 ar.exception);
1035 } else {
1036 loge("queryModemActivityInfo: Unknown exception");
1037 }
1038 }
Amit Mahajand4766222016-01-28 15:28:28 -08001039 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
1040 if (request.result == null) {
Chen Xu13851032019-09-10 18:49:52 -07001041 request.result = new ModemActivityInfo(0, 0, 0, null, 0);
Amit Mahajand4766222016-01-28 15:28:28 -08001042 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001043 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001044 break;
1045
Meng Wang1a7c35a2016-05-05 20:56:15 -07001046 case CMD_SET_ALLOWED_CARRIERS:
1047 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001048 CarrierRestrictionRules argument =
1049 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001050 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001051 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001052 break;
1053
1054 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1055 ar = (AsyncResult) msg.obj;
1056 request = (MainThreadRequest) ar.userObj;
1057 if (ar.exception == null && ar.result != null) {
1058 request.result = ar.result;
1059 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001060 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1061 if (ar.exception instanceof CommandException) {
1062 loge("setAllowedCarriers: CommandException: " + ar.exception);
1063 CommandException.Error error =
1064 ((CommandException) (ar.exception)).getCommandError();
1065 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1066 request.result =
1067 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1068 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001069 } else {
1070 loge("setAllowedCarriers: Unknown exception");
1071 }
1072 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001073 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001074 break;
1075
1076 case CMD_GET_ALLOWED_CARRIERS:
1077 request = (MainThreadRequest) msg.obj;
1078 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001079 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001080 break;
1081
1082 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1083 ar = (AsyncResult) msg.obj;
1084 request = (MainThreadRequest) ar.userObj;
1085 if (ar.exception == null && ar.result != null) {
1086 request.result = ar.result;
1087 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001088 request.result = new IllegalStateException(
1089 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001090 if (ar.result == null) {
1091 loge("getAllowedCarriers: Empty response");
1092 } else if (ar.exception instanceof CommandException) {
1093 loge("getAllowedCarriers: CommandException: " +
1094 ar.exception);
1095 } else {
1096 loge("getAllowedCarriers: Unknown exception");
1097 }
1098 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001099 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001100 break;
1101
Nathan Haroldb3014052017-01-25 15:57:32 -08001102 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1103 ar = (AsyncResult) msg.obj;
1104 request = (MainThreadRequest) ar.userObj;
1105 if (ar.exception == null && ar.result != null) {
1106 request.result = ar.result;
1107 } else {
1108 request.result = new IllegalArgumentException(
1109 "Failed to retrieve Forbidden Plmns");
1110 if (ar.result == null) {
1111 loge("getForbiddenPlmns: Empty response");
1112 } else {
1113 loge("getForbiddenPlmns: Unknown exception");
1114 }
1115 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001116 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001117 break;
1118
1119 case CMD_GET_FORBIDDEN_PLMNS:
1120 request = (MainThreadRequest) msg.obj;
1121 uiccCard = getUiccCardFromRequest(request);
1122 if (uiccCard == null) {
1123 loge("getForbiddenPlmns() UiccCard is null");
1124 request.result = new IllegalArgumentException(
1125 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001126 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001127 break;
1128 }
1129 Integer appType = (Integer) request.argument;
1130 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1131 if (uiccApp == null) {
1132 loge("getForbiddenPlmns() no app with specified type -- "
1133 + appType);
1134 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001135 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001136 break;
1137 } else {
1138 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1139 + " specified type -- " + appType);
1140 }
1141 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1142 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1143 onCompleted);
1144 break;
1145
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001146 case CMD_SWITCH_SLOTS:
1147 request = (MainThreadRequest) msg.obj;
1148 int[] physicalSlots = (int[]) request.argument;
1149 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1150 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1151 break;
1152
1153 case EVENT_SWITCH_SLOTS_DONE:
1154 ar = (AsyncResult) msg.obj;
1155 request = (MainThreadRequest) ar.userObj;
1156 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001157 notifyRequester(request);
1158 break;
1159 case CMD_GET_NETWORK_SELECTION_MODE:
1160 request = (MainThreadRequest) msg.obj;
1161 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1162 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1163 break;
1164
1165 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1166 ar = (AsyncResult) msg.obj;
1167 request = (MainThreadRequest) ar.userObj;
1168 if (ar.exception != null) {
1169 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1170 } else {
1171 int mode = ((int[]) ar.result)[0];
1172 if (mode == 0) {
1173 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1174 } else {
1175 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1176 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001177 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001178 notifyRequester(request);
1179 break;
1180 case CMD_GET_CDMA_ROAMING_MODE:
1181 request = (MainThreadRequest) msg.obj;
1182 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1183 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1184 break;
1185 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1186 ar = (AsyncResult) msg.obj;
1187 request = (MainThreadRequest) ar.userObj;
1188 if (ar.exception != null) {
1189 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1190 } else {
1191 request.result = ((int[]) ar.result)[0];
1192 }
1193 notifyRequester(request);
1194 break;
1195 case CMD_SET_CDMA_ROAMING_MODE:
1196 request = (MainThreadRequest) msg.obj;
1197 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1198 int mode = (int) request.argument;
1199 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1200 break;
1201 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1202 ar = (AsyncResult) msg.obj;
1203 request = (MainThreadRequest) ar.userObj;
1204 request.result = ar.exception == null;
1205 notifyRequester(request);
1206 break;
1207 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1208 request = (MainThreadRequest) msg.obj;
1209 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1210 int subscriptionMode = (int) request.argument;
1211 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1212 break;
1213 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1214 ar = (AsyncResult) msg.obj;
1215 request = (MainThreadRequest) ar.userObj;
1216 request.result = ar.exception == null;
1217 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001218 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001219 case CMD_GET_ALL_CELL_INFO:
1220 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001221 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001222 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001223 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001224 case EVENT_GET_ALL_CELL_INFO_DONE:
1225 ar = (AsyncResult) msg.obj;
1226 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001227 // If a timeout occurs, the response will be null
1228 request.result = (ar.exception == null && ar.result != null)
1229 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001230 synchronized (request) {
1231 request.notifyAll();
1232 }
1233 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001234 case CMD_REQUEST_CELL_INFO_UPDATE:
1235 request = (MainThreadRequest) msg.obj;
1236 request.phone.requestCellInfoUpdate(request.workSource,
1237 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1238 break;
1239 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1240 ar = (AsyncResult) msg.obj;
1241 request = (MainThreadRequest) ar.userObj;
1242 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1243 try {
1244 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001245 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001246 cb.onError(
1247 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1248 ar.exception.getClass().getName(),
1249 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001250 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001251 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001252 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001253 } else {
1254 // use the result as returned
1255 cb.onCellInfo((List<CellInfo>) ar.result);
1256 }
1257 } catch (RemoteException re) {
1258 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1259 }
1260 break;
1261 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001262 request = (MainThreadRequest) msg.obj;
1263 WorkSource ws = (WorkSource) request.argument;
1264 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001265 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001266 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001267 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001268 ar = (AsyncResult) msg.obj;
1269 request = (MainThreadRequest) ar.userObj;
1270 if (ar.exception == null) {
1271 request.result = ar.result;
1272 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001273 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001274 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001275 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001276 }
1277
1278 synchronized (request) {
1279 request.notifyAll();
1280 }
1281 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001282 case CMD_MODEM_REBOOT:
1283 request = (MainThreadRequest) msg.obj;
1284 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001285 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001286 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001287 case EVENT_CMD_MODEM_REBOOT_DONE:
1288 handleNullReturnEvent(msg, "rebootModem");
1289 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001290 case CMD_REQUEST_ENABLE_MODEM:
1291 request = (MainThreadRequest) msg.obj;
1292 boolean enable = (boolean) request.argument;
1293 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001294 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001295 PhoneConfigurationManager.getInstance()
1296 .enablePhone(request.phone, enable, onCompleted);
1297 break;
1298 case EVENT_ENABLE_MODEM_DONE:
1299 ar = (AsyncResult) msg.obj;
1300 request = (MainThreadRequest) ar.userObj;
1301 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001302 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001303 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001304 if ((boolean) request.result) {
1305 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1306 updateModemStateMetrics();
1307 } else {
1308 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1309 + ar.exception);
1310 }
1311 notifyRequester(request);
1312 break;
1313 case CMD_GET_MODEM_STATUS:
1314 request = (MainThreadRequest) msg.obj;
1315 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1316 PhoneConfigurationManager.getInstance()
1317 .getPhoneStatusFromModem(request.phone, onCompleted);
1318 break;
1319 case EVENT_GET_MODEM_STATUS_DONE:
1320 ar = (AsyncResult) msg.obj;
1321 request = (MainThreadRequest) ar.userObj;
1322 int id = request.phone.getPhoneId();
1323 if (ar.exception == null && ar.result != null) {
1324 request.result = ar.result;
1325 //update the cache as modem status has changed
1326 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1327 (boolean) request.result);
1328 } else {
1329 // Return true if modem status cannot be retrieved. For most cases,
1330 // modem status is on. And for older version modems, GET_MODEM_STATUS
1331 // and disable modem are not supported. Modem is always on.
1332 // TODO: this should be fixed in R to support a third
1333 // status UNKNOWN b/131631629
1334 request.result = true;
1335 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1336 + ar.exception);
1337 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001338 notifyRequester(request);
1339 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001340 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1341 ar = (AsyncResult) msg.obj;
1342 request = (MainThreadRequest) ar.userObj;
1343 if (ar.exception == null && ar.result != null) {
1344 request.result = ar.result;
1345 } else {
1346 request.result = -1;
1347 loge("Failed to set Forbidden Plmns");
1348 if (ar.result == null) {
1349 loge("setForbidenPlmns: Empty response");
1350 } else if (ar.exception != null) {
1351 loge("setForbiddenPlmns: Exception: " + ar.exception);
1352 request.result = -1;
1353 } else {
1354 loge("setForbiddenPlmns: Unknown exception");
1355 }
1356 }
1357 notifyRequester(request);
1358 break;
1359 case CMD_SET_FORBIDDEN_PLMNS:
1360 request = (MainThreadRequest) msg.obj;
1361 uiccCard = getUiccCardFromRequest(request);
1362 if (uiccCard == null) {
1363 loge("setForbiddenPlmns: UiccCard is null");
1364 request.result = -1;
1365 notifyRequester(request);
1366 break;
1367 }
1368 Pair<Integer, List<String>> setFplmnsArgs =
1369 (Pair<Integer, List<String>>) request.argument;
1370 appType = setFplmnsArgs.first;
1371 List<String> fplmns = setFplmnsArgs.second;
1372 uiccApp = uiccCard.getApplicationByType(appType);
1373 if (uiccApp == null) {
1374 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1375 request.result = -1;
1376 loge("Failed to get UICC App");
1377 notifyRequester(request);
1378 } else {
1379 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1380 ((SIMRecords) uiccApp.getIccRecords())
1381 .setForbiddenPlmns(onCompleted, fplmns);
1382 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001383 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001384 case CMD_ERASE_MODEM_CONFIG:
1385 request = (MainThreadRequest) msg.obj;
1386 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1387 defaultPhone.eraseModemConfig(onCompleted);
1388 break;
1389 case EVENT_ERASE_MODEM_CONFIG_DONE:
1390 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001391 break;
zoey chenf95ca592019-12-30 16:11:23 +08001392
1393 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1394 request = (MainThreadRequest) msg.obj;
1395 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1396 Pair<String, String> changed = (Pair<String, String>) request.argument;
1397 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1398 changed.first, changed.second, onCompleted);
1399 break;
1400 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1401 ar = (AsyncResult) msg.obj;
1402 request = (MainThreadRequest) ar.userObj;
1403 if (ar.exception == null) {
1404 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1405 } else {
1406 request.result = msg.arg1;
1407 }
1408 notifyRequester(request);
1409 break;
1410
1411 case CMD_SET_ICC_LOCK_ENABLED:
1412 request = (MainThreadRequest) msg.obj;
1413 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1414 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1415 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1416 enabled.first, enabled.second, onCompleted);
1417 break;
1418 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1419 ar = (AsyncResult) msg.obj;
1420 request = (MainThreadRequest) ar.userObj;
1421 if (ar.exception == null) {
1422 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1423 } else {
1424 request.result = msg.arg1;
1425 }
1426 notifyRequester(request);
1427 break;
1428
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001429 default:
1430 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1431 break;
1432 }
1433 }
Jake Hambye994d462014-02-03 13:10:13 -08001434
Pengquan Menga1bb6272018-09-06 09:59:22 -07001435 private void notifyRequester(MainThreadRequest request) {
1436 synchronized (request) {
1437 request.notifyAll();
1438 }
1439 }
1440
Jake Hambye994d462014-02-03 13:10:13 -08001441 private void handleNullReturnEvent(Message msg, String command) {
1442 AsyncResult ar = (AsyncResult) msg.obj;
1443 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1444 if (ar.exception == null) {
1445 request.result = true;
1446 } else {
1447 request.result = false;
1448 if (ar.exception instanceof CommandException) {
1449 loge(command + ": CommandException: " + ar.exception);
1450 } else {
1451 loge(command + ": Unknown exception");
1452 }
1453 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001454 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001455 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001456 }
1457
1458 /**
1459 * Posts the specified command to be executed on the main thread,
1460 * waits for the request to complete, and returns the result.
1461 * @see #sendRequestAsync
1462 */
1463 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001464 return sendRequest(
1465 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001466 }
1467
1468 /**
1469 * Posts the specified command to be executed on the main thread,
1470 * waits for the request to complete, and returns the result.
1471 * @see #sendRequestAsync
1472 */
1473 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1474 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001475 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001476 }
1477
1478 /**
1479 * Posts the specified command to be executed on the main thread,
1480 * waits for the request to complete, and returns the result.
1481 * @see #sendRequestAsync
1482 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001483 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001484 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001485 }
1486
1487 /**
1488 * Posts the specified command to be executed on the main thread,
1489 * waits for the request to complete, and returns the result.
1490 * @see #sendRequestAsync
1491 */
Nathan Harold92bed182018-10-12 18:16:49 -07001492 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1493 return sendRequest(command, argument, subId, null, workSource);
1494 }
1495
1496 /**
1497 * Posts the specified command to be executed on the main thread,
1498 * waits for the request to complete, and returns the result.
1499 * @see #sendRequestAsync
1500 */
1501 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1502 return sendRequest(
1503 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1504 }
1505
1506 /**
1507 * Posts the specified command to be executed on the main thread,
1508 * waits for the request to complete, and returns the result.
1509 * @see #sendRequestAsync
1510 */
1511 private Object sendRequest(
1512 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001513 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1514 throw new RuntimeException("This method will deadlock if called from the main thread.");
1515 }
1516
Nathan Harold92bed182018-10-12 18:16:49 -07001517 MainThreadRequest request = null;
1518 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1519 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1520 } else if (phone != null) {
1521 request = new MainThreadRequest(argument, phone, workSource);
1522 } else {
1523 request = new MainThreadRequest(argument, subId, workSource);
1524 }
1525
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001526 Message msg = mMainThreadHandler.obtainMessage(command, request);
1527 msg.sendToTarget();
1528
1529 // Wait for the request to complete
1530 synchronized (request) {
1531 while (request.result == null) {
1532 try {
1533 request.wait();
1534 } catch (InterruptedException e) {
1535 // Do nothing, go back and wait until the request is complete
1536 }
1537 }
1538 }
1539 return request.result;
1540 }
1541
1542 /**
1543 * Asynchronous ("fire and forget") version of sendRequest():
1544 * Posts the specified command to be executed on the main thread, and
1545 * returns immediately.
1546 * @see #sendRequest
1547 */
1548 private void sendRequestAsync(int command) {
1549 mMainThreadHandler.sendEmptyMessage(command);
1550 }
1551
1552 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001553 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001554 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001555 */
1556 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001557 sendRequestAsync(command, argument, null, null);
1558 }
1559
1560 /**
1561 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1562 * @see {@link #sendRequest(int,Object)}
1563 */
1564 private void sendRequestAsync(
1565 int command, Object argument, Phone phone, WorkSource workSource) {
1566 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001567 Message msg = mMainThreadHandler.obtainMessage(command, request);
1568 msg.sendToTarget();
1569 }
1570
1571 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001572 * Initialize the singleton PhoneInterfaceManager instance.
1573 * This is only done once, at startup, from PhoneApp.onCreate().
1574 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001575 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001576 synchronized (PhoneInterfaceManager.class) {
1577 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001578 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001579 } else {
1580 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1581 }
1582 return sInstance;
1583 }
1584 }
1585
1586 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001587 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001588 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001589 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001590 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001591 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001592 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1593 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001594 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001595 mTelephonySharedPreferences =
1596 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001597 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001598 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001599
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001600 publish();
1601 }
1602
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001603 private Phone getDefaultPhone() {
1604 Phone thePhone = getPhone(getDefaultSubscription());
1605 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1606 }
1607
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001608 private void publish() {
1609 if (DBG) log("publish: " + this);
1610
1611 ServiceManager.addService("phone", this);
1612 }
1613
Stuart Scott584921c2015-01-15 17:10:34 -08001614 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001615 if (request.phone != null) {
1616 return request.phone;
1617 } else {
1618 return getPhoneFromSubId(request.subId);
1619 }
1620 }
1621
1622 private Phone getPhoneFromSubId(int subId) {
1623 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1624 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001625 }
1626
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001627 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1628 Phone phone = getPhoneFromRequest(request);
1629 return phone == null ? null :
1630 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1631 }
1632
Wink Saville36469e72014-06-11 15:17:00 -07001633 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001634 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001635 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001636 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001637
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001638 private void sendEraseModemConfig(Phone phone) {
1639 if (phone != null) {
1640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1641 mApp, phone.getSubId(), "eraseModemConfig");
1642 final long identity = Binder.clearCallingIdentity();
1643 try {
1644 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1645 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1646 } finally {
1647 Binder.restoreCallingIdentity(identity);
1648 }
1649 }
1650 }
1651
Peter Wang050bb052020-01-13 23:33:09 -08001652 private boolean isImsAvailableOnDevice() {
1653 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1654 if (pm == null) {
1655 // For some reason package manger is not available.. This will fail internally anyway,
1656 // so do not throw error and allow.
1657 return true;
1658 }
1659 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1660 }
1661
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001662 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001663 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001664 }
1665
Wink Savilleb564aae2014-10-23 10:18:09 -07001666 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001667 if (DBG) log("dial: " + number);
1668 // No permission check needed here: This is just a wrapper around the
1669 // ACTION_DIAL intent, which is available to any app since it puts up
1670 // the UI before it does anything.
1671
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001672 final long identity = Binder.clearCallingIdentity();
1673 try {
1674 String url = createTelUrl(number);
1675 if (url == null) {
1676 return;
1677 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001678
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001679 // PENDING: should we just silently fail if phone is offhook or ringing?
1680 PhoneConstants.State state = mCM.getState(subId);
1681 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1682 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1683 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1684 mApp.startActivity(intent);
1685 }
1686 } finally {
1687 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001688 }
1689 }
1690
1691 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001692 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001693 }
1694
Wink Savilleb564aae2014-10-23 10:18:09 -07001695 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001696 if (DBG) log("call: " + number);
1697
1698 // This is just a wrapper around the ACTION_CALL intent, but we still
1699 // need to do a permission check since we're calling startActivity()
1700 // from the context of the phone app.
1701 enforceCallPermission();
1702
Jordan Liu1617b712019-07-10 15:06:26 -07001703 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001704 != AppOpsManager.MODE_ALLOWED) {
1705 return;
1706 }
1707
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001708 final long identity = Binder.clearCallingIdentity();
1709 try {
1710 String url = createTelUrl(number);
1711 if (url == null) {
1712 return;
1713 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001714
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001715 boolean isValid = false;
1716 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1717 if (slist != null) {
1718 for (SubscriptionInfo subInfoRecord : slist) {
1719 if (subInfoRecord.getSubscriptionId() == subId) {
1720 isValid = true;
1721 break;
1722 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001723 }
Wink Saville08874612014-08-31 19:19:58 -07001724 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001725 if (!isValid) {
1726 return;
1727 }
Wink Saville08874612014-08-31 19:19:58 -07001728
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001729 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1730 intent.putExtra(SUBSCRIPTION_KEY, subId);
1731 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1732 mApp.startActivity(intent);
1733 } finally {
1734 Binder.restoreCallingIdentity(identity);
1735 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001736 }
1737
Wink Savilleb564aae2014-10-23 10:18:09 -07001738 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001739 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001740 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1741 }
1742
Wink Savilleb564aae2014-10-23 10:18:09 -07001743 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001744 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001745 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1746 }
1747
Wink Savilleb564aae2014-10-23 10:18:09 -07001748 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001749 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001750
1751 final long identity = Binder.clearCallingIdentity();
1752 try {
1753 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1754 checkSimPin.start();
1755 return checkSimPin.unlockSim(null, pin);
1756 } finally {
1757 Binder.restoreCallingIdentity(identity);
1758 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001759 }
1760
Wink Savilleb564aae2014-10-23 10:18:09 -07001761 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001762 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001763
1764 final long identity = Binder.clearCallingIdentity();
1765 try {
1766 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1767 checkSimPuk.start();
1768 return checkSimPuk.unlockSim(puk, pin);
1769 } finally {
1770 Binder.restoreCallingIdentity(identity);
1771 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001772 }
1773
1774 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001775 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001776 * a synchronous one.
1777 */
1778 private static class UnlockSim extends Thread {
1779
1780 private final IccCard mSimCard;
1781
1782 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001783 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1784 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785
1786 // For replies from SimCard interface
1787 private Handler mHandler;
1788
1789 // For async handler to identify request type
1790 private static final int SUPPLY_PIN_COMPLETE = 100;
1791
1792 public UnlockSim(IccCard simCard) {
1793 mSimCard = simCard;
1794 }
1795
1796 @Override
1797 public void run() {
1798 Looper.prepare();
1799 synchronized (UnlockSim.this) {
1800 mHandler = new Handler() {
1801 @Override
1802 public void handleMessage(Message msg) {
1803 AsyncResult ar = (AsyncResult) msg.obj;
1804 switch (msg.what) {
1805 case SUPPLY_PIN_COMPLETE:
1806 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1807 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001808 mRetryCount = msg.arg1;
1809 if (ar.exception != null) {
1810 if (ar.exception instanceof CommandException &&
1811 ((CommandException)(ar.exception)).getCommandError()
1812 == CommandException.Error.PASSWORD_INCORRECT) {
1813 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1814 } else {
1815 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1816 }
1817 } else {
1818 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1819 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001820 mDone = true;
1821 UnlockSim.this.notifyAll();
1822 }
1823 break;
1824 }
1825 }
1826 };
1827 UnlockSim.this.notifyAll();
1828 }
1829 Looper.loop();
1830 }
1831
1832 /*
1833 * Use PIN or PUK to unlock SIM card
1834 *
1835 * If PUK is null, unlock SIM card with PIN
1836 *
1837 * If PUK is not null, unlock SIM card with PUK and set PIN code
1838 */
Wink Saville9de0f752013-10-22 19:04:03 -07001839 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001840
1841 while (mHandler == null) {
1842 try {
1843 wait();
1844 } catch (InterruptedException e) {
1845 Thread.currentThread().interrupt();
1846 }
1847 }
1848 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1849
1850 if (puk == null) {
1851 mSimCard.supplyPin(pin, callback);
1852 } else {
1853 mSimCard.supplyPuk(puk, pin, callback);
1854 }
1855
1856 while (!mDone) {
1857 try {
1858 Log.d(LOG_TAG, "wait for done");
1859 wait();
1860 } catch (InterruptedException e) {
1861 // Restore the interrupted status
1862 Thread.currentThread().interrupt();
1863 }
1864 }
1865 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001866 int[] resultArray = new int[2];
1867 resultArray[0] = mResult;
1868 resultArray[1] = mRetryCount;
1869 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001870 }
1871 }
1872
1873 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001874 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001875
1876 }
1877
Wink Savilleb564aae2014-10-23 10:18:09 -07001878 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001879 // No permission check needed here: this call is harmless, and it's
1880 // needed for the ServiceState.requestStateUpdate() call (which is
1881 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001882 final long identity = Binder.clearCallingIdentity();
1883 try {
1884 final Phone phone = getPhone(subId);
1885 if (phone != null) {
1886 phone.updateServiceLocation();
1887 }
1888 } finally {
1889 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001890 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891 }
1892
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001893 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001894 @Override
1895 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001896 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001897 }
1898
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001899 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001900 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1901 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1902 callingFeatureId);
1903 }
1904
1905 @Deprecated
1906 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001907 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001908 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
1909 }
1910
1911 @Override
1912 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1913 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001914 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001915 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001916 return false;
1917 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001918
1919 final long identity = Binder.clearCallingIdentity();
1920 try {
1921 return isRadioOnForSubscriber(subId);
1922 } finally {
1923 Binder.restoreCallingIdentity(identity);
1924 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001925 }
1926
1927 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001928 final long identity = Binder.clearCallingIdentity();
1929 try {
1930 final Phone phone = getPhone(subId);
1931 if (phone != null) {
1932 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1933 } else {
1934 return false;
1935 }
1936 } finally {
1937 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001938 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001939 }
1940
1941 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001942 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 }
Wink Saville36469e72014-06-11 15:17:00 -07001944
Wink Savilleb564aae2014-10-23 10:18:09 -07001945 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001947
1948 final long identity = Binder.clearCallingIdentity();
1949 try {
1950 final Phone phone = getPhone(subId);
1951 if (phone != null) {
1952 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1953 }
1954 } finally {
1955 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001956 }
Wink Saville36469e72014-06-11 15:17:00 -07001957 }
1958
1959 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001960 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001961 }
1962
Wink Savilleb564aae2014-10-23 10:18:09 -07001963 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001964 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001965
1966 final long identity = Binder.clearCallingIdentity();
1967 try {
1968 final Phone phone = getPhone(subId);
1969 if (phone == null) {
1970 return false;
1971 }
1972 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1973 toggleRadioOnOffForSubscriber(subId);
1974 }
1975 return true;
1976 } finally {
1977 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001978 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001979 }
Wink Saville36469e72014-06-11 15:17:00 -07001980
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001981 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08001982 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001983 /*
1984 * If any of the Radios are available, it will need to be
1985 * shutdown. So return true if any Radio is available.
1986 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001987 final long identity = Binder.clearCallingIdentity();
1988 try {
1989 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1990 Phone phone = PhoneFactory.getPhone(i);
1991 if (phone != null && phone.isRadioAvailable()) return true;
1992 }
1993 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1994 return false;
1995 } finally {
1996 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001997 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001998 }
1999
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002000 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002001 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002002 enforceModifyPermission();
2003
2004 final long identity = Binder.clearCallingIdentity();
2005 try {
2006 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2007 logv("Shutting down Phone " + i);
2008 shutdownRadioUsingPhoneId(i);
2009 }
2010 } finally {
2011 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002012 }
2013 }
2014
2015 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002016 Phone phone = PhoneFactory.getPhone(phoneId);
2017 if (phone != null && phone.isRadioAvailable()) {
2018 phone.shutdownRadio();
2019 }
2020 }
2021
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002022 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002023 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002024
2025 final long identity = Binder.clearCallingIdentity();
2026 try {
2027 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2028 if (defaultPhone != null) {
2029 defaultPhone.setRadioPower(turnOn);
2030 return true;
2031 } else {
2032 loge("There's no default phone.");
2033 return false;
2034 }
2035 } finally {
2036 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002037 }
Wink Saville36469e72014-06-11 15:17:00 -07002038 }
2039
Wink Savilleb564aae2014-10-23 10:18:09 -07002040 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002041 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002042
2043 final long identity = Binder.clearCallingIdentity();
2044 try {
2045 final Phone phone = getPhone(subId);
2046 if (phone != null) {
2047 phone.setRadioPower(turnOn);
2048 return true;
2049 } else {
2050 return false;
2051 }
2052 } finally {
2053 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002054 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002055 }
2056
Wink Saville36469e72014-06-11 15:17:00 -07002057 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002058 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002059 public boolean enableDataConnectivity() {
2060 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002061
2062 final long identity = Binder.clearCallingIdentity();
2063 try {
2064 int subId = mSubscriptionController.getDefaultDataSubId();
2065 final Phone phone = getPhone(subId);
2066 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002067 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002068 return true;
2069 } else {
2070 return false;
2071 }
2072 } finally {
2073 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002074 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002075 }
2076
Wink Saville36469e72014-06-11 15:17:00 -07002077 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002078 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002079 public boolean disableDataConnectivity() {
2080 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002081
2082 final long identity = Binder.clearCallingIdentity();
2083 try {
2084 int subId = mSubscriptionController.getDefaultDataSubId();
2085 final Phone phone = getPhone(subId);
2086 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002087 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002088 return true;
2089 } else {
2090 return false;
2091 }
2092 } finally {
2093 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002094 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 }
2096
Sanket Padawe356d7632015-06-22 14:03:32 -07002097 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002098 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002099 final long identity = Binder.clearCallingIdentity();
2100 try {
2101 final Phone phone = getPhone(subId);
2102 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002103 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002104 } else {
2105 return false;
2106 }
2107 } finally {
2108 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002109 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002110 }
2111
2112 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002113 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002114 }
2115
pkanwarae03a6b2016-11-06 20:37:09 -08002116 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002117 enforceCallPermission();
2118
2119 final long identity = Binder.clearCallingIdentity();
2120 try {
2121 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2122 return;
2123 }
2124 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2125 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2126 } finally {
2127 Binder.restoreCallingIdentity(identity);
2128 }
pkanwar32d516d2016-10-14 19:37:38 -07002129 };
2130
Wink Savilleb564aae2014-10-23 10:18:09 -07002131 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002132 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002133
2134 final long identity = Binder.clearCallingIdentity();
2135 try {
2136 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2137 return false;
2138 }
2139 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2140 } finally {
2141 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002142 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002143 }
2144
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002145 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002146 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002147 }
2148
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002149 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002150 final long identity = Binder.clearCallingIdentity();
2151 try {
2152 Phone phone = PhoneFactory.getPhone(slotIndex);
2153 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2154 PhoneConstantConversions.convertCallState(phone.getState());
2155 } finally {
2156 Binder.restoreCallingIdentity(identity);
2157 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002158 }
2159
Sanket Padawe356d7632015-06-22 14:03:32 -07002160 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002161 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002162 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2163 }
2164
2165 @Override
2166 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002167 final long identity = Binder.clearCallingIdentity();
2168 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002169 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002170 if (phone != null) {
2171 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2172 } else {
2173 return PhoneConstantConversions.convertDataState(
2174 PhoneConstants.DataState.DISCONNECTED);
2175 }
2176 } finally {
2177 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002178 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002179 }
2180
Sanket Padawe356d7632015-06-22 14:03:32 -07002181 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002182 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002183 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2184 }
2185
2186 @Override
2187 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002188 final long identity = Binder.clearCallingIdentity();
2189 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002190 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002191 if (phone != null) {
2192 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2193 } else {
2194 return TelephonyManager.DATA_ACTIVITY_NONE;
2195 }
2196 } finally {
2197 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002198 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002199 }
2200
2201 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002202 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002203 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002204 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002205
2206 LocationAccessPolicy.LocationPermissionResult locationResult =
2207 LocationAccessPolicy.checkLocationPermission(mApp,
2208 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2209 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002210 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002211 .setCallingPid(Binder.getCallingPid())
2212 .setCallingUid(Binder.getCallingUid())
2213 .setMethod("getCellLocation")
2214 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2215 .build());
2216 switch (locationResult) {
2217 case DENIED_HARD:
2218 throw new SecurityException("Not allowed to access cell location");
2219 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002220 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2221 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002222 }
2223
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002224 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002225 final long identity = Binder.clearCallingIdentity();
2226 try {
2227 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002228 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002229 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002230 } finally {
2231 Binder.restoreCallingIdentity(identity);
2232 }
Svetoslav64fad262015-04-14 14:35:21 -07002233 }
2234
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002236 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2237 String callingFeatureId) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002238 if (!TextUtils.isEmpty(callingPackage)) {
2239 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002240 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2241 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002242 return "";
2243 }
2244 }
2245
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002246 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2247 // registered cell info, so return a NULL country instead.
2248 final long identity = Binder.clearCallingIdentity();
2249 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002250 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2251 // Get default phone in this case.
2252 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2253 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002254 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002255 // Todo: fix this when we can get the actual cellular network info when the device
2256 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002257 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002258 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2259 null)) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002260 return "";
2261 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002262 Phone phone = PhoneFactory.getPhone(phoneId);
2263 if (phone != null) {
2264 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002265 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002266 if (sst != null) {
2267 LocaleTracker lt = sst.getLocaleTracker();
2268 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002269 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2270 return lt.getCurrentCountry();
2271 } else if (emergencyNumberTracker != null) {
2272 return emergencyNumberTracker.getEmergencyCountryIso();
2273 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002274 }
2275 }
2276 }
2277 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002278 } finally {
2279 Binder.restoreCallingIdentity(identity);
2280 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002281 }
2282
2283 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002284 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002285 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002286 }
2287
Sanket Padawe356d7632015-06-22 14:03:32 -07002288 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002289 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002290 mApp.enforceCallingOrSelfPermission(
2291 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002292
2293 final long identity = Binder.clearCallingIdentity();
2294 try {
2295 final Phone phone = getPhone(subId);
2296 if (phone != null) {
2297 phone.enableLocationUpdates();
2298 }
2299 } finally {
2300 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002301 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002302 }
2303
2304 @Override
2305 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002306 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002307 }
2308
Sanket Padawe356d7632015-06-22 14:03:32 -07002309 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002310 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311 mApp.enforceCallingOrSelfPermission(
2312 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002313
2314 final long identity = Binder.clearCallingIdentity();
2315 try {
2316 final Phone phone = getPhone(subId);
2317 if (phone != null) {
2318 phone.disableLocationUpdates();
2319 }
2320 } finally {
2321 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002322 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002323 }
2324
Nathan Harold31d7ff32018-10-15 20:20:30 -07002325 /**
2326 * Returns the target SDK version number for a given package name.
2327 *
Nathan Haroldec184742019-07-10 17:04:16 -07002328 * This call MUST be invoked before clearing the calling UID.
2329 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002330 * @return target SDK if the package is found or INT_MAX.
2331 */
2332 private int getTargetSdk(String packageName) {
2333 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002334 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002335 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002336 if (ai != null) return ai.targetSdkVersion;
2337 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002338 loge("Failed to get package info for pkg="
2339 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002340 }
2341 return Integer.MAX_VALUE;
2342 }
2343
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002344 @Override
2345 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002346 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2347 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002348 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002349 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2350 throw new SecurityException(
2351 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2352 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002353
Jordan Liu1617b712019-07-10 15:06:26 -07002354 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2356 return null;
2357 }
Svetoslav64fad262015-04-14 14:35:21 -07002358
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002359 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002361 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002362 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002363
Nathan Haroldf180aac2018-06-01 18:43:55 -07002364 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2365 for (CellInfo ci : info) {
2366 if (ci instanceof CellInfoGsm) {
2367 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2368 } else if (ci instanceof CellInfoWcdma) {
2369 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2370 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002371 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002372 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002373 }
2374
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002375 private List<CellInfo> getCachedCellInfo() {
2376 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2377 for (Phone phone : PhoneFactory.getPhones()) {
2378 List<CellInfo> info = phone.getAllCellInfo();
2379 if (info != null) cellInfos.addAll(info);
2380 }
2381 return cellInfos;
2382 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002383
2384 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002385 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002386 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002387 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002388
2389 LocationAccessPolicy.LocationPermissionResult locationResult =
2390 LocationAccessPolicy.checkLocationPermission(mApp,
2391 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2392 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002393 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002394 .setCallingPid(Binder.getCallingPid())
2395 .setCallingUid(Binder.getCallingUid())
2396 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002397 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002398 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2399 .build());
2400 switch (locationResult) {
2401 case DENIED_HARD:
2402 throw new SecurityException("Not allowed to access cell info");
2403 case DENIED_SOFT:
2404 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405 }
2406
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002407 final int targetSdk = getTargetSdk(callingPackage);
2408 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2409 return getCachedCellInfo();
2410 }
2411
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002412 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002413 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002414 final long identity = Binder.clearCallingIdentity();
2415 try {
2416 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2417 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002418 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002419 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002420 if (info != null) cellInfos.addAll(info);
2421 }
2422 return cellInfos;
2423 } finally {
2424 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002425 }
2426 }
2427
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002428 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002429 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2430 String callingFeatureId) {
2431 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2432 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002433 }
2434
2435 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002436 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2437 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002438 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002439 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002440 }
2441
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002442 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2443 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002444 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002445 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002446
2447 LocationAccessPolicy.LocationPermissionResult locationResult =
2448 LocationAccessPolicy.checkLocationPermission(mApp,
2449 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2450 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002451 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002452 .setCallingPid(Binder.getCallingPid())
2453 .setCallingUid(Binder.getCallingUid())
2454 .setMethod("requestCellInfoUpdate")
2455 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2456 .build());
2457 switch (locationResult) {
2458 case DENIED_HARD:
2459 throw new SecurityException("Not allowed to access cell info");
2460 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002461 try {
2462 cb.onCellInfo(new ArrayList<CellInfo>());
2463 } catch (RemoteException re) {
2464 // Drop without consequences
2465 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002466 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002467 }
2468
Nathan Harolda939a962019-05-09 10:13:47 -07002469
2470 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002471 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2472
2473 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2474 }
2475
2476 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002478 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002479 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002480
2481 final long identity = Binder.clearCallingIdentity();
2482 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002483 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002484 } finally {
2485 Binder.restoreCallingIdentity(identity);
2486 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002487 }
2488
Shishir Agrawala9f32182016-04-12 12:00:16 -07002489 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002490 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002491 Phone phone = PhoneFactory.getPhone(slotIndex);
2492 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002493 return null;
2494 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002495 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002496 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002497 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002498 return null;
2499 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002500
2501 final long identity = Binder.clearCallingIdentity();
2502 try {
2503 return phone.getImei();
2504 } finally {
2505 Binder.restoreCallingIdentity(identity);
2506 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002507 }
2508
2509 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002510 public String getTypeAllocationCodeForSlot(int slotIndex) {
2511 Phone phone = PhoneFactory.getPhone(slotIndex);
2512 String tac = null;
2513 if (phone != null) {
2514 String imei = phone.getImei();
2515 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2516 }
2517 return tac;
2518 }
2519
2520 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002521 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002522 Phone phone = PhoneFactory.getPhone(slotIndex);
2523 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002524 return null;
2525 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002526
Jeff Davidson913390f2018-02-23 17:11:49 -08002527 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002528 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002529 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002530 return null;
2531 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002532
2533 final long identity = Binder.clearCallingIdentity();
2534 try {
2535 return phone.getMeid();
2536 } finally {
2537 Binder.restoreCallingIdentity(identity);
2538 }
Jack Yu2af8d712017-03-15 17:14:14 -07002539 }
2540
2541 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002542 public String getManufacturerCodeForSlot(int slotIndex) {
2543 Phone phone = PhoneFactory.getPhone(slotIndex);
2544 String manufacturerCode = null;
2545 if (phone != null) {
2546 String meid = phone.getMeid();
2547 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2548 }
2549 return manufacturerCode;
2550 }
2551
2552 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002553 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2554 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002555 Phone phone = PhoneFactory.getPhone(slotIndex);
2556 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002557 return null;
2558 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002559 int subId = phone.getSubId();
2560 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002561 mApp, subId, callingPackage, callingFeatureId,
2562 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002563 return null;
2564 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002565
2566 final long identity = Binder.clearCallingIdentity();
2567 try {
2568 return phone.getDeviceSvn();
2569 } finally {
2570 Binder.restoreCallingIdentity(identity);
2571 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002572 }
2573
fionaxu43304da2017-11-27 22:51:16 -08002574 @Override
2575 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002576 final long identity = Binder.clearCallingIdentity();
2577 try {
2578 final Phone phone = getPhone(subId);
2579 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2580 } finally {
2581 Binder.restoreCallingIdentity(identity);
2582 }
fionaxu43304da2017-11-27 22:51:16 -08002583 }
2584
2585 @Override
2586 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002587 final long identity = Binder.clearCallingIdentity();
2588 try {
2589 final Phone phone = getPhone(subId);
2590 return phone == null ? null : phone.getCarrierName();
2591 } finally {
2592 Binder.restoreCallingIdentity(identity);
2593 }
fionaxu43304da2017-11-27 22:51:16 -08002594 }
2595
calvinpanffe225e2018-11-01 19:43:06 +08002596 @Override
chen xu0026ca62019-03-06 15:28:50 -08002597 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002598 final long identity = Binder.clearCallingIdentity();
2599 try {
2600 final Phone phone = getPhone(subId);
2601 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002602 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002603 } finally {
2604 Binder.restoreCallingIdentity(identity);
2605 }
2606 }
2607
2608 @Override
chen xu0026ca62019-03-06 15:28:50 -08002609 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002610 final long identity = Binder.clearCallingIdentity();
2611 try {
2612 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002613 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002614 } finally {
2615 Binder.restoreCallingIdentity(identity);
2616 }
2617 }
2618
chen xu651eec72018-11-11 19:03:44 -08002619 @Override
chen xu864e11c2018-12-06 22:10:03 -08002620 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2621 if (!isSubscriptionMccMnc) {
2622 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2623 }
chen xu651eec72018-11-11 19:03:44 -08002624 final Phone phone = PhoneFactory.getPhone(slotIndex);
2625 if (phone == null) {
2626 return TelephonyManager.UNKNOWN_CARRIER_ID;
2627 }
2628 final long identity = Binder.clearCallingIdentity();
2629 try {
2630 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2631 } finally {
2632 Binder.restoreCallingIdentity(identity);
2633 }
2634 }
2635
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002636 //
2637 // Internal helper methods.
2638 //
2639
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002640 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002641 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2642 *
2643 * @throws SecurityException if the caller does not have the required permission
2644 */
2645 private void enforceModifyPermission() {
2646 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2647 }
2648
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002649 /**
2650 * Make sure the caller is system.
2651 *
2652 * @throws SecurityException if the caller is not system.
2653 */
2654 private void enforceSystemCaller() {
2655 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2656 throw new SecurityException("Caller must be system");
2657 }
2658 }
2659
Shuo Qianf2b2df42019-11-13 17:43:31 -08002660 private void enforceActiveEmergencySessionPermission() {
2661 mApp.enforceCallingOrSelfPermission(
2662 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2663 }
2664
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002665 /**
2666 * Make sure the caller has the CALL_PHONE permission.
2667 *
2668 * @throws SecurityException if the caller does not have the required permission
2669 */
2670 private void enforceCallPermission() {
2671 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2672 }
2673
paulhu423b5f22019-08-23 19:17:33 +08002674 private void enforceSettingsPermission() {
2675 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002676 }
2677
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002678 private String createTelUrl(String number) {
2679 if (TextUtils.isEmpty(number)) {
2680 return null;
2681 }
2682
Jake Hambye994d462014-02-03 13:10:13 -08002683 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002684 }
2685
Ihab Awadf9e92732013-12-05 18:02:52 -08002686 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002687 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2688 }
2689
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002690 private static void logv(String msg) {
2691 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2692 }
2693
Ihab Awadf9e92732013-12-05 18:02:52 -08002694 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002695 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2696 }
2697
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002698 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002699 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002700 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002701 }
2702
Sanket Padawe356d7632015-06-22 14:03:32 -07002703 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002704 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002705 final long identity = Binder.clearCallingIdentity();
2706 try {
2707 final Phone phone = PhoneFactory.getPhone(slotIndex);
2708 if (phone == null) {
2709 return PhoneConstants.PHONE_TYPE_NONE;
2710 } else {
2711 return phone.getPhoneType();
2712 }
2713 } finally {
2714 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002715 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002716 }
2717
2718 /**
2719 * Returns the CDMA ERI icon index to display
2720 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002721 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002722 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2723 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2724 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002725 }
2726
Sanket Padawe356d7632015-06-22 14:03:32 -07002727 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002728 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2729 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002730 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002731 mApp, subId, callingPackage, callingFeatureId,
2732 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002733 return -1;
2734 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735
2736 final long identity = Binder.clearCallingIdentity();
2737 try {
2738 final Phone phone = getPhone(subId);
2739 if (phone != null) {
2740 return phone.getCdmaEriIconIndex();
2741 } else {
2742 return -1;
2743 }
2744 } finally {
2745 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002746 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002747 }
2748
2749 /**
2750 * Returns the CDMA ERI icon mode,
2751 * 0 - ON
2752 * 1 - FLASHING
2753 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002754 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002755 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2756 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2757 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002758 }
2759
Sanket Padawe356d7632015-06-22 14:03:32 -07002760 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002761 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2762 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002763 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002764 mApp, subId, callingPackage, callingFeatureId,
2765 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002766 return -1;
2767 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002768
2769 final long identity = Binder.clearCallingIdentity();
2770 try {
2771 final Phone phone = getPhone(subId);
2772 if (phone != null) {
2773 return phone.getCdmaEriIconMode();
2774 } else {
2775 return -1;
2776 }
2777 } finally {
2778 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002779 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780 }
2781
2782 /**
2783 * Returns the CDMA ERI text,
2784 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002785 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002786 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2787 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2788 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002789 }
2790
Sanket Padawe356d7632015-06-22 14:03:32 -07002791 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002792 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2793 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002794 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002795 mApp, subId, callingPackage, callingFeatureId,
2796 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002797 return null;
2798 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002799
2800 final long identity = Binder.clearCallingIdentity();
2801 try {
2802 final Phone phone = getPhone(subId);
2803 if (phone != null) {
2804 return phone.getCdmaEriText();
2805 } else {
2806 return null;
2807 }
2808 } finally {
2809 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002810 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002811 }
2812
2813 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002814 * Returns the CDMA MDN.
2815 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002816 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002817 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002818 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2819 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002820
2821 final long identity = Binder.clearCallingIdentity();
2822 try {
2823 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002824 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002825 return phone.getLine1Number();
2826 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002827 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002828 return null;
2829 }
2830 } finally {
2831 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002832 }
2833 }
2834
2835 /**
2836 * Returns the CDMA MIN.
2837 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002838 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002839 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2841 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002842
2843 final long identity = Binder.clearCallingIdentity();
2844 try {
2845 final Phone phone = getPhone(subId);
2846 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2847 return phone.getCdmaMin();
2848 } else {
2849 return null;
2850 }
2851 } finally {
2852 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002853 }
2854 }
2855
Hall Liud892bec2018-11-30 14:51:45 -08002856 @Override
2857 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2858 INumberVerificationCallback callback, String callingPackage) {
2859 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2860 != PERMISSION_GRANTED) {
2861 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2862 }
2863 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2864
2865 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2866 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2867 throw new SecurityException("Calling package must be configured in the device config");
2868 }
2869
2870 if (range == null) {
2871 throw new NullPointerException("Range must be non-null");
2872 }
2873
2874 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002875 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002876
2877 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2878 }
2879
Junda Liuca05d5d2014-08-14 22:36:34 -07002880 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002881 * Returns true if CDMA provisioning needs to run.
2882 */
2883 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002884 final long identity = Binder.clearCallingIdentity();
2885 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002886 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002887 } finally {
2888 Binder.restoreCallingIdentity(identity);
2889 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002890 }
2891
2892 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002893 * Sets the voice mail number of a given subId.
2894 */
2895 @Override
2896 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08002897 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2898 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002899
2900 final long identity = Binder.clearCallingIdentity();
2901 try {
2902 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2903 new Pair<String, String>(alphaTag, number), new Integer(subId));
2904 return success;
2905 } finally {
2906 Binder.restoreCallingIdentity(identity);
2907 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002908 }
2909
Ta-wei Yen87c49842016-05-13 21:19:52 -07002910 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002911 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2912 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002913 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2914 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002915 if (!TextUtils.equals(callingPackage, systemDialer)) {
2916 throw new SecurityException("caller must be system dialer");
2917 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002918
2919 final long identity = Binder.clearCallingIdentity();
2920 try {
2921 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2922 if (phoneAccountHandle == null) {
2923 return null;
2924 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002925 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002926 } finally {
2927 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002928 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002929 }
2930
2931 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002932 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2933 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002934 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002935 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002936 mApp, subId, callingPackage, callingFeatureId,
2937 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002938 return null;
2939 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002940
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002941 final long identity = Binder.clearCallingIdentity();
2942 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002943 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002944 } finally {
2945 Binder.restoreCallingIdentity(identity);
2946 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002947 }
2948
2949 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002950 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2951 VisualVoicemailSmsFilterSettings settings) {
2952 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002953
2954 final long identity = Binder.clearCallingIdentity();
2955 try {
2956 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002957 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002958 } finally {
2959 Binder.restoreCallingIdentity(identity);
2960 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002961 }
2962
2963 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002964 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2965 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002966
2967 final long identity = Binder.clearCallingIdentity();
2968 try {
2969 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002970 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002971 } finally {
2972 Binder.restoreCallingIdentity(identity);
2973 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002974 }
2975
2976 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002977 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2978 String callingPackage, int subId) {
2979 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002980
2981 final long identity = Binder.clearCallingIdentity();
2982 try {
2983 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002984 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002985 } finally {
2986 Binder.restoreCallingIdentity(identity);
2987 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002988 }
2989
2990 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002991 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002992 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002993
2994 final long identity = Binder.clearCallingIdentity();
2995 try {
2996 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002997 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002998 } finally {
2999 Binder.restoreCallingIdentity(identity);
3000 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003001 }
3002
3003 @Override
3004 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
3005 String number, int port, String text, PendingIntent sentIntent) {
3006 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003007 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003008 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003009 SmsController smsController = PhoneFactory.getSmsController();
3010 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
3011 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003012 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003013
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003014 /**
fionaxu0152e512016-11-14 13:36:14 -08003015 * Sets the voice activation state of a given subId.
3016 */
3017 @Override
3018 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003019 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3020 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003021
3022 final long identity = Binder.clearCallingIdentity();
3023 try {
3024 final Phone phone = getPhone(subId);
3025 if (phone != null) {
3026 phone.setVoiceActivationState(activationState);
3027 } else {
3028 loge("setVoiceActivationState fails with invalid subId: " + subId);
3029 }
3030 } finally {
3031 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003032 }
3033 }
3034
3035 /**
3036 * Sets the data activation state of a given subId.
3037 */
3038 @Override
3039 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003040 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3041 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003042
3043 final long identity = Binder.clearCallingIdentity();
3044 try {
3045 final Phone phone = getPhone(subId);
3046 if (phone != null) {
3047 phone.setDataActivationState(activationState);
3048 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003049 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003050 }
3051 } finally {
3052 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003053 }
3054 }
3055
3056 /**
3057 * Returns the voice activation state of a given subId.
3058 */
3059 @Override
3060 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003061 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003062
fionaxu0152e512016-11-14 13:36:14 -08003063 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003064 final long identity = Binder.clearCallingIdentity();
3065 try {
3066 if (phone != null) {
3067 return phone.getVoiceActivationState();
3068 } else {
3069 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3070 }
3071 } finally {
3072 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003073 }
3074 }
3075
3076 /**
3077 * Returns the data activation state of a given subId.
3078 */
3079 @Override
3080 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003081 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003082
fionaxu0152e512016-11-14 13:36:14 -08003083 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003084 final long identity = Binder.clearCallingIdentity();
3085 try {
3086 if (phone != null) {
3087 return phone.getDataActivationState();
3088 } else {
3089 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3090 }
3091 } finally {
3092 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003093 }
3094 }
3095
3096 /**
Wink Saville36469e72014-06-11 15:17:00 -07003097 * Returns the unread count of voicemails for a subId
3098 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003099 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003100 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3101 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003102 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003103 mApp, subId, callingPackage, callingFeatureId,
3104 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003105 return 0;
3106 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003107 final long identity = Binder.clearCallingIdentity();
3108 try {
3109 final Phone phone = getPhone(subId);
3110 if (phone != null) {
3111 return phone.getVoiceMessageCount();
3112 } else {
3113 return 0;
3114 }
3115 } finally {
3116 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003117 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003118 }
3119
3120 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003121 * returns true, if the device is in a state where both voice and data
3122 * are supported simultaneously. This can change based on location or network condition.
3123 */
3124 @Override
3125 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003126 final long identity = Binder.clearCallingIdentity();
3127 try {
3128 final Phone phone = getPhone(subId);
3129 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3130 } finally {
3131 Binder.restoreCallingIdentity(identity);
3132 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003133 }
3134
3135 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003136 * Send the dialer code if called from the current default dialer or the caller has
3137 * carrier privilege.
3138 * @param inputCode The dialer code to send
3139 */
3140 @Override
3141 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003142 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003143 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003144 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3145 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003146 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003147 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003148 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003149 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003150
3151 final long identity = Binder.clearCallingIdentity();
3152 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003153 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003154 } finally {
3155 Binder.restoreCallingIdentity(identity);
3156 }
fionaxu235cc5e2017-03-06 22:25:57 -08003157 }
3158
Pengquan Menga1bb6272018-09-06 09:59:22 -07003159 @Override
3160 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003161 TelephonyPermissions
3162 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3163 mApp, subId, "getNetworkSelectionMode");
3164 final long identity = Binder.clearCallingIdentity();
3165 try {
3166 if (!isActiveSubscription(subId)) {
3167 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3168 }
3169 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3170 } finally {
3171 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003172 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003173 }
3174
Brad Ebinger35c841c2018-10-01 10:40:55 -07003175 @Override
Sarah Chin5f0ecd72019-12-06 10:24:18 -08003176 public PhoneCapability getPhoneCapability(int subId, String callingPackage,
3177 String callingFeatureId) {
3178 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3179 mApp, subId, callingPackage, callingFeatureId, "getPhoneCapability")) {
3180 return null;
3181 }
3182 final long identity = Binder.clearCallingIdentity();
3183 try {
3184 return mPhoneConfigurationManager.getStaticPhoneCapability();
3185 } finally {
3186 Binder.restoreCallingIdentity(identity);
3187 }
3188 }
3189
3190 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003191 public boolean isInEmergencySmsMode() {
3192 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3193 final long identity = Binder.clearCallingIdentity();
3194 try {
3195 for (Phone phone : PhoneFactory.getPhones()) {
3196 if (phone.isInEmergencySmsMode()) {
3197 return true;
3198 }
3199 }
3200 } finally {
3201 Binder.restoreCallingIdentity(identity);
3202 }
3203 return false;
3204 }
3205
shilu366312e2019-12-17 09:28:10 -08003206 /**
3207 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3208 * @param subId The subscription to use to check the configuration.
3209 * @param c The callback that will be used to send the result.
3210 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003211 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003212 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3213 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003214 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003215 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003216
Brad Ebinger77b832e2019-10-17 17:03:22 -07003217 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3218 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3219 "IMS not available on device.");
3220 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003221 final long token = Binder.clearCallingIdentity();
3222 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003223 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003224 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003225 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003226 } catch (ImsException e) {
3227 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003228 } finally {
3229 Binder.restoreCallingIdentity(token);
3230 }
3231 }
3232
shilu366312e2019-12-17 09:28:10 -08003233 /**
3234 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3235 * @param subId The subscription to use to check the configuration.
3236 * @param c The callback that will be used to send the result.
3237 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003238 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003239 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
shilu366312e2019-12-17 09:28:10 -08003240 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003241 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003242 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3243 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3244 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003245 final long token = Binder.clearCallingIdentity();
3246 try {
3247 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3248 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3249 .removeRegistrationCallbackForSubscription(c, subId);
3250 } catch (ImsException e) {
3251 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3252 + "is inactive, ignoring unregister.");
3253 // If the subscription is no longer active, just return, since the callback
3254 // will already have been removed internally.
3255 } finally {
3256 Binder.restoreCallingIdentity(token);
3257 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003258 }
3259
Brad Ebinger774ba362019-10-22 17:36:18 -07003260 /**
3261 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3262 */
3263 @Override
3264 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3265 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3266 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3267 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3268 "IMS not available on device.");
3269 }
3270 final long token = Binder.clearCallingIdentity();
3271 try {
3272 Phone phone = getPhone(subId);
3273 if (phone == null) {
3274 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3275 + subId + "'");
3276 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3277 }
3278 phone.getImsRegistrationState(regState -> {
3279 try {
3280 consumer.accept((regState == null)
3281 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3282 } catch (RemoteException e) {
3283 // Ignore if the remote process is no longer available to call back.
3284 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3285 }
3286 });
3287 } finally {
3288 Binder.restoreCallingIdentity(token);
3289 }
3290 }
3291
3292 /**
3293 * Get the transport type for the IMS service registration state.
3294 */
3295 @Override
3296 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
shilu366312e2019-12-17 09:28:10 -08003297 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger774ba362019-10-22 17:36:18 -07003298 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3299 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3300 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3301 "IMS not available on device.");
3302 }
3303 final long token = Binder.clearCallingIdentity();
3304 try {
3305 Phone phone = getPhone(subId);
3306 if (phone == null) {
3307 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3308 + subId + "'");
3309 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3310 }
3311 phone.getImsRegistrationTech(regTech -> {
3312 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3313 int regTechConverted = (regTech == null)
3314 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3315 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3316 regTechConverted);
3317 try {
3318 consumer.accept(regTechConverted);
3319 } catch (RemoteException e) {
3320 // Ignore if the remote process is no longer available to call back.
3321 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3322 }
3323 });
3324 } finally {
3325 Binder.restoreCallingIdentity(token);
3326 }
3327 }
3328
shilu366312e2019-12-17 09:28:10 -08003329 /**
3330 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3331 * @param subId The subscription to use to check the configuration.
3332 * @param c The callback that will be used to send the result.
3333 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003334 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003335 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3336 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003337 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003338 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003339 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3340 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3341 "IMS not available on device.");
3342 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003343 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3344 final long token = Binder.clearCallingIdentity();
3345 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003346 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003347 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003348 } catch (ImsException e) {
3349 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003350 } finally {
3351 Binder.restoreCallingIdentity(token);
3352 }
3353 }
3354
shilu366312e2019-12-17 09:28:10 -08003355 /**
3356 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3357 * @param subId The subscription to use to check the configuration.
3358 * @param c The callback that will be used to send the result.
3359 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003360 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003361 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
shilu366312e2019-12-17 09:28:10 -08003362 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003363 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003364 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3365 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3366 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003367
3368 final long token = Binder.clearCallingIdentity();
3369 try {
3370 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3371 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003372 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003373 } catch (ImsException e) {
3374 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3375 + "is inactive, ignoring unregister.");
3376 // If the subscription is no longer active, just return, since the callback
3377 // will already have been removed internally.
3378 } finally {
3379 Binder.restoreCallingIdentity(token);
3380 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003381 }
3382
3383 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003384 public boolean isCapable(int subId, int capability, int regTech) {
3385 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003386 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3387 final long token = Binder.clearCallingIdentity();
3388 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003389 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003390 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003391 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003392 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3393 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003394 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003395 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3396 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003397 } finally {
3398 Binder.restoreCallingIdentity(token);
3399 }
3400 }
3401
3402 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003403 public boolean isAvailable(int subId, int capability, int regTech) {
3404 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003405 final long token = Binder.clearCallingIdentity();
3406 try {
3407 Phone phone = getPhone(subId);
3408 if (phone == null) return false;
3409 return phone.isImsCapabilityAvailable(capability, regTech);
3410 } finally {
3411 Binder.restoreCallingIdentity(token);
3412 }
3413 }
3414
Brad Ebinger77b832e2019-10-17 17:03:22 -07003415 /**
3416 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3417 * subscription.
3418 * @param subId The subscription to use to check the configuration.
3419 * @param callback The callback that will be used to send the result.
3420 * @param capability The MmTelFeature capability that will be used to send the result.
3421 * @param transportType The transport type of the MmTelFeature capability.
3422 */
3423 @Override
3424 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3425 int transportType) {
3426 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3427 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3428 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3429 "IMS not available on device.");
3430 }
3431 final long token = Binder.clearCallingIdentity();
3432 try {
3433 int slotId = getSlotIndex(subId);
3434 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3435 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3436 + subId + "'");
3437 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3438 }
3439 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3440 transportType, aBoolean -> {
3441 try {
3442 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3443 } catch (RemoteException e) {
3444 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3445 + "running. Ignore");
3446 }
3447 });
3448 } finally {
3449 Binder.restoreCallingIdentity(token);
3450 }
3451 }
3452
shilu366312e2019-12-17 09:28:10 -08003453 /**
3454 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3455 * @param subId The subscription to use to check the configuration.
3456 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003457 @Override
3458 public boolean isAdvancedCallingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003459 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
3460 enforceReadPrivilegedPermission("isAdvancedCallingSettingEnabled");
3461
Brad Ebinger35c841c2018-10-01 10:40:55 -07003462 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3463 final long token = Binder.clearCallingIdentity();
3464 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003465 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003466 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003467 } catch (ImsException e) {
3468 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003469 } finally {
3470 Binder.restoreCallingIdentity(token);
3471 }
3472 }
3473
3474 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003475 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003476 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003477 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003478 final long identity = Binder.clearCallingIdentity();
3479 try {
3480 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003481 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003482 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003483 } catch (ImsException e) {
3484 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003485 } finally {
3486 Binder.restoreCallingIdentity(identity);
3487 }
3488 }
3489
shilu366312e2019-12-17 09:28:10 -08003490 /**
3491 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3492 * @param subId The subscription to use to check the configuration.
3493 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003494 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003495 public boolean isVtSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003496 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003497 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003498 final long identity = Binder.clearCallingIdentity();
3499 try {
3500 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003501 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3502 } catch (ImsException e) {
3503 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003504 } finally {
3505 Binder.restoreCallingIdentity(identity);
3506 }
3507 }
3508
3509 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003510 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003511 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003512 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003513 final long identity = Binder.clearCallingIdentity();
3514 try {
3515 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003516 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003517 } catch (ImsException e) {
3518 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003519 } finally {
3520 Binder.restoreCallingIdentity(identity);
3521 }
3522 }
3523
shilu366312e2019-12-17 09:28:10 -08003524 /**
3525 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3526 * @param subId The subscription to use to check the configuration.
3527 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003528 @Override
3529 public boolean isVoWiFiSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003530 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003531 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3532 final long identity = Binder.clearCallingIdentity();
3533 try {
3534 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003535 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003536 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003537 } catch (ImsException e) {
3538 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003539 } finally {
3540 Binder.restoreCallingIdentity(identity);
3541 }
3542 }
3543
3544 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003545 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003546 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003547 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003548 final long identity = Binder.clearCallingIdentity();
3549 try {
3550 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003551 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003552 } catch (ImsException e) {
3553 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003554 } finally {
3555 Binder.restoreCallingIdentity(identity);
3556 }
3557 }
3558
shilu366312e2019-12-17 09:28:10 -08003559 /**
3560 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3561 * @param subId The subscription to use to check the configuration.
3562 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003563 @Override
3564 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003565 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003566 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3567 final long identity = Binder.clearCallingIdentity();
3568 try {
3569 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003570 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003571 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003572 } catch (ImsException e) {
3573 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003574 } finally {
3575 Binder.restoreCallingIdentity(identity);
3576 }
3577 }
3578
3579 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003580 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003581 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003582 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003583 final long identity = Binder.clearCallingIdentity();
3584 try {
3585 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003586 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003587 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003588 } catch (ImsException e) {
3589 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003590 } finally {
3591 Binder.restoreCallingIdentity(identity);
3592 }
3593 }
3594
3595 @Override
3596 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3597 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3598 "setVoWiFiNonPersistent");
3599 final long identity = Binder.clearCallingIdentity();
3600 try {
3601 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003602 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003603 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003604 } catch (ImsException e) {
3605 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003606 } finally {
3607 Binder.restoreCallingIdentity(identity);
3608 }
3609 }
3610
shilu366312e2019-12-17 09:28:10 -08003611 /**
3612 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3613 * @param subId The subscription to use to check the configuration.
3614 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003615 @Override
3616 public int getVoWiFiModeSetting(int subId) {
shilu366312e2019-12-17 09:28:10 -08003617 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003618 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3619 final long identity = Binder.clearCallingIdentity();
3620 try {
3621 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003622 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003623 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003624 } catch (ImsException e) {
3625 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003626 } finally {
3627 Binder.restoreCallingIdentity(identity);
3628 }
3629 }
3630
3631 @Override
3632 public void setVoWiFiModeSetting(int subId, int mode) {
3633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3634 "setVoWiFiModeSetting");
3635 final long identity = Binder.clearCallingIdentity();
3636 try {
3637 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003638 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003639 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003640 } catch (ImsException e) {
3641 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003642 } finally {
3643 Binder.restoreCallingIdentity(identity);
3644 }
3645 }
3646
3647 @Override
3648 public int getVoWiFiRoamingModeSetting(int subId) {
3649 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3650 final long identity = Binder.clearCallingIdentity();
3651 try {
3652 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003653 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003654 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003655 } catch (ImsException e) {
3656 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003657 } finally {
3658 Binder.restoreCallingIdentity(identity);
3659 }
3660 }
3661
3662 @Override
3663 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3664 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3665 "setVoWiFiRoamingModeSetting");
3666 final long identity = Binder.clearCallingIdentity();
3667 try {
3668 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003669 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003670 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003671 } catch (ImsException e) {
3672 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003673 } finally {
3674 Binder.restoreCallingIdentity(identity);
3675 }
3676 }
3677
3678 @Override
3679 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3680 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3681 "setRttCapabilityEnabled");
3682 final long identity = Binder.clearCallingIdentity();
3683 try {
3684 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003685 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3686 } catch (ImsException e) {
3687 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003688 } finally {
3689 Binder.restoreCallingIdentity(identity);
3690 }
3691 }
3692
shilu366312e2019-12-17 09:28:10 -08003693 /**
3694 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3695 * @param subId The subscription to use to check the configuration.
3696 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003697 @Override
3698 public boolean isTtyOverVolteEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003699 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003700 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3701 final long identity = Binder.clearCallingIdentity();
3702 try {
3703 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003704 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003705 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003706 } catch (ImsException e) {
3707 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003708 } finally {
3709 Binder.restoreCallingIdentity(identity);
3710 }
3711 }
3712
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003713 @Override
3714 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3715 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3716 final long identity = Binder.clearCallingIdentity();
3717 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003718 if (!isImsAvailableOnDevice()) {
3719 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3720 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003721 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003722 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003723 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003724 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003725 } catch (ImsException e) {
3726 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003727 } finally {
3728 Binder.restoreCallingIdentity(identity);
3729 }
3730 }
3731
3732 @Override
3733 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3734 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3735 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003736 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3737 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3738 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003739 try {
3740 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003741 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003742 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003743 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003744 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3745 + "is inactive, ignoring unregister.");
3746 // If the subscription is no longer active, just return, since the callback will already
3747 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003748 } finally {
3749 Binder.restoreCallingIdentity(identity);
3750 }
3751 }
3752
allenwtsu99c623b2020-01-03 18:24:23 +08003753
3754 private void checkModifyPhoneStatePermission(int subId, String message) {
3755 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3756 message);
3757 }
3758
3759 private boolean isImsProvisioningRequired(int subId, int capability,
3760 boolean isMmtelCapability) {
3761 Phone phone = getPhone(subId);
3762 if (phone == null) {
3763 loge("phone instance null for subid " + subId);
3764 return false;
3765 }
3766 if (isMmtelCapability) {
3767 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3768 return false;
3769 }
3770 } else {
3771 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3772 return false;
3773 }
3774 }
3775 return true;
3776 }
3777
3778 @Override
3779 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3780 boolean isProvisioned) {
3781 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3782
3783 final long identity = Binder.clearCallingIdentity();
3784 try {
3785 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3786 if (!isImsProvisioningRequired(subId, capability, false)) {
3787 return;
3788 }
3789
3790 // this capability requires provisioning, route to the correct API.
3791 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3792 switch (capability) {
3793 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3794 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3795 ims.setEabProvisioned(isProvisioned);
3796 break;
3797 default: {
3798 throw new IllegalArgumentException("Tried to set provisioning for "
3799 + "rcs capability '" + capability + "', which does not require "
3800 + "provisioning.");
3801 }
3802 }
3803 } finally {
3804 Binder.restoreCallingIdentity(identity);
3805 }
3806
3807 }
3808
3809
3810 @Override
3811 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3812 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3813 final long identity = Binder.clearCallingIdentity();
3814 try {
3815 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3816 if (!isImsProvisioningRequired(subId, capability, false)) {
3817 return true;
3818 }
3819
3820 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3821 switch (capability) {
3822 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3823 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3824 return ims.isEabProvisionedOnDevice();
3825
3826 default: {
3827 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3828 + "capability '" + capability + "', which does not require "
3829 + "provisioning.");
3830 }
3831 }
3832
3833 } finally {
3834 Binder.restoreCallingIdentity(identity);
3835 }
3836 }
3837
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003838 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003839 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3840 boolean isProvisioned) {
3841 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3842 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3843 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3844 }
allenwtsu99c623b2020-01-03 18:24:23 +08003845 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003846 final long identity = Binder.clearCallingIdentity();
3847 try {
3848 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003849 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003850 return;
3851 }
3852
3853 // this capability requires provisioning, route to the correct API.
3854 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3855 switch (capability) {
3856 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3857 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3858 ims.setVolteProvisioned(isProvisioned);
3859 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3860 ims.setWfcProvisioned(isProvisioned);
3861 }
3862 break;
3863 }
3864 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3865 // There is currently no difference in VT provisioning type.
3866 ims.setVtProvisioned(isProvisioned);
3867 break;
3868 }
3869 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3870 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3871 // change the capability of the feature instead if needed.
3872 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3873 == isProvisioned) {
3874 // No change in provisioning.
3875 return;
3876 }
3877 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3878 try {
3879 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003880 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003881 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3882 + ", Exception" + e.getMessage());
3883 }
3884 break;
3885 }
3886 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003887 throw new IllegalArgumentException("Tried to set provisioning for "
3888 + "MmTel capability '" + capability + "', which does not require "
3889 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003890 }
3891 }
3892
3893 } finally {
3894 Binder.restoreCallingIdentity(identity);
3895 }
3896 }
3897
3898 @Override
3899 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3900 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3901 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3902 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3903 }
3904 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3905 final long identity = Binder.clearCallingIdentity();
3906 try {
3907 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003908 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003909 return true;
3910 }
3911
3912 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3913 switch (capability) {
3914 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3915 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3916 return ims.isVolteProvisionedOnDevice();
3917 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3918 return ims.isWfcProvisionedOnDevice();
3919 }
3920 // This should never happen, since we are checking tech above to make sure it
3921 // is either LTE or IWLAN.
3922 throw new IllegalArgumentException("Invalid radio technology for voice "
3923 + "capability.");
3924 }
3925 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3926 // There is currently no difference in VT provisioning type.
3927 return ims.isVtProvisionedOnDevice();
3928 }
3929 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3930 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3931 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3932 }
3933 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003934 throw new IllegalArgumentException(
3935 "Tried to get provisioning for MmTel capability '" + capability
3936 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003937 }
3938 }
3939
3940 } finally {
3941 Binder.restoreCallingIdentity(identity);
3942 }
3943 }
3944
3945 @Override
3946 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3947 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3948 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3949 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3950 }
3951 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3952 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3953 return (provisionedBits & capability) > 0;
3954 }
3955
3956 @Override
3957 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3958 boolean isProvisioned) {
3959 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3960 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3961 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3962 }
3963 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3964 "setProvisioningStatusForCapability");
3965 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3966 // If the current provisioning status for capability already matches isProvisioned,
3967 // do nothing.
3968 if (((provisionedBits & capability) > 0) == isProvisioned) {
3969 return;
3970 }
3971 if (isProvisioned) {
3972 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3973 } else {
3974 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3975 }
3976 }
3977
3978 /**
3979 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3980 * technology. The bitfield should mirror the bitfield defined by
3981 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3982 */
3983 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3984 String key = getMmTelProvisioningKey(subId, tech);
3985 // Default is no capabilities are provisioned.
3986 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3987 }
3988
3989 /**
3990 * Sets the MmTel capability provisioning bitfield (defined by
3991 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3992 * technology specified.
3993 *
3994 * Note: This is a synchronous command and should not be called on UI thread.
3995 */
3996 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3997 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3998 String key = getMmTelProvisioningKey(subId, tech);
3999 editor.putInt(key, newField);
4000 editor.commit();
4001 }
4002
4003 private static String getMmTelProvisioningKey(int subId, int tech) {
4004 // resulting key is provision_ims_mmtel_{subId}_{tech}
4005 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4006 }
4007
4008 /**
4009 * Query CarrierConfig to see if the specified capability requires provisioning for the
4010 * carrier associated with the subscription id.
4011 */
4012 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4013 int capability) {
4014 CarrierConfigManager configManager = new CarrierConfigManager(context);
4015 PersistableBundle c = configManager.getConfigForSubId(subId);
4016 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004017 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004018 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4019 false);
4020 boolean requireVoiceVtProvisioning = c.getBoolean(
4021 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4022
4023 // First check to make sure that the capability requires provisioning.
4024 switch (capability) {
4025 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4026 // intentional fallthrough
4027 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4028 if (requireVoiceVtProvisioning) {
4029 // Voice and Video requires provisioning
4030 return true;
4031 }
4032 break;
4033 }
4034 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4035 if (requireUtProvisioning) {
4036 // UT requires provisioning
4037 return true;
4038 }
4039 break;
4040 }
4041 }
4042 return false;
4043 }
4044
allenwtsu99c623b2020-01-03 18:24:23 +08004045 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4046 int capability) {
4047 CarrierConfigManager configManager = new CarrierConfigManager(context);
4048 PersistableBundle c = configManager.getConfigForSubId(subId);
4049
4050 boolean requireRcsProvisioning = c.getBoolean(
4051 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4052
4053 // First check to make sure that the capability requires provisioning.
4054 switch (capability) {
4055 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4056 // intentional fallthrough
4057 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4058 if (requireRcsProvisioning) {
4059 // OPTION or PRESENCE requires provisioning
4060 return true;
4061 }
4062 break;
4063 }
4064 }
4065 return false;
4066 }
4067
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004068 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004069 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004070 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4071 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4072 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004073 enforceReadPrivilegedPermission("getImsProvisioningInt");
4074 final long identity = Binder.clearCallingIdentity();
4075 try {
4076 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004077 int slotId = getSlotIndex(subId);
4078 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4079 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4080 + subId + "' for key:" + key);
4081 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4082 }
4083 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004084 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004085 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4086 + subId + "' for key:" + key);
4087 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004088 } finally {
4089 Binder.restoreCallingIdentity(identity);
4090 }
4091 }
4092
4093 @Override
4094 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004095 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4096 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4097 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004098 enforceReadPrivilegedPermission("getImsProvisioningString");
4099 final long identity = Binder.clearCallingIdentity();
4100 try {
4101 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004102 int slotId = getSlotIndex(subId);
4103 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4104 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4105 + subId + "' for key:" + key);
4106 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4107 }
4108 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004109 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004110 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4111 + subId + "' for key:" + key);
4112 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004113 } finally {
4114 Binder.restoreCallingIdentity(identity);
4115 }
4116 }
4117
4118 @Override
4119 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004120 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4121 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4122 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004123 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4124 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004125 final long identity = Binder.clearCallingIdentity();
4126 try {
4127 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004128 int slotId = getSlotIndex(subId);
4129 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4130 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4131 + subId + "' for key:" + key);
4132 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4133 }
4134 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004135 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004136 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4137 + "' for key:" + key);
4138 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004139 } finally {
4140 Binder.restoreCallingIdentity(identity);
4141 }
4142 }
4143
4144 @Override
4145 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004146 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4147 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4148 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004149 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4150 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004151 final long identity = Binder.clearCallingIdentity();
4152 try {
4153 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004154 int slotId = getSlotIndex(subId);
4155 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4156 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4157 + subId + "' for key:" + key);
4158 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4159 }
4160 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004161 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004162 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4163 + "' for key:" + key);
4164 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004165 } finally {
4166 Binder.restoreCallingIdentity(identity);
4167 }
4168 }
4169
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004170 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004171 int slotId = SubscriptionManager.getSlotIndex(subId);
4172 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004173 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4174 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004175 }
4176 return slotId;
4177 }
4178
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004179 private int getSlotIndex(int subId) {
4180 int slotId = SubscriptionManager.getSlotIndex(subId);
4181 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4182 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4183 }
4184 return slotId;
4185 }
4186
Wink Saville36469e72014-06-11 15:17:00 -07004187 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004188 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004189 */
4190 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004191 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4192 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004193 final int targetSdk = getTargetSdk(callingPackage);
4194 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004195 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004196 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004197 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004198 mApp, subId, callingPackage, callingFeatureId,
4199 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004200 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4201 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004202
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004203 final long identity = Binder.clearCallingIdentity();
4204 try {
4205 final Phone phone = getPhone(subId);
4206 if (phone != null) {
4207 return phone.getServiceState().getDataNetworkType();
4208 } else {
4209 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4210 }
4211 } finally {
4212 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004213 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004214 }
4215
4216 /**
4217 * Returns the data network type
4218 */
4219 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004220 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4221 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4222 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004223 }
4224
4225 /**
4226 * Returns the data network type for a subId
4227 */
4228 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004229 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4230 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004231 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004232 mApp, subId, callingPackage, callingFeatureId,
4233 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004234 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4235 }
4236
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004237 final long identity = Binder.clearCallingIdentity();
4238 try {
4239 final Phone phone = getPhone(subId);
4240 if (phone != null) {
4241 return phone.getServiceState().getDataNetworkType();
4242 } else {
4243 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4244 }
4245 } finally {
4246 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004247 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004248 }
4249
4250 /**
Wink Saville36469e72014-06-11 15:17:00 -07004251 * Returns the Voice network type for a subId
4252 */
4253 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004254 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4255 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004256 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004257 mApp, subId, callingPackage, callingFeatureId,
4258 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004259 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4260 }
4261
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004262 final long identity = Binder.clearCallingIdentity();
4263 try {
4264 final Phone phone = getPhone(subId);
4265 if (phone != null) {
4266 return phone.getServiceState().getVoiceNetworkType();
4267 } else {
4268 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4269 }
4270 } finally {
4271 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004272 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004273 }
4274
4275 /**
4276 * @return true if a ICC card is present
4277 */
4278 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004279 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004280 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4281 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004282 }
4283
4284 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004285 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004286 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004287 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004288 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004289 final long identity = Binder.clearCallingIdentity();
4290 try {
4291 final Phone phone = PhoneFactory.getPhone(slotIndex);
4292 if (phone != null) {
4293 return phone.getIccCard().hasIccCard();
4294 } else {
4295 return false;
4296 }
4297 } finally {
4298 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004299 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004300 }
4301
4302 /**
4303 * Return if the current radio is LTE on CDMA. This
4304 * is a tri-state return value as for a period of time
4305 * the mode may be unknown.
4306 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004307 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004308 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004309 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004310 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004311 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004312 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4313 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4314 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004315 }
4316
Sanket Padawe356d7632015-06-22 14:03:32 -07004317 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004318 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4319 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004320 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004321 mApp, subId, callingPackage, callingFeatureId,
4322 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004323 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4324 }
4325
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004326 final long identity = Binder.clearCallingIdentity();
4327 try {
4328 final Phone phone = getPhone(subId);
4329 if (phone == null) {
4330 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4331 } else {
4332 return phone.getLteOnCdmaMode();
4333 }
4334 } finally {
4335 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004336 }
Wink Saville36469e72014-06-11 15:17:00 -07004337 }
4338
Wink Saville36469e72014-06-11 15:17:00 -07004339 /**
4340 * {@hide}
4341 * Returns Default subId, 0 in the case of single standby.
4342 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004343 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004344 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004345 }
4346
Shishir Agrawala9f32182016-04-12 12:00:16 -07004347 private int getSlotForDefaultSubscription() {
4348 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4349 }
4350
Wink Savilleb564aae2014-10-23 10:18:09 -07004351 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004352 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004353 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004354
Pengquan Menge92a50d2018-09-21 15:54:48 -07004355 private boolean isActiveSubscription(int subId) {
4356 return mSubscriptionController.isActiveSubId(subId);
4357 }
4358
Ihab Awadf2177b72013-11-25 13:33:23 -08004359 /**
4360 * @see android.telephony.TelephonyManager.WifiCallingChoices
4361 */
4362 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004363 final long identity = Binder.clearCallingIdentity();
4364 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004365 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004366 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4367 getWhenToMakeWifiCallsDefaultPreference());
4368 } finally {
4369 Binder.restoreCallingIdentity(identity);
4370 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004371 }
4372
4373 /**
4374 * @see android.telephony.TelephonyManager.WifiCallingChoices
4375 */
4376 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004377 final long identity = Binder.clearCallingIdentity();
4378 try {
4379 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004380 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004381 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4382 } finally {
4383 Binder.restoreCallingIdentity(identity);
4384 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004385 }
4386
Sailesh Nepald1e68152013-12-12 19:08:02 -08004387 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004388 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004389 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004390 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004391
Jordan Liu4c733742019-02-28 12:03:40 -08004392 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4393 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4394 if (phoneId == -1) {
4395 throw new IllegalArgumentException("Given slot index: " + slotIndex
4396 + " does not correspond to an active phone");
4397 }
4398 return PhoneFactory.getPhone(phoneId);
4399 }
4400
Shishir Agrawal566b7612013-10-28 14:41:00 -07004401 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004402 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4403 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004404 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4405 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004406 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004407 if (DBG) {
4408 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4409 }
4410 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4411 p2);
4412 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004413
Jordan Liu4c733742019-02-28 12:03:40 -08004414
4415 @Override
4416 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4417 int slotIndex, String callingPackage, String aid, int p2) {
4418 enforceModifyPermission();
4419 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4420 if (DBG) {
4421 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4422 }
4423 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4424 callingPackage, aid, p2);
4425 }
4426
4427 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4428 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004429 final long identity = Binder.clearCallingIdentity();
4430 try {
4431 if (TextUtils.equals(ISDR_AID, aid)) {
4432 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004433 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4434 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004435 if (bestComponent == null
4436 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4437 loge("The calling package is not allowed to access ISD-R.");
4438 throw new SecurityException(
4439 "The calling package is not allowed to access ISD-R.");
4440 }
Derek Tan740e1672017-06-27 14:56:27 -07004441 }
Derek Tan740e1672017-06-27 14:56:27 -07004442
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004443 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004444 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4445 null /* workSource */);
4446 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004447 return response;
4448 } finally {
4449 Binder.restoreCallingIdentity(identity);
4450 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004451 }
4452
4453 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004454 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4456 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004457 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4458 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4459 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004460
Jordan Liu4c733742019-02-28 12:03:40 -08004461 @Override
4462 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4463 enforceModifyPermission();
4464 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4465 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4466 channel);
4467 }
4468
4469 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004470 final long identity = Binder.clearCallingIdentity();
4471 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004472 if (channel < 0) {
4473 return false;
4474 }
Jordan Liu4c733742019-02-28 12:03:40 -08004475 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4476 null /* workSource */);
4477 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004478 return success;
4479 } finally {
4480 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004481 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004482 }
4483
4484 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004485 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004486 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4488 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004489 if (DBG) {
4490 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4491 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4492 + p3 + " data=" + data);
4493 }
4494 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4495 command, p1, p2, p3, data);
4496 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004497
Jordan Liu4c733742019-02-28 12:03:40 -08004498 @Override
4499 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4500 int command, int p1, int p2, int p3, String data) {
4501 enforceModifyPermission();
4502 if (DBG) {
4503 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4504 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4505 + p3 + " data=" + data);
4506 }
4507 return iccTransmitApduLogicalChannelWithPermission(
4508 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4509 data);
4510 }
4511
4512 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4513 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004514 final long identity = Binder.clearCallingIdentity();
4515 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004516 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004517 return "";
4518 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004519
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004520 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004521 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4522 null /* workSource */);
4523 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004524
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004525 // Append the returned status code to the end of the response payload.
4526 String s = Integer.toHexString(
4527 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4528 if (response.payload != null) {
4529 s = IccUtils.bytesToHexString(response.payload) + s;
4530 }
4531 return s;
4532 } finally {
4533 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004534 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004535 }
Jake Hambye994d462014-02-03 13:10:13 -08004536
Evan Charltonc66da362014-05-16 14:06:40 -07004537 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004538 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4539 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004540 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4541 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004542 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004543 if (DBG) {
4544 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4545 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4546 }
4547 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4548 cla, command, p1, p2, p3, data);
4549 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004550
Jordan Liu4c733742019-02-28 12:03:40 -08004551 @Override
4552 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4553 int command, int p1, int p2, int p3, String data) {
4554 enforceModifyPermission();
4555 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4556 if (DBG) {
4557 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4558 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4559 + " data=" + data);
4560 }
4561
4562 return iccTransmitApduBasicChannelWithPermission(
4563 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4564 p2, p3, data);
4565 }
4566
4567 // open APDU basic channel assuming the caller has sufficient permissions
4568 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4569 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004570 final long identity = Binder.clearCallingIdentity();
4571 try {
4572 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4573 && TextUtils.equals(ISDR_AID, data)) {
4574 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004575 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4576 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004577 if (bestComponent == null
4578 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4579 loge("The calling package is not allowed to select ISD-R.");
4580 throw new SecurityException(
4581 "The calling package is not allowed to select ISD-R.");
4582 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004583 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004584
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004585 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004586 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4587 null /* workSource */);
4588 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004589
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004590 // Append the returned status code to the end of the response payload.
4591 String s = Integer.toHexString(
4592 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4593 if (response.payload != null) {
4594 s = IccUtils.bytesToHexString(response.payload) + s;
4595 }
4596 return s;
4597 } finally {
4598 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004599 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004600 }
4601
4602 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004603 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004604 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4606 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004607
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004608 final long identity = Binder.clearCallingIdentity();
4609 try {
4610 if (DBG) {
4611 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4612 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4613 }
4614
4615 IccIoResult response =
4616 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4617 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4618 subId);
4619
4620 if (DBG) {
4621 log("Exchange SIM_IO [R]" + response);
4622 }
4623
4624 byte[] result = null;
4625 int length = 2;
4626 if (response.payload != null) {
4627 length = 2 + response.payload.length;
4628 result = new byte[length];
4629 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4630 } else {
4631 result = new byte[length];
4632 }
4633
4634 result[length - 1] = (byte) response.sw2;
4635 result[length - 2] = (byte) response.sw1;
4636 return result;
4637 } finally {
4638 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004639 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004640 }
4641
Nathan Haroldb3014052017-01-25 15:57:32 -08004642 /**
4643 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4644 * on a particular subscription
4645 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004646 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4647 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004648 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004649 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004650 return null;
4651 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004652
4653 final long identity = Binder.clearCallingIdentity();
4654 try {
4655 if (appType != TelephonyManager.APPTYPE_USIM
4656 && appType != TelephonyManager.APPTYPE_SIM) {
4657 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4658 return null;
4659 }
4660 Object response = sendRequest(
4661 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4662 if (response instanceof String[]) {
4663 return (String[]) response;
4664 }
yincheng zhaod698b842019-09-06 17:06:54 -07004665 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004666 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004667 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004668 } finally {
4669 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004670 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004671 }
4672
yincheng zhaod698b842019-09-06 17:06:54 -07004673 /**
4674 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4675 * subscription.
4676 *
4677 * @param subId the id of the subscription.
4678 * @param appType the uicc app type, must be USIM or SIM.
4679 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4680 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004681 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004682 * @return number of fplmns that is successfully written to the SIM.
4683 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004684 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4685 String callingFeatureId) {
4686 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4687 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004688 if (DBG) logv("no permissions for setForbiddenplmns");
4689 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4690 }
4691 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4692 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4693 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4694 }
4695 if (fplmns == null) {
4696 throw new IllegalArgumentException("Fplmn List provided is null");
4697 }
4698 for (String fplmn : fplmns) {
4699 if (!CellIdentity.isValidPlmn(fplmn)) {
4700 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4701 }
4702 }
4703 final long identity = Binder.clearCallingIdentity();
4704 try {
4705 Object response = sendRequest(
4706 CMD_SET_FORBIDDEN_PLMNS,
4707 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4708 subId);
4709 return (int) response;
4710 } finally {
4711 Binder.restoreCallingIdentity(identity);
4712 }
4713 }
4714
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004715 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004716 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004717 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4718 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004719
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004720 final long identity = Binder.clearCallingIdentity();
4721 try {
4722 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4723 if (response.payload == null) {
4724 return "";
4725 }
Evan Charltonc66da362014-05-16 14:06:40 -07004726
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004727 // Append the returned status code to the end of the response payload.
4728 String s = Integer.toHexString(
4729 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4730 s = IccUtils.bytesToHexString(response.payload) + s;
4731 return s;
4732 } finally {
4733 Binder.restoreCallingIdentity(identity);
4734 }
Evan Charltonc66da362014-05-16 14:06:40 -07004735 }
4736
Jake Hambye994d462014-02-03 13:10:13 -08004737 /**
4738 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4739 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4740 *
4741 * @param itemID the ID of the item to read
4742 * @return the NV item as a String, or null on error.
4743 */
4744 @Override
4745 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004746 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4748 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004749
4750 final long identity = Binder.clearCallingIdentity();
4751 try {
4752 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004753 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004754 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4755 return value;
4756 } finally {
4757 Binder.restoreCallingIdentity(identity);
4758 }
Jake Hambye994d462014-02-03 13:10:13 -08004759 }
4760
4761 /**
4762 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4763 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4764 *
4765 * @param itemID the ID of the item to read
4766 * @param itemValue the value to write, as a String
4767 * @return true on success; false on any failure
4768 */
4769 @Override
4770 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004771 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4773 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004774
4775 final long identity = Binder.clearCallingIdentity();
4776 try {
4777 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4778 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004779 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004780 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4781 return success;
4782 } finally {
4783 Binder.restoreCallingIdentity(identity);
4784 }
Jake Hambye994d462014-02-03 13:10:13 -08004785 }
4786
4787 /**
4788 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4789 * Used for device configuration by some CDMA operators.
4790 *
4791 * @param preferredRoamingList byte array containing the new PRL
4792 * @return true on success; false on any failure
4793 */
4794 @Override
4795 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004796 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4797 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004798
4799 final long identity = Binder.clearCallingIdentity();
4800 try {
4801 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4802 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4803 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4804 return success;
4805 } finally {
4806 Binder.restoreCallingIdentity(identity);
4807 }
Jake Hambye994d462014-02-03 13:10:13 -08004808 }
4809
4810 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004811 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004812 * Used for device configuration by some CDMA operators.
4813 *
chen xu6dac5ab2018-10-26 17:39:23 -07004814 * @param slotIndex - device slot.
4815 *
Jake Hambye994d462014-02-03 13:10:13 -08004816 * @return true on success; false on any failure
4817 */
4818 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004819 public boolean resetModemConfig(int slotIndex) {
4820 Phone phone = PhoneFactory.getPhone(slotIndex);
4821 if (phone != null) {
4822 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4823 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004824
chen xu6dac5ab2018-10-26 17:39:23 -07004825 final long identity = Binder.clearCallingIdentity();
4826 try {
4827 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4828 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4829 return success;
4830 } finally {
4831 Binder.restoreCallingIdentity(identity);
4832 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004833 }
chen xu6dac5ab2018-10-26 17:39:23 -07004834 return false;
4835 }
4836
4837 /**
4838 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4839 *
4840 * @param slotIndex - device slot.
4841 *
4842 * @return true on success; false on any failure
4843 */
4844 @Override
4845 public boolean rebootModem(int slotIndex) {
4846 Phone phone = PhoneFactory.getPhone(slotIndex);
4847 if (phone != null) {
4848 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4849 mApp, phone.getSubId(), "rebootModem");
4850
4851 final long identity = Binder.clearCallingIdentity();
4852 try {
4853 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4854 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4855 return success;
4856 } finally {
4857 Binder.restoreCallingIdentity(identity);
4858 }
4859 }
4860 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004861 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004862
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004863 public String[] getPcscfAddress(String apnType, String callingPackage,
4864 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004865 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004866 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4867 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004868 return new String[0];
4869 }
4870
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004871 final long identity = Binder.clearCallingIdentity();
4872 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004873 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004874 } finally {
4875 Binder.restoreCallingIdentity(identity);
4876 }
Wink Saville36469e72014-06-11 15:17:00 -07004877 }
4878
Brad Ebinger51f743a2017-01-23 13:50:20 -08004879 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004880 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4881 * {@link #disableIms(int)}.
4882 * @param slotIndex device slot.
4883 */
4884 public void resetIms(int slotIndex) {
4885 enforceModifyPermission();
4886
4887 final long identity = Binder.clearCallingIdentity();
4888 try {
4889 if (mImsResolver == null) {
4890 // may happen if the does not support IMS.
4891 return;
4892 }
4893 mImsResolver.disableIms(slotIndex);
4894 mImsResolver.enableIms(slotIndex);
4895 } finally {
4896 Binder.restoreCallingIdentity(identity);
4897 }
4898 }
4899
4900 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004901 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4902 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004903 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004904 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004905 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004906
4907 final long identity = Binder.clearCallingIdentity();
4908 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004909 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004910 // may happen if the device does not support IMS.
4911 return;
4912 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004913 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004914 } finally {
4915 Binder.restoreCallingIdentity(identity);
4916 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004917 }
4918
4919 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004920 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4921 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004922 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004923 public void disableIms(int slotId) {
4924 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004925
4926 final long identity = Binder.clearCallingIdentity();
4927 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004928 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004929 // may happen if the device does not support IMS.
4930 return;
4931 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004932 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004933 } finally {
4934 Binder.restoreCallingIdentity(identity);
4935 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004936 }
4937
4938 /**
4939 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4940 * feature or {@link null} if the service is not available. If the feature is available, the
4941 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4942 */
4943 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004944 IImsServiceFeatureCallback callback) {
4945 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004946
4947 final long identity = Binder.clearCallingIdentity();
4948 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004949 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004950 // may happen if the device does not support IMS.
4951 return null;
4952 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004953 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004954 } finally {
4955 Binder.restoreCallingIdentity(identity);
4956 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004957 }
4958
4959 /**
4960 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4961 * feature during emergency calling or {@link null} if the service is not available. If the
4962 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4963 * listener for feature updates.
4964 */
4965 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4966 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004967
4968 final long identity = Binder.clearCallingIdentity();
4969 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004970 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004971 // may happen if the device does not support IMS.
4972 return null;
4973 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004974 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004975 } finally {
4976 Binder.restoreCallingIdentity(identity);
4977 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004978 }
4979
Brad Ebinger5f64b052017-12-14 14:26:15 -08004980 /**
4981 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004982 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004983 */
4984 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4985 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004986
4987 final long identity = Binder.clearCallingIdentity();
4988 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004989 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004990 // may happen if the device does not support IMS.
4991 return null;
4992 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004993 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004994 } finally {
4995 Binder.restoreCallingIdentity(identity);
4996 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004997 }
4998
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004999 /**
5000 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005001 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005002 */
5003 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5004 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005005
5006 final long identity = Binder.clearCallingIdentity();
5007 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005008 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005009 // may happen if the device does not support IMS.
5010 return null;
5011 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005012 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005013 } finally {
5014 Binder.restoreCallingIdentity(identity);
5015 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005016 }
5017
Brad Ebinger884c07b2018-02-15 16:17:40 -08005018 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005019 * Sets the ImsService Package Name that Telephony will bind to.
5020 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005021 * @param slotIndex the slot ID that the ImsService should bind for.
5022 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005023 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005024 * @param featureTypes An integer array of feature types associated with a packageName.
5025 * @param packageName The name of the package that the current configuration will be replaced
5026 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005027 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005028 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005029 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5030 int[] featureTypes, String packageName) {
5031 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5032 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005033 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5034 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005035 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005036
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005037 final long identity = Binder.clearCallingIdentity();
5038 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005039 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005040 // may happen if the device does not support IMS.
5041 return false;
5042 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005043 Map<Integer, String> featureConfig = new HashMap<>();
5044 for (int featureType : featureTypes) {
5045 featureConfig.put(featureType, packageName);
5046 }
5047 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5048 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005049 } finally {
5050 Binder.restoreCallingIdentity(identity);
5051 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005052 }
5053
5054 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005055 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005056 *
5057 * @param slotId The slot that the ImsService is associated with.
5058 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5059 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005060 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005061 * @return the package name of the ImsService configuration.
5062 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005063 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5064 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005065 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005066 TelephonyPermissions
5067 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5068 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5069 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005070
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005071 final long identity = Binder.clearCallingIdentity();
5072 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005073 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005074 // may happen if the device does not support IMS.
5075 return "";
5076 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005077 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005078 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5079 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005080 } finally {
5081 Binder.restoreCallingIdentity(identity);
5082 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005083 }
5084
Brad Ebinger77b832e2019-10-17 17:03:22 -07005085 /**
5086 * Get the MmTelFeature state associated with the requested subscription id.
5087 * @param subId The subscription that the MmTelFeature is associated with.
5088 * @param callback A callback with an integer containing the
5089 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5090 */
5091 @Override
5092 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5093 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5094 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5095 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5096 "IMS not available on device.");
5097 }
5098 final long token = Binder.clearCallingIdentity();
5099 try {
5100 int slotId = getSlotIndex(subId);
5101 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5102 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5103 + subId + "'");
5104 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5105 }
5106 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5107 try {
5108 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5109 } catch (RemoteException e) {
5110 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5111 + "Ignore");
5112 }
5113 });
5114 } finally {
5115 Binder.restoreCallingIdentity(token);
5116 }
5117 }
5118
Wink Saville36469e72014-06-11 15:17:00 -07005119 public void setImsRegistrationState(boolean registered) {
5120 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005121
5122 final long identity = Binder.clearCallingIdentity();
5123 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005124 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005125 } finally {
5126 Binder.restoreCallingIdentity(identity);
5127 }
Wink Saville36469e72014-06-11 15:17:00 -07005128 }
5129
5130 /**
Stuart Scott54788802015-03-30 13:18:01 -07005131 * Set the network selection mode to automatic.
5132 *
5133 */
5134 @Override
5135 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005136 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5137 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005138
5139 final long identity = Binder.clearCallingIdentity();
5140 try {
shilufc958392020-01-20 11:36:01 -08005141 if (!isActiveSubscription(subId)) {
5142 return;
5143 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005144 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5145 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5146 } finally {
5147 Binder.restoreCallingIdentity(identity);
5148 }
Stuart Scott54788802015-03-30 13:18:01 -07005149 }
5150
Pengquan Mengea84e042018-09-20 14:57:26 -07005151 /**
5152 * Ask the radio to connect to the input network and change selection mode to manual.
5153 *
5154 * @param subId the id of the subscription.
5155 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5156 * the operator to attach to.
5157 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5158 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5159 * normal network selection next time.
5160 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005161 */
5162 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005163 public boolean setNetworkSelectionModeManual(
5164 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005165 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5166 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005167
5168 if (!isActiveSubscription(subId)) {
5169 return false;
5170 }
5171
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005172 final long identity = Binder.clearCallingIdentity();
5173 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005174 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005175 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005176 if (DBG) {
5177 log("setNetworkSelectionModeManual: subId: " + subId
5178 + " operator: " + operatorInfo);
5179 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005180 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5181 } finally {
5182 Binder.restoreCallingIdentity(identity);
5183 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005184 }
5185
5186 /**
5187 * Scans for available networks.
5188 */
5189 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005190 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5191 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005192 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5193 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005194 LocationAccessPolicy.LocationPermissionResult locationResult =
5195 LocationAccessPolicy.checkLocationPermission(mApp,
5196 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5197 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005198 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005199 .setCallingPid(Binder.getCallingPid())
5200 .setCallingUid(Binder.getCallingUid())
5201 .setMethod("getCellNetworkScanResults")
5202 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5203 .build());
5204 switch (locationResult) {
5205 case DENIED_HARD:
5206 throw new SecurityException("Not allowed to access scan results -- location");
5207 case DENIED_SOFT:
5208 return null;
5209 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005210
Pengquan Menga1bb6272018-09-06 09:59:22 -07005211 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005212 try {
5213 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005214 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005215 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005216 } finally {
5217 Binder.restoreCallingIdentity(identity);
5218 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005219 }
5220
5221 /**
sqian80370722020-01-29 15:02:51 -08005222 * Get the call forwarding info, given the call forwarding reason.
5223 */
5224 @Override
5225 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5226 enforceReadPrivilegedPermission("getCallForwarding");
5227 long identity = Binder.clearCallingIdentity();
5228 try {
5229 if (DBG) {
5230 log("getCallForwarding: subId " + subId
5231 + " callForwardingReason" + callForwardingReason);
5232 }
5233 return (CallForwardingInfo) sendRequest(
5234 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5235 } finally {
5236 Binder.restoreCallingIdentity(identity);
5237 }
5238 }
5239
5240 /**
5241 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5242 * reason, the number to forward, and the timeout before the forwarding is attempted.
5243 */
5244 @Override
5245 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5246 enforceModifyPermission();
5247 long identity = Binder.clearCallingIdentity();
5248 try {
5249 if (DBG) {
5250 log("setCallForwarding: subId " + subId
5251 + " callForwardingInfo" + callForwardingInfo);
5252 }
5253 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5254 } finally {
5255 Binder.restoreCallingIdentity(identity);
5256 }
5257 }
5258
5259 /**
5260 * Get the call forwarding info, given the call forwarding reason.
5261 */
5262 @Override
5263 public int getCallWaitingStatus(int subId) {
5264 enforceReadPrivilegedPermission("getCallForwarding");
5265 long identity = Binder.clearCallingIdentity();
5266 try {
5267 if (DBG) log("getCallWaitingStatus: subId " + subId);
5268 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5269 } finally {
5270 Binder.restoreCallingIdentity(identity);
5271 }
5272 }
5273
5274 /**
5275 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5276 * reason, the number to forward, and the timeout before the forwarding is attempted.
5277 */
5278 @Override
5279 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5280 enforceModifyPermission();
5281 long identity = Binder.clearCallingIdentity();
5282 try {
5283 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5284 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5285 } finally {
5286 Binder.restoreCallingIdentity(identity);
5287 }
5288 }
5289
5290 /**
yinxub1bed742017-04-17 11:45:04 -07005291 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005292 *
yinxub1bed742017-04-17 11:45:04 -07005293 * @param subId id of the subscription
5294 * @param request contains the radio access networks with bands/channels to scan
5295 * @param messenger callback messenger for scan results or errors
5296 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005297 * @return the id of the requested scan which can be used to stop the scan.
5298 */
5299 @Override
5300 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005301 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5303 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005304 LocationAccessPolicy.LocationPermissionResult locationResult =
5305 LocationAccessPolicy.checkLocationPermission(mApp,
5306 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5307 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005308 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005309 .setCallingPid(Binder.getCallingPid())
5310 .setCallingUid(Binder.getCallingUid())
5311 .setMethod("requestNetworkScan")
5312 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5313 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005314 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005315 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005316 if (e != null) {
5317 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5318 throw e;
5319 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005320 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005321 return TelephonyScanManager.INVALID_SCAN_ID;
5322 }
5323 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005324 }
Hall Liu912dfd32019-04-25 14:02:26 -07005325 int callingUid = Binder.getCallingUid();
5326 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005327 final long identity = Binder.clearCallingIdentity();
5328 try {
5329 return mNetworkScanRequestTracker.startNetworkScan(
5330 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005331 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005332 } finally {
5333 Binder.restoreCallingIdentity(identity);
5334 }
yinxu504e1392017-04-12 16:03:22 -07005335 }
5336
Hall Liub2ac8ef2019-02-28 15:56:23 -08005337 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005338 NetworkScanRequest request, int subId) {
5339 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5340 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5341 boolean hasNetworkScanPermission =
5342 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5343 == PERMISSION_GRANTED;
5344
5345 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5346 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5347 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005348 }
5349
5350 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5351 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005352 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5353 return new SecurityException("Specific channels must not be"
5354 + " scanned without location access.");
5355 }
5356 }
5357 }
5358
Hall Liub2ac8ef2019-02-28 15:56:23 -08005359 return null;
5360 }
5361
yinxu504e1392017-04-12 16:03:22 -07005362 /**
5363 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005364 *
5365 * @param subId id of the subscription
5366 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005367 */
5368 @Override
5369 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005370 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5371 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005372
Hall Liu912dfd32019-04-25 14:02:26 -07005373 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005374 final long identity = Binder.clearCallingIdentity();
5375 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005376 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005377 } finally {
5378 Binder.restoreCallingIdentity(identity);
5379 }
yinxu504e1392017-04-12 16:03:22 -07005380 }
5381
5382 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005383 * Get the calculated preferred network type.
5384 * Used for debugging incorrect network type.
5385 *
5386 * @return the preferred network type, defined in RILConstants.java.
5387 */
5388 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005389 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005390 final Phone defaultPhone = getDefaultPhone();
5391 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005392 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005393 return RILConstants.PREFERRED_NETWORK_MODE;
5394 }
5395
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005396 final long identity = Binder.clearCallingIdentity();
5397 try {
5398 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005399 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005400 } finally {
5401 Binder.restoreCallingIdentity(identity);
5402 }
Junda Liu84d15a22014-07-02 11:21:04 -07005403 }
5404
5405 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005406 * Get the preferred network type.
5407 * Used for device configuration by some CDMA operators.
5408 *
5409 * @return the preferred network type, defined in RILConstants.java.
5410 */
5411 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005412 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005413 TelephonyPermissions
5414 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5415 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005416
5417 final long identity = Binder.clearCallingIdentity();
5418 try {
5419 if (DBG) log("getPreferredNetworkType");
5420 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5421 int networkType = (result != null ? result[0] : -1);
5422 if (DBG) log("getPreferredNetworkType: " + networkType);
5423 return networkType;
5424 } finally {
5425 Binder.restoreCallingIdentity(identity);
5426 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005427 }
5428
5429 /**
5430 * Set the preferred network type.
5431 * Used for device configuration by some CDMA operators.
5432 *
5433 * @param networkType the preferred network type, defined in RILConstants.java.
5434 * @return true on success; false on any failure.
5435 */
5436 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005437 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005438 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5439 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005440
5441 final long identity = Binder.clearCallingIdentity();
5442 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005443 Settings.Global.putInt(mApp.getContentResolver(),
5444 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5445 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005446 } finally {
5447 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005448 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005449 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005450
5451 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005452 * Get the allowed network types that store in the telephony provider.
5453 *
5454 * @param subId the id of the subscription.
5455 * @return allowedNetworkTypes the allowed network types.
5456 */
5457 @Override
5458 public long getAllowedNetworkTypes(int subId) {
5459 TelephonyPermissions
5460 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5461 mApp, subId, "getAllowedNetworkTypes");
5462
5463 final long identity = Binder.clearCallingIdentity();
5464 try {
5465 return SubscriptionManager.getLongSubscriptionProperty(
5466 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5467 } finally {
5468 Binder.restoreCallingIdentity(identity);
5469 }
5470 }
5471
5472 /**
5473 * Set the allowed network types.
5474 *
5475 * @param subId the id of the subscription.
5476 * @param allowedNetworkTypes the allowed network types.
5477 * @return true on success; false on any failure.
5478 */
5479 @Override
5480 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5481 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5482 mApp, subId, "setAllowedNetworkTypes");
5483 final long identity = Binder.clearCallingIdentity();
5484 try {
5485 SubscriptionManager.setSubscriptionProperty(subId,
5486 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5487 String.valueOf(allowedNetworkTypes));
5488 return setPreferredNetworkTypesInternal(subId);
5489 } finally {
5490 Binder.restoreCallingIdentity(identity);
5491 }
5492 }
5493
5494 private boolean setPreferredNetworkTypesInternal(int subId) {
5495 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5496 Settings.Global.getInt(mApp.getContentResolver(),
5497 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5498 RILConstants.PREFERRED_NETWORK_MODE));
5499 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5500 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5501 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5502 (int) (networkTypeBitMask & allowedNetworkTypes));
5503
5504 if (DBG) {
5505 log("setPreferredNetworkTypesInternal: subId " + subId
5506 + " networkTypes " + networkTypeBitMask
5507 + " allowedNetworkTypes " + allowedNetworkTypes
5508 + " networkMode " + networkMode);
5509 }
5510
5511 Boolean success = (Boolean) sendRequest(
5512 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5513 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5514 return success;
5515 }
5516
5517 /**
Miaoa84611c2019-03-15 09:21:10 +08005518 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005519 *
Miaoa84611c2019-03-15 09:21:10 +08005520 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005521 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005522 * @hide
5523 */
5524 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005525 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005526 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005527 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005528 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005529 try {
Miaoa84611c2019-03-15 09:21:10 +08005530 if (phone != null) {
5531 return phone.hasMatchedTetherApnSetting();
5532 } else {
5533 return false;
5534 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005535 } finally {
5536 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005537 }
Junda Liu475951f2014-11-07 16:45:03 -08005538 }
5539
5540 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005541 * Set mobile data enabled
5542 * Used by the user through settings etc to turn on/off mobile data
5543 *
5544 * @param enable {@code true} turn turn data on, else {@code false}
5545 */
5546 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005547 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005548 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5549 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005550
5551 final long identity = Binder.clearCallingIdentity();
5552 try {
5553 int phoneId = mSubscriptionController.getPhoneId(subId);
5554 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5555 Phone phone = PhoneFactory.getPhone(phoneId);
5556 if (phone != null) {
5557 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005558 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005559 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005560 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005561 }
5562 } finally {
5563 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005564 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005565 }
5566
5567 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005568 * Enable or disable always reporting signal strength changes from radio.
5569 *
5570 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5571 */
5572 @Override
5573 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5574 enforceModifyPermission();
5575 enforceSystemCaller();
5576
5577 final long identity = Binder.clearCallingIdentity();
5578 final Phone phone = getPhone(subId);
5579 try {
5580 if (phone != null) {
5581 if (DBG) {
5582 log("setAlwaysReportSignalStrength: subId=" + subId
5583 + " isEnable=" + isEnable);
5584 }
5585 phone.setAlwaysReportSignalStrength(isEnable);
5586 } else {
5587 loge("setAlwaysReportSignalStrength: no phone found for subId="
5588 + subId);
5589 }
5590 } finally {
5591 Binder.restoreCallingIdentity(identity);
5592 }
5593 }
5594
5595 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005596 * Get the user enabled state of Mobile Data.
5597 *
5598 * TODO: remove and use isUserDataEnabled.
5599 * This can't be removed now because some vendor codes
5600 * calls through ITelephony directly while they should
5601 * use TelephonyManager.
5602 *
5603 * @return true on enabled
5604 */
5605 @Override
5606 public boolean getDataEnabled(int subId) {
5607 return isUserDataEnabled(subId);
5608 }
5609
5610 /**
5611 * Get whether mobile data is enabled per user setting.
5612 *
5613 * There are other factors deciding whether mobile data is actually enabled, but they are
5614 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005615 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005616 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005617 *
5618 * @return {@code true} if data is enabled else {@code false}
5619 */
5620 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005621 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005622 try {
5623 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5624 null);
5625 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005626 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5627 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005629
5630 final long identity = Binder.clearCallingIdentity();
5631 try {
5632 int phoneId = mSubscriptionController.getPhoneId(subId);
5633 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5634 Phone phone = PhoneFactory.getPhone(phoneId);
5635 if (phone != null) {
5636 boolean retVal = phone.isUserDataEnabled();
5637 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5638 return retVal;
5639 } else {
5640 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5641 return false;
5642 }
5643 } finally {
5644 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005645 }
5646 }
5647
5648 /**
Shuo Qian985d1232020-01-08 14:30:06 -08005649 * Checks if the device is capable of mobile data by considering whether whether the
5650 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5651 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005652 *
Shuo Qian985d1232020-01-08 14:30:06 -08005653 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005654 */
5655 @Override
5656 public boolean isDataEnabled(int subId) {
Shuo Qian985d1232020-01-08 14:30:06 -08005657 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005658
5659 final long identity = Binder.clearCallingIdentity();
5660 try {
5661 int phoneId = mSubscriptionController.getPhoneId(subId);
5662 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5663 Phone phone = PhoneFactory.getPhone(phoneId);
5664 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005665 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005666 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5667 return retVal;
5668 } else {
5669 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5670 return false;
5671 }
5672 } finally {
5673 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005674 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005675 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005676
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005677 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5678 Phone phone) {
5679 //load access rules from carrier configs, and check those as well: b/139133814
5680 SubscriptionController subController = SubscriptionController.getInstance();
5681 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5682 || subController == null) return privilegeFromSim;
5683
5684 int uid = Binder.getCallingUid();
5685 PackageManager pkgMgr = phone.getContext().getPackageManager();
5686 String[] packages = pkgMgr.getPackagesForUid(uid);
5687
5688 final long identity = Binder.clearCallingIdentity();
5689 try {
5690 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5691 SubscriptionManager subManager = (SubscriptionManager)
5692 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5693 for (String pkg : packages) {
5694 if (subManager.canManageSubscription(subInfo, pkg)) {
5695 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5696 }
5697 }
5698 return privilegeFromSim;
5699 } finally {
5700 Binder.restoreCallingIdentity(identity);
5701 }
5702 }
5703
5704 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5705 String pkgName) {
5706 //load access rules from carrier configs, and check those as well: b/139133814
5707 SubscriptionController subController = SubscriptionController.getInstance();
5708 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5709 || subController == null) return privilegeFromSim;
5710
5711 final long identity = Binder.clearCallingIdentity();
5712 try {
5713 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5714 SubscriptionManager subManager = (SubscriptionManager)
5715 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5716 return subManager.canManageSubscription(subInfo, pkgName)
5717 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5718 } finally {
5719 Binder.restoreCallingIdentity(identity);
5720 }
5721 }
5722
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005723 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005724 public int getCarrierPrivilegeStatus(int subId) {
5725 final Phone phone = getPhone(subId);
5726 if (phone == null) {
5727 loge("getCarrierPrivilegeStatus: Invalid subId");
5728 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5729 }
5730 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005731 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005732 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005733 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5734 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005735
5736 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5737 card.getCarrierPrivilegeStatusForCurrentTransaction(
5738 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005739 }
Junda Liu29340342014-07-10 15:23:27 -07005740
5741 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005742 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005743 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005744 final Phone phone = getPhone(subId);
5745 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005746 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005747 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5748 }
5749 UiccProfile profile =
5750 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5751 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005752 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005753 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5754 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005755 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005756 profile.getCarrierPrivilegeStatusForUid(
5757 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005758 }
5759
5760 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005761 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5762 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005763 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005764 }
5765
5766 int phoneId = SubscriptionManager.getPhoneId(subId);
5767 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005768 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005769 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005770 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5771 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005772 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5773 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5774 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005775 }
5776
5777 @Override
5778 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005779 if (TextUtils.isEmpty(pkgName))
5780 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005781 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5782 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5783 UiccCard card = UiccController.getInstance().getUiccCard(i);
5784 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005785 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005786 continue;
5787 }
5788
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005789 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5790 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5791 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005792 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5793 break;
5794 }
5795 }
5796
5797 return result;
Junda Liu29340342014-07-10 15:23:27 -07005798 }
Derek Tan89e89d42014-07-08 17:00:10 -07005799
5800 @Override
Junda Liue64de782015-04-16 17:19:16 -07005801 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5802 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5803 loge("phoneId " + phoneId + " is not valid.");
5804 return null;
5805 }
5806 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005807 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005808 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005809 return null ;
5810 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005811 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005812 }
5813
Amith Yamasani6e118872016-02-19 12:53:51 -08005814 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005815 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005816 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005817 List<String> privilegedPackages = new ArrayList<>();
5818 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005819 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5820 // has UICC in that slot.
5821 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005822 if (card.hasCarrierPrivilegeRules()) {
5823 if (packages == null) {
5824 // Only check packages in user 0 for now
5825 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005826 PackageManager.MATCH_DISABLED_COMPONENTS
5827 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005828 | PackageManager.GET_SIGNING_CERTIFICATES,
5829 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005830 }
5831 for (int p = packages.size() - 1; p >= 0; p--) {
5832 PackageInfo pkgInfo = packages.get(p);
5833 if (pkgInfo != null && pkgInfo.packageName != null
5834 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005835 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005836 privilegedPackages.add(pkgInfo.packageName);
5837 }
5838 }
5839 }
5840 }
5841 return privilegedPackages;
5842 }
5843
chen xuf7e9fe82019-05-09 19:31:02 -07005844 @Override
5845 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005846 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5847
5848 final long identity = Binder.clearCallingIdentity();
5849
chen xuf7e9fe82019-05-09 19:31:02 -07005850 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005851 try {
5852 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5853 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5854 }
5855 } finally {
5856 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005857 }
5858 return privilegedPackages;
5859 }
5860
Wink Savilleb564aae2014-10-23 10:18:09 -07005861 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005862 final Phone phone = getPhone(subId);
5863 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005864 if (card == null) {
5865 loge("getIccId: No UICC");
5866 return null;
5867 }
5868 String iccId = card.getIccId();
5869 if (TextUtils.isEmpty(iccId)) {
5870 loge("getIccId: ICC ID is null or empty.");
5871 return null;
5872 }
5873 return iccId;
5874 }
5875
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005876 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005877 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5878 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08005879 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005880 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005881
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882 final long identity = Binder.clearCallingIdentity();
5883 try {
5884 final String iccId = getIccId(subId);
5885 final Phone phone = getPhone(subId);
5886 if (phone == null) {
5887 return false;
5888 }
5889 final String subscriberId = phone.getSubscriberId();
5890
5891 if (DBG_MERGE) {
5892 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5893 + subscriberId + " to " + number);
5894 }
5895
5896 if (TextUtils.isEmpty(iccId)) {
5897 return false;
5898 }
5899
5900 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5901
5902 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5903 if (alphaTag == null) {
5904 editor.remove(alphaTagPrefKey);
5905 } else {
5906 editor.putString(alphaTagPrefKey, alphaTag);
5907 }
5908
5909 // Record both the line number and IMSI for this ICCID, since we need to
5910 // track all merged IMSIs based on line number
5911 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5912 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5913 if (number == null) {
5914 editor.remove(numberPrefKey);
5915 editor.remove(subscriberPrefKey);
5916 } else {
5917 editor.putString(numberPrefKey, number);
5918 editor.putString(subscriberPrefKey, subscriberId);
5919 }
5920
5921 editor.commit();
5922 return true;
5923 } finally {
5924 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005925 }
Derek Tan7226c842014-07-02 17:42:23 -07005926 }
5927
5928 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005929 public String getLine1NumberForDisplay(int subId, String callingPackage,
5930 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005931 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005932 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005933 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005934 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005935 return null;
5936 }
Derek Tan97ebb422014-09-05 16:55:38 -07005937
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005938 final long identity = Binder.clearCallingIdentity();
5939 try {
5940 String iccId = getIccId(subId);
5941 if (iccId != null) {
5942 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5943 if (DBG_MERGE) {
5944 log("getLine1NumberForDisplay returning "
5945 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5946 }
5947 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005948 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005949 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5950 return null;
5951 } finally {
5952 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005953 }
Derek Tan7226c842014-07-02 17:42:23 -07005954 }
5955
5956 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005957 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5958 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005959 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005960 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005961 return null;
5962 }
Derek Tan97ebb422014-09-05 16:55:38 -07005963
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005964 final long identity = Binder.clearCallingIdentity();
5965 try {
5966 String iccId = getIccId(subId);
5967 if (iccId != null) {
5968 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5969 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5970 }
5971 return null;
5972 } finally {
5973 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005974 }
Derek Tan7226c842014-07-02 17:42:23 -07005975 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005976
5977 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005978 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5979 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005980 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5981 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005982 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005983 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005984 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005985 return null;
5986 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005987
Jordan Liub49b04b2019-05-06 14:45:15 -07005988 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5989 // the process, where TelephonyManager was instantiated.
5990 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005991 final long identity = Binder.clearCallingIdentity();
5992 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005993 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005994 final TelephonyManager tele = TelephonyManager.from(context);
5995 final SubscriptionManager sub = SubscriptionManager.from(context);
5996
5997 // Figure out what subscribers are currently active
5998 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005999
Jordan Liub49b04b2019-05-06 14:45:15 -07006000 // Only consider subs which match the current subId
6001 // This logic can be simplified. See b/131189269 for progress.
6002 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006003 activeSubscriberIds.add(tele.getSubscriberId(subId));
6004 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006005
6006 // First pass, find a number override for an active subscriber
6007 String mergeNumber = null;
6008 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6009 for (String key : prefs.keySet()) {
6010 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6011 final String subscriberId = (String) prefs.get(key);
6012 if (activeSubscriberIds.contains(subscriberId)) {
6013 final String iccId = key.substring(
6014 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6015 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6016 mergeNumber = (String) prefs.get(numberKey);
6017 if (DBG_MERGE) {
6018 Slog.d(LOG_TAG, "Found line number " + mergeNumber
6019 + " for active subscriber " + subscriberId);
6020 }
6021 if (!TextUtils.isEmpty(mergeNumber)) {
6022 break;
6023 }
6024 }
6025 }
6026 }
6027
6028 // Shortcut when no active merged subscribers
6029 if (TextUtils.isEmpty(mergeNumber)) {
6030 return null;
6031 }
6032
6033 // Second pass, find all subscribers under that line override
6034 final ArraySet<String> result = new ArraySet<>();
6035 for (String key : prefs.keySet()) {
6036 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6037 final String number = (String) prefs.get(key);
6038 if (mergeNumber.equals(number)) {
6039 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6040 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6041 final String subscriberId = (String) prefs.get(subscriberKey);
6042 if (!TextUtils.isEmpty(subscriberId)) {
6043 result.add(subscriberId);
6044 }
6045 }
6046 }
6047 }
6048
6049 final String[] resultArray = result.toArray(new String[result.size()]);
6050 Arrays.sort(resultArray);
6051 if (DBG_MERGE) {
6052 Slog.d(LOG_TAG,
6053 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6054 }
6055 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006056 } finally {
6057 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006058 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006059 }
6060
6061 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07006062 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
6063 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
6064
6065 final long identity = Binder.clearCallingIdentity();
6066 try {
6067 final TelephonyManager telephonyManager = mApp.getSystemService(
6068 TelephonyManager.class);
6069 String subscriberId = telephonyManager.getSubscriberId(subId);
6070 if (subscriberId == null) {
6071 if (DBG) {
6072 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
6073 + subId);
6074 }
6075 return null;
6076 }
6077
6078 final SubscriptionInfo info = SubscriptionController.getInstance()
6079 .getSubscriptionInfo(subId);
6080 final ParcelUuid groupUuid = info.getGroupUuid();
6081 // If it doesn't belong to any group, return just subscriberId of itself.
6082 if (groupUuid == null) {
6083 return new String[]{subscriberId};
6084 }
6085
6086 // Get all subscriberIds from the group.
6087 final List<String> mergedSubscriberIds = new ArrayList<>();
6088 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006089 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
6090 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07006091 for (SubscriptionInfo subInfo : groupInfos) {
6092 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6093 if (subscriberId != null) {
6094 mergedSubscriberIds.add(subscriberId);
6095 }
6096 }
6097
6098 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6099 } finally {
6100 Binder.restoreCallingIdentity(identity);
6101
6102 }
6103 }
6104
6105 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006106 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006107 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006108 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006109
6110 final long identity = Binder.clearCallingIdentity();
6111 try {
6112 final Phone phone = getPhone(subId);
6113 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6114 } finally {
6115 Binder.restoreCallingIdentity(identity);
6116 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006117 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006118
6119 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006120 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006121 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6122 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006123 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6124 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006125
6126 final long identity = Binder.clearCallingIdentity();
6127 try {
6128 final Phone phone = getPhone(subId);
6129 if (phone == null) {
6130 return false;
6131 }
6132 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6133 cdmaNonRoamingList);
6134 } finally {
6135 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006136 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006137 }
6138
6139 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006140 @Deprecated
6141 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6142 enforceModifyPermission();
6143
6144 int returnValue = 0;
6145 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006146 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006147 if(result.exception == null) {
6148 if (result.result != null) {
6149 byte[] responseData = (byte[])(result.result);
6150 if(responseData.length > oemResp.length) {
6151 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6152 responseData.length + "bytes. Buffer Size is " +
6153 oemResp.length + "bytes.");
6154 }
6155 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6156 returnValue = responseData.length;
6157 }
6158 } else {
6159 CommandException ex = (CommandException) result.exception;
6160 returnValue = ex.getCommandError().ordinal();
6161 if(returnValue > 0) returnValue *= -1;
6162 }
6163 } catch (RuntimeException e) {
6164 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6165 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6166 if(returnValue > 0) returnValue *= -1;
6167 }
6168
6169 return returnValue;
6170 }
6171
6172 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006173 public void setRadioCapability(RadioAccessFamily[] rafs) {
6174 try {
6175 ProxyController.getInstance().setRadioCapability(rafs);
6176 } catch (RuntimeException e) {
6177 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6178 }
6179 }
6180
6181 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006182 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006183 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006184 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006185 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006186 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006187 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006188 final long identity = Binder.clearCallingIdentity();
6189 try {
chen xub97461a2018-10-26 14:17:57 -07006190 TelephonyPermissions
6191 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6192 mApp, phone.getSubId(), "getRadioAccessFamily");
6193 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006194 } finally {
6195 Binder.restoreCallingIdentity(identity);
6196 }
chen xub97461a2018-10-26 14:17:57 -07006197 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006198 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006199
6200 @Override
6201 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006202 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006203 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006204
6205 final long identity = Binder.clearCallingIdentity();
6206 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006207 ImsManager.getInstance(defaultPhone.getContext(),
6208 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006209 } finally {
6210 Binder.restoreCallingIdentity(identity);
6211 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006212 }
6213
6214 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006215 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006216 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006217 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6218 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006219 return false;
6220 }
Svet Ganovb320e182015-04-16 12:30:10 -07006221
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006222 final long identity = Binder.clearCallingIdentity();
6223 try {
6224 // Check the user preference and the system-level IMS setting. Even if the user has
6225 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6226 // In the long run, we may instead need to check if there exists a connection service
6227 // which can support video calling.
6228 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006229 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006230 return imsManager.isVtEnabledByPlatform()
6231 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6232 && imsManager.isVtEnabledByUser();
6233 } finally {
6234 Binder.restoreCallingIdentity(identity);
6235 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006236 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006237
Andrew Leea1239f22015-03-02 17:44:07 -08006238 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006239 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6240 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006241 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006242 mApp, subId, callingPackage, callingFeatureId,
6243 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006244 return false;
6245 }
6246
6247 final long identity = Binder.clearCallingIdentity();
6248 try {
6249 CarrierConfigManager configManager =
6250 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006251 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006252 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6253 } finally {
6254 Binder.restoreCallingIdentity(identity);
6255 }
Andrew Leea1239f22015-03-02 17:44:07 -08006256 }
6257
6258 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006259 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006260 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006261 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006262 return false;
6263 }
6264
6265 final long identity = Binder.clearCallingIdentity();
6266 try {
6267 CarrierConfigManager configManager =
6268 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006269 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006270 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6271 } finally {
6272 Binder.restoreCallingIdentity(identity);
6273 }
Andrew Leea1239f22015-03-02 17:44:07 -08006274 }
6275
Andrew Lee9431b832015-03-09 18:46:45 -07006276 @Override
6277 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006278 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006279 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006280 }
6281
6282 @Override
6283 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006284 final long identity = Binder.clearCallingIdentity();
6285 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006286 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006287 } finally {
6288 Binder.restoreCallingIdentity(identity);
6289 }
Andrew Lee9431b832015-03-09 18:46:45 -07006290 }
6291
Hall Liuf6668912018-10-31 17:05:23 -07006292 /**
6293 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6294 * support for the feature and device firmware support.
6295 *
6296 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6297 */
6298 @Override
6299 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006300 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006301 final Phone phone = getPhone(subscriptionId);
6302 if (phone == null) {
6303 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6304 return false;
6305 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006306 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006307 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006308 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6309 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006310 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006311 return isCarrierSupported && isDeviceSupported;
6312 } finally {
6313 Binder.restoreCallingIdentity(identity);
6314 }
Hall Liu98187582018-01-22 19:15:32 -08006315 }
6316
Hall Liuf6668912018-10-31 17:05:23 -07006317 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006318 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6319 * RTT setting, will return true if the device and carrier both support RTT.
6320 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006321 */
6322 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006323 final long identity = Binder.clearCallingIdentity();
6324 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006325 boolean isRttSupported = isRttSupported(subscriptionId);
6326 boolean isUserRttSettingOn = Settings.Secure.getInt(
6327 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6328 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6329 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6330 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006331 } finally {
6332 Binder.restoreCallingIdentity(identity);
6333 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006334 }
6335
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006336 @Deprecated
6337 @Override
6338 public String getDeviceId(String callingPackage) {
6339 return getDeviceIdWithFeature(callingPackage, null);
6340 }
6341
Sanket Padawe7310cc72015-01-14 09:53:20 -08006342 /**
6343 * Returns the unique device ID of phone, for example, the IMEI for
6344 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6345 *
6346 * <p>Requires Permission:
6347 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6348 */
6349 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006350 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006351 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006352 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006353 return null;
6354 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006355 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006356 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006357 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006358 return null;
6359 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006360
6361 final long identity = Binder.clearCallingIdentity();
6362 try {
6363 return phone.getDeviceId();
6364 } finally {
6365 Binder.restoreCallingIdentity(identity);
6366 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006367 }
6368
Ping Sunc67b7c22016-03-02 19:16:45 +08006369 /**
6370 * {@hide}
6371 * Returns the IMS Registration Status on a particular subid
6372 *
6373 * @param subId
6374 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006375 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006376 Phone phone = getPhone(subId);
6377 if (phone != null) {
6378 return phone.isImsRegistered();
6379 } else {
6380 return false;
6381 }
6382 }
6383
Santos Cordon7a1885b2015-02-03 11:15:19 -08006384 @Override
6385 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006386 final long identity = Binder.clearCallingIdentity();
6387 try {
6388 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6389 } finally {
6390 Binder.restoreCallingIdentity(identity);
6391 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006392 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006393
Tyler Gunnf70ed162019-04-03 15:28:53 -07006394 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006395 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006396 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006397 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006398 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006399 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6400 }
6401 final long identity = Binder.clearCallingIdentity();
6402 try {
6403 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6404 } finally {
6405 Binder.restoreCallingIdentity(identity);
6406 }
6407 }
6408
6409 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006410 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6411 final long identity = Binder.clearCallingIdentity();
6412 try {
6413 Phone phone = getPhone(subscriptionId);
6414 if (phone == null) {
6415 return null;
6416 }
6417 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6418 } finally {
6419 Binder.restoreCallingIdentity(identity);
6420 }
6421 }
6422
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006423 /**
6424 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006425 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006426 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006427 final long identity = Binder.clearCallingIdentity();
6428 try {
6429 Phone phone = getPhone(subId);
6430 if (phone != null) {
6431 return phone.isWifiCallingEnabled();
6432 } else {
6433 return false;
6434 }
6435 } finally {
6436 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006437 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006438 }
6439
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006440 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006441 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006442 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006443 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006444 final long identity = Binder.clearCallingIdentity();
6445 try {
6446 Phone phone = getPhone(subId);
6447 if (phone != null) {
6448 return phone.isVideoEnabled();
6449 } else {
6450 return false;
6451 }
6452 } finally {
6453 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006454 }
6455 }
6456
6457 /**
6458 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6459 * defined in {@link ImsRegistrationImplBase}.
6460 */
6461 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006462 final long identity = Binder.clearCallingIdentity();
6463 try {
6464 Phone phone = getPhone(subId);
6465 if (phone != null) {
6466 return phone.getImsRegistrationTech();
6467 } else {
6468 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6469 }
6470 } finally {
6471 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006472 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006473 }
6474
Stuart Scott8eef64f2015-04-08 15:13:54 -07006475 @Override
6476 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006477 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006478 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6479 return;
6480 }
6481
Svet Ganovcc087f82015-05-12 20:35:54 -07006482 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006483
Svet Ganovcc087f82015-05-12 20:35:54 -07006484 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006485 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6486 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006487 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006488 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006489 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006490 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6491 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006492 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006493 // There has been issues when Sms raw table somehow stores orphan
6494 // fragments. They lead to garbled message when new fragments come
6495 // in and combined with those stale ones. In case this happens again,
6496 // user can reset all network settings which will clean up this table.
6497 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006498 // Clean up IMS settings as well here.
6499 int slotId = getSlotIndex(subId);
6500 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6501 ImsManager.getInstance(mApp, slotId).factoryReset();
6502 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006503
6504 // Erase modem config if erase modem on network setting is enabled.
6505 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6506 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6507 if (configValue != null && Boolean.parseBoolean(configValue)) {
6508 sendEraseModemConfig(getDefaultPhone());
6509 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006510 } finally {
6511 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006512 }
6513 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006514
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006515 private void cleanUpSmsRawTable(Context context) {
6516 ContentResolver resolver = context.getContentResolver();
6517 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6518 resolver.delete(uri, null, null);
6519 }
6520
Narayan Kamath1c496c22015-04-16 14:40:19 +01006521 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006522 public String getSimLocaleForSubscriber(int subId) {
6523 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6524 final Phone phone = getPhone(subId);
6525 if (phone == null) {
6526 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006527 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006528 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006529 final long identity = Binder.clearCallingIdentity();
6530 try {
chen xu5d3637b2019-01-21 23:31:38 -08006531 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006532 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08006533 if (info == null) {
6534 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6535 return null;
6536 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006537 // Try and fetch the locale from the carrier properties or from the SIM language
6538 // preferences (EF-PL and EF-LI)...
6539 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006540 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006541 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6542 if (localeFromDefaultSim != null) {
6543 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6544 if (DBG) log("Using locale from subId: " + subId + " locale: "
6545 + localeFromDefaultSim);
6546 return localeFromDefaultSim.toLanguageTag();
6547 } else {
6548 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006549 }
6550 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006551
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006552 // The SIM language preferences only store a language (e.g. fr = French), not an
6553 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6554 // the SIM and carrier preferences does not include a country we add the country
6555 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006556 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006557 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006558 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006559 return mccLocale.toLanguageTag();
6560 }
6561
6562 if (DBG) log("No locale found - returning null");
6563 return null;
6564 } finally {
6565 Binder.restoreCallingIdentity(identity);
6566 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006567 }
6568
6569 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006570 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6571 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006572 }
6573
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006574 /**
6575 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6576 */
6577 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006578 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6579 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006580 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006581
Chenjie Yu1ba97252018-01-11 18:16:20 -08006582 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006583 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006584
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006585 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006586 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6587 * representing the state of the modem.
6588 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006589 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6590 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006591 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006592 */
6593 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006594 public void requestModemActivityInfo(ResultReceiver result) {
6595 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006596 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006597
6598 final long identity = Binder.clearCallingIdentity();
6599 try {
6600 ModemActivityInfo ret = null;
6601 synchronized (mLastModemActivityInfo) {
6602 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6603 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006604 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006605 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006606 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xu13851032019-09-10 18:49:52 -07006607 int[] txTimeMs = info.getTransmitTimeMillis();
6608 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006609 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xu13851032019-09-10 18:49:52 -07006610 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006611 }
6612 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006613 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6614 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006615 mLastModemActivityInfo.setIdleTimeMillis(
6616 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xu13851032019-09-10 18:49:52 -07006617 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6618 mLastModemActivityInfo.setReceiveTimeMillis(
6619 info.getReceiveTimeMillis() + mLastModemActivityInfo
6620 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006621 }
Chen Xu13851032019-09-10 18:49:52 -07006622
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006623 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6624 mLastModemActivityInfo.getSleepTimeMillis(),
6625 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xu13851032019-09-10 18:49:52 -07006626 mLastModemActivityInfo.getTransmitTimeMillis(),
6627 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006629 Bundle bundle = new Bundle();
6630 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6631 result.send(0, bundle);
6632 } finally {
6633 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006634 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006635 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006636
Siddharth Rayb8114062018-06-17 15:02:38 -07006637 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6638 // less than total activity duration.
6639 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6640 if (info == null) {
6641 return false;
6642 }
6643 int activityDurationMs =
6644 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6645 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006646 int[] txTimeMs = info.getTransmitTimeMillis();
6647 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6648 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006649 }
6650 return (info.isValid()
6651 && (info.getSleepTimeMillis() <= activityDurationMs)
6652 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006653 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006654 && (totalTxTimeMs <= activityDurationMs));
6655 }
6656
Jack Yu85bd38a2015-11-09 11:34:32 -08006657 /**
6658 * {@hide}
6659 * Returns the service state information on specified subscription.
6660 */
6661 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006662 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6663 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006664 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006665 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006666 return null;
6667 }
6668
Hall Liuf19c44f2018-11-27 14:38:17 -08006669 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6670 LocationAccessPolicy.checkLocationPermission(mApp,
6671 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6672 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006673 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006674 .setCallingPid(Binder.getCallingPid())
6675 .setCallingUid(Binder.getCallingUid())
6676 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006677 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006678 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6679 .build());
6680
6681 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6682 LocationAccessPolicy.checkLocationPermission(mApp,
6683 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6684 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006685 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006686 .setCallingPid(Binder.getCallingPid())
6687 .setCallingUid(Binder.getCallingUid())
6688 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006689 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006690 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6691 .build());
6692 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6693 boolean hasFinePermission =
6694 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6695 boolean hasCoarsePermission =
6696 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6697
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006698 final long identity = Binder.clearCallingIdentity();
6699 try {
6700 final Phone phone = getPhone(subId);
6701 if (phone == null) {
6702 return null;
6703 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006704
Hall Liuf19c44f2018-11-27 14:38:17 -08006705 ServiceState ss = phone.getServiceState();
6706
6707 // Scrub out the location info in ServiceState depending on what level of access
6708 // the caller has.
6709 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006710 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6711 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006712 } finally {
6713 Binder.restoreCallingIdentity(identity);
6714 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006715 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006716
6717 /**
6718 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6719 *
6720 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6721 * voicemail ringtone.
6722 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6723 * PhoneAccount.
6724 */
6725 @Override
6726 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006727 final long identity = Binder.clearCallingIdentity();
6728 try {
6729 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6730 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006731 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006732 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006733
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006734 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6735 } finally {
6736 Binder.restoreCallingIdentity(identity);
6737 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006738 }
6739
6740 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006741 * Sets the per-account voicemail ringtone.
6742 *
6743 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6744 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6745 *
6746 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6747 * voicemail ringtone.
6748 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6749 * PhoneAccount.
6750 */
6751 @Override
6752 public void setVoicemailRingtoneUri(String callingPackage,
6753 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006754 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006755 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006756 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6757 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006758 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6759 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6760 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006761 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006762
6763 final long identity = Binder.clearCallingIdentity();
6764 try {
6765 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6766 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006767 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006768 }
6769 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6770 } finally {
6771 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006772 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006773 }
6774
6775 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006776 * Returns whether vibration is set for voicemail notification in Phone settings.
6777 *
6778 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6779 * voicemail vibration setting.
6780 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6781 */
6782 @Override
6783 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006784 final long identity = Binder.clearCallingIdentity();
6785 try {
6786 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6787 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006788 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006789 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006790
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006791 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6792 } finally {
6793 Binder.restoreCallingIdentity(identity);
6794 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006795 }
6796
Youhan Wange64578a2016-05-02 15:32:42 -07006797 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006798 * Sets the per-account voicemail vibration.
6799 *
6800 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6801 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6802 *
6803 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6804 * voicemail vibration setting.
6805 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6806 * specific PhoneAccount.
6807 */
6808 @Override
6809 public void setVoicemailVibrationEnabled(String callingPackage,
6810 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006811 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006812 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006813 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6814 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006815 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6816 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6817 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006818 }
6819
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006820 final long identity = Binder.clearCallingIdentity();
6821 try {
6822 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6823 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006824 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006825 }
6826 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6827 } finally {
6828 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006829 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006830 }
6831
6832 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006833 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6834 *
6835 * @throws SecurityException if the caller does not have the required permission
6836 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006837 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006838 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006839 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006840 }
6841
6842 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006843 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6844 * permission.
6845 *
6846 * @throws SecurityException if the caller does not have the required permission
6847 */
6848 private void enforceSendSmsPermission() {
6849 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6850 }
6851
6852 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006853 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006854 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006855 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006856 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006857 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006858 final long identity = Binder.clearCallingIdentity();
6859 try {
6860 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006861 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006862 if (componentName == null) {
6863 throw new SecurityException(
6864 "Caller not current active visual voicemail package[null]");
6865 }
6866 String vvmPackage = componentName.getPackageName();
6867 if (!callingPackage.equals(vvmPackage)) {
6868 throw new SecurityException("Caller not current active visual voicemail package["
6869 + vvmPackage + "]");
6870 }
6871 } finally {
6872 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006873 }
6874 }
6875
6876 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006877 * Return the application ID for the app type.
6878 *
6879 * @param subId the subscription ID that this request applies to.
6880 * @param appType the uicc app type.
6881 * @return Application ID for specificied app type, or null if no uicc.
6882 */
6883 @Override
6884 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006885 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006886 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006887
6888 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006889 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006890 if (phone == null) {
6891 return null;
6892 }
6893 String aid = null;
6894 try {
6895 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6896 .getApplicationByType(appType).getAid();
6897 } catch (Exception e) {
6898 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6899 }
6900 return aid;
6901 } finally {
6902 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006903 }
Youhan Wange64578a2016-05-02 15:32:42 -07006904 }
6905
Youhan Wang4001d252016-05-11 10:29:41 -07006906 /**
6907 * Return the Electronic Serial Number.
6908 *
6909 * @param subId the subscription ID that this request applies to.
6910 * @return ESN or null if error.
6911 */
6912 @Override
6913 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006914 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006915 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006916
6917 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006918 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006919 if (phone == null) {
6920 return null;
6921 }
6922 String esn = null;
6923 try {
6924 esn = phone.getEsn();
6925 } catch (Exception e) {
6926 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6927 }
6928 return esn;
6929 } finally {
6930 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006931 }
Youhan Wang4001d252016-05-11 10:29:41 -07006932 }
6933
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006934 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006935 * Return the Preferred Roaming List Version.
6936 *
6937 * @param subId the subscription ID that this request applies to.
6938 * @return PRLVersion or null if error.
6939 */
6940 @Override
6941 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006942 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006943 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006944
6945 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006946 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006947 if (phone == null) {
6948 return null;
6949 }
6950 String cdmaPrlVersion = null;
6951 try {
6952 cdmaPrlVersion = phone.getCdmaPrlVersion();
6953 } catch (Exception e) {
6954 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6955 }
6956 return cdmaPrlVersion;
6957 } finally {
6958 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006959 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006960 }
6961
6962 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006963 * Get snapshot of Telephony histograms
6964 * @return List of Telephony histograms
6965 * @hide
6966 */
6967 @Override
6968 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006969 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6970 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006971
6972 final long identity = Binder.clearCallingIdentity();
6973 try {
6974 return RIL.getTelephonyRILTimingHistograms();
6975 } finally {
6976 Binder.restoreCallingIdentity(identity);
6977 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006978 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006979
6980 /**
6981 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006982 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6983 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006984 * Require system privileges. In the future we may add this to carrier APIs.
6985 *
Michele Berionne482f8202018-11-27 18:57:59 -08006986 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006987 */
6988 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006989 @TelephonyManager.SetCarrierRestrictionResult
6990 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006991 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006992 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006993
Michele Berionne482f8202018-11-27 18:57:59 -08006994 if (carrierRestrictionRules == null) {
6995 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006996 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006997
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006998 final long identity = Binder.clearCallingIdentity();
6999 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007000 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007001 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007002 } finally {
7003 Binder.restoreCallingIdentity(identity);
7004 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007005 }
7006
7007 /**
7008 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007009 * Get the allowed carrier list and the excluded carrier list, including the priority between
7010 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007011 * Require system privileges. In the future we may add this to carrier APIs.
7012 *
Michele Berionne482f8202018-11-27 18:57:59 -08007013 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007014 */
7015 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007016 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007017 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007018 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007019
7020 final long identity = Binder.clearCallingIdentity();
7021 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007022 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7023 if (response instanceof CarrierRestrictionRules) {
7024 return (CarrierRestrictionRules) response;
7025 }
7026 // Response is an Exception of some kind,
7027 // which is signalled to the user as a NULL retval
7028 return null;
7029 } catch (Exception e) {
7030 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7031 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007032 } finally {
7033 Binder.restoreCallingIdentity(identity);
7034 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007035 }
7036
fionaxu59545b42016-05-25 15:53:37 -07007037 /**
7038 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7039 * @param subId the subscription ID that this action applies to.
7040 * @param enabled control enable or disable metered apns.
7041 * {@hide}
7042 */
7043 @Override
7044 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7045 enforceModifyPermission();
7046 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007047
7048 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007049 if (phone == null) {
7050 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7051 return;
7052 }
7053 try {
7054 phone.carrierActionSetMeteredApnsEnabled(enabled);
7055 } catch (Exception e) {
7056 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007057 } finally {
7058 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007059 }
7060 }
7061
7062 /**
7063 * Action set from carrier signalling broadcast receivers to enable/disable radio
7064 * @param subId the subscription ID that this action applies to.
7065 * @param enabled control enable or disable radio.
7066 * {@hide}
7067 */
7068 @Override
7069 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7070 enforceModifyPermission();
7071 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007072
7073 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007074 if (phone == null) {
7075 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7076 return;
7077 }
7078 try {
7079 phone.carrierActionSetRadioEnabled(enabled);
7080 } catch (Exception e) {
7081 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007082 } finally {
7083 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007084 }
7085 }
7086
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007087 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007088 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7089 * network status based on which carrier apps could apply actions accordingly,
7090 * enable/disable default url handler for example.
7091 *
7092 * @param subId the subscription ID that this action applies to.
7093 * @param report control start/stop reporting the default network status.
7094 * {@hide}
7095 */
7096 @Override
7097 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7098 enforceModifyPermission();
7099 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007100
7101 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007102 if (phone == null) {
7103 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7104 return;
7105 }
7106 try {
7107 phone.carrierActionReportDefaultNetworkStatus(report);
7108 } catch (Exception e) {
7109 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007110 } finally {
7111 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007112 }
7113 }
7114
7115 /**
fionaxud9622282017-07-17 17:51:30 -07007116 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7117 * @param subId the subscription ID that this action applies to.
7118 * {@hide}
7119 */
7120 @Override
7121 public void carrierActionResetAll(int subId) {
7122 enforceModifyPermission();
7123 final Phone phone = getPhone(subId);
7124 if (phone == null) {
7125 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7126 return;
7127 }
7128 try {
7129 phone.carrierActionResetAll();
7130 } catch (Exception e) {
7131 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7132 }
7133 }
7134
7135 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007136 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7137 * bug report is being generated.
7138 */
7139 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007140 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007141 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7142 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007143 writer.println("Permission Denial: can't dump Phone from pid="
7144 + Binder.getCallingPid()
7145 + ", uid=" + Binder.getCallingUid()
7146 + "without permission "
7147 + android.Manifest.permission.DUMP);
7148 return;
7149 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007150 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007151 }
Jack Yueb89b242016-06-22 13:27:47 -07007152
Brad Ebingerdac2f002018-04-03 15:17:52 -07007153 @Override
7154 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
7155 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
7156 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01007157 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
7158 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007159 }
7160
Jack Yueb89b242016-06-22 13:27:47 -07007161 /**
Jack Yu84291ec2017-05-26 16:07:50 -07007162 * Get aggregated video call data usage since boot.
7163 *
7164 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
7165 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07007166 * {@hide}
7167 */
7168 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07007169 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07007170 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
7171 null);
7172
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007173 final long identity = Binder.clearCallingIdentity();
7174 try {
7175 // NetworkStatsService keeps tracking the active network interface and identity. It
7176 // records the delta with the corresponding network identity.
7177 // We just return the total video call data usage snapshot since boot.
7178 Phone phone = getPhone(subId);
7179 if (phone != null) {
7180 return phone.getVtDataUsage(perUidStats);
7181 }
7182 return null;
7183 } finally {
7184 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07007185 }
Jack Yueb89b242016-06-22 13:27:47 -07007186 }
Jack Yu75ab2952016-07-08 14:29:33 -07007187
7188 /**
7189 * Policy control of data connection. Usually used when data limit is passed.
7190 * @param enabled True if enabling the data, otherwise disabling.
7191 * @param subId Subscription index
7192 * {@hide}
7193 */
7194 @Override
7195 public void setPolicyDataEnabled(boolean enabled, int subId) {
7196 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007197
7198 final long identity = Binder.clearCallingIdentity();
7199 try {
7200 Phone phone = getPhone(subId);
7201 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007202 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007203 }
7204 } finally {
7205 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007206 }
7207 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007208
7209 /**
7210 * Get Client request stats
7211 * @return List of Client Request Stats
7212 * @hide
7213 */
7214 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007215 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7216 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007217 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007218 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007219 return null;
7220 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007221 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007222
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007223 final long identity = Binder.clearCallingIdentity();
7224 try {
7225 if (phone != null) {
7226 return phone.getClientRequestStats();
7227 }
7228
7229 return null;
7230 } finally {
7231 Binder.restoreCallingIdentity(identity);
7232 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007233 }
7234
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007235 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007236 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007237 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007238 }
Jack Yueb4124c2017-02-16 15:32:43 -08007239
7240 /**
Grace Chen70990072017-03-24 17:21:30 -07007241 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007242 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007243 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007244 * @param state State of SIM (power down, power up, pass through)
7245 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7246 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7247 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007248 *
7249 **/
7250 @Override
Grace Chen70990072017-03-24 17:21:30 -07007251 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007252 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007253 Phone phone = PhoneFactory.getPhone(slotIndex);
7254
vagdeviaf9a5b92018-08-15 16:01:53 -07007255 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7256
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007257 final long identity = Binder.clearCallingIdentity();
7258 try {
7259 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007260 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007261 }
7262 } finally {
7263 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007264 }
7265 }
Shuo Qiandd210312017-04-12 22:11:33 +00007266
Tyler Gunn65d45c22017-06-05 11:22:26 -07007267 private boolean isUssdApiAllowed(int subId) {
7268 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007269 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007270 if (configManager == null) {
7271 return false;
7272 }
7273 PersistableBundle pb = configManager.getConfigForSubId(subId);
7274 if (pb == null) {
7275 return false;
7276 }
7277 return pb.getBoolean(
7278 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7279 }
7280
Shuo Qiandd210312017-04-12 22:11:33 +00007281 /**
7282 * Check if phone is in emergency callback mode
7283 * @return true if phone is in emergency callback mode
7284 * @param subId sub id
7285 */
goneil9c5f4872017-12-05 14:07:56 -08007286 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007287 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007288 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007289 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007290
7291 final long identity = Binder.clearCallingIdentity();
7292 try {
7293 if (phone != null) {
7294 return phone.isInEcm();
7295 } else {
7296 return false;
7297 }
7298 } finally {
7299 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007300 }
7301 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007302
7303 /**
7304 * Get the current signal strength information for the given subscription.
7305 * Because this information is not updated when the device is in a low power state
7306 * it should not be relied-upon to be current.
7307 * @param subId Subscription index
7308 * @return the most recent cached signal strength info from the modem
7309 */
7310 @Override
7311 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007312 final long identity = Binder.clearCallingIdentity();
7313 try {
7314 Phone p = getPhone(subId);
7315 if (p == null) {
7316 return null;
7317 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007318
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007319 return p.getSignalStrength();
7320 } finally {
7321 Binder.restoreCallingIdentity(identity);
7322 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007323 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007324
Pengquan Meng77b7f132018-08-22 14:49:57 -07007325 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007326 * Get the current modem radio state for the given slot.
7327 * @param slotIndex slot index.
7328 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007329 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007330 * @return the current radio power state from the modem
7331 */
7332 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007333 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007334 Phone phone = PhoneFactory.getPhone(slotIndex);
7335 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007336 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7337 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007338 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7339 }
7340
7341 final long identity = Binder.clearCallingIdentity();
7342 try {
7343 return phone.getRadioPowerState();
7344 } finally {
7345 Binder.restoreCallingIdentity(identity);
7346 }
7347 }
7348 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7349 }
7350
7351 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007352 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7353 *
7354 * <p>Requires one of the following permissions:
7355 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7356 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7357 * privileges.
7358 *
7359 * @param subId subscription id
7360 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7361 * {@code false}.
7362 */
7363 @Override
7364 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007365 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7366 null /* message */);
7367
Pengquan Menga1bb6272018-09-06 09:59:22 -07007368 boolean isEnabled = false;
7369 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007370 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007371 Phone phone = getPhone(subId);
7372 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007373 } catch (Exception e) {
7374 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7375 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007376 } finally {
7377 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007378 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007379 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007380 }
7381
7382
7383 /**
7384 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7385 *
7386 * <p> Requires permission:
7387 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7388 * privileges.
7389 *
7390 * @param subId subscription id
7391 * @param isEnabled {@code true} means enable, {@code false} means disable.
7392 */
7393 @Override
7394 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007395 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7396 mApp, subId, "setDataRoamingEnabled");
7397
Pengquan Menga1bb6272018-09-06 09:59:22 -07007398 final long identity = Binder.clearCallingIdentity();
7399 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007400 Phone phone = getPhone(subId);
7401 if (phone != null) {
7402 phone.setDataRoamingEnabled(isEnabled);
7403 }
7404 } finally {
7405 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007406 }
7407 }
7408
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007409 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007410 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007411 TelephonyPermissions
7412 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007413 mApp, subId, "isManualNetworkSelectionAllowed");
7414
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007415 boolean isAllowed = true;
7416 final long identity = Binder.clearCallingIdentity();
7417 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007418 Phone phone = getPhone(subId);
7419 if (phone != null) {
7420 isAllowed = phone.isCspPlmnEnabled();
7421 }
7422 } finally {
7423 Binder.restoreCallingIdentity(identity);
7424 }
7425 return isAllowed;
7426 }
7427
7428 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007429 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007430 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007431 try {
7432 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007433 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007434 } catch (SecurityException e) {
7435 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7436 // has carrier privileges on an active UICC
7437 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7438 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007439 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007440 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007441 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007442
7443 final long identity = Binder.clearCallingIdentity();
7444 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007445 UiccController uiccController = UiccController.getInstance();
7446 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007447 if (hasReadPermission) {
7448 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007449 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007450
7451 // Remove private info if the caller doesn't have access
7452 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7453 for (UiccCardInfo cardInfo : cardInfos) {
7454 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7455 // is available
7456 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7457 if (card == null || card.getUiccProfile() == null) {
7458 // assume no access if the card or profile is unavailable
7459 filteredInfos.add(cardInfo.getUnprivileged());
7460 continue;
7461 }
7462 UiccProfile profile = card.getUiccProfile();
7463 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7464 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7465 filteredInfos.add(cardInfo);
7466 } else {
7467 filteredInfos.add(cardInfo.getUnprivileged());
7468 }
7469 }
7470 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007471 } finally {
7472 Binder.restoreCallingIdentity(identity);
7473 }
7474 }
7475
7476 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007477 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007478 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007479
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007480 final long identity = Binder.clearCallingIdentity();
7481 try {
7482 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7483 if (slots == null) {
7484 Rlog.i(LOG_TAG, "slots is null.");
7485 return null;
7486 }
7487
7488 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7489 for (int i = 0; i < slots.length; i++) {
7490 UiccSlot slot = slots[i];
7491 if (slot == null) {
7492 continue;
7493 }
7494
Jordan Liu7be7e652019-05-06 18:55:02 +00007495 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007496 UiccCard card = slot.getUiccCard();
7497 if (card != null) {
7498 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007499 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007500 cardId = slot.getEid();
7501 if (TextUtils.isEmpty(cardId)) {
7502 cardId = slot.getIccId();
7503 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007504 }
7505
Jordan Liu857451f2019-05-09 16:35:35 -07007506 if (cardId != null) {
7507 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7508 // if cardId is an EID, it's all digits so this is fine
7509 cardId = IccUtils.stripTrailingFs(cardId);
7510 }
7511
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007512 int cardState = 0;
7513 switch (slot.getCardState()) {
7514 case CARDSTATE_ABSENT:
7515 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7516 break;
7517 case CARDSTATE_PRESENT:
7518 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7519 break;
7520 case CARDSTATE_ERROR:
7521 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7522 break;
7523 case CARDSTATE_RESTRICTED:
7524 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7525 break;
7526 default:
7527 break;
7528
7529 }
7530
7531 infos[i] = new UiccSlotInfo(
7532 slot.isActive(),
7533 slot.isEuicc(),
7534 cardId,
7535 cardState,
7536 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007537 slot.isExtendedApduSupported(),
7538 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007539 }
7540 return infos;
7541 } finally {
7542 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007543 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007544 }
7545
7546 @Override
7547 public boolean switchSlots(int[] physicalSlots) {
7548 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007549
7550 final long identity = Binder.clearCallingIdentity();
7551 try {
7552 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7553 } finally {
7554 Binder.restoreCallingIdentity(identity);
7555 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007556 }
Jack Yu4c988042018-02-27 15:30:01 -08007557
7558 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007559 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007560 final long identity = Binder.clearCallingIdentity();
7561 try {
7562 return UiccController.getInstance().getCardIdForDefaultEuicc();
7563 } finally {
7564 Binder.restoreCallingIdentity(identity);
7565 }
7566 }
7567
7568 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007569 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7570 enforceModifyPermission();
7571 final Phone phone = getPhone(subId);
7572 if (phone == null) {
7573 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7574 return;
7575 }
7576
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007577 final long identity = Binder.clearCallingIdentity();
7578 try {
7579 phone.setRadioIndicationUpdateMode(filters, mode);
7580 } finally {
7581 Binder.restoreCallingIdentity(identity);
7582 }
Jack Yu4c988042018-02-27 15:30:01 -08007583 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007584
7585 /**
goneil47ffb6e2018-04-06 15:40:58 -07007586 * A test API to reload the UICC profile.
7587 *
7588 * <p>Requires that the calling app has permission
7589 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7590 * @hide
7591 */
7592 @Override
7593 public void refreshUiccProfile(int subId) {
7594 enforceModifyPermission();
7595
7596 final long identity = Binder.clearCallingIdentity();
7597 try {
7598 Phone phone = getPhone(subId);
7599 if (phone == null) {
7600 return;
7601 }
7602 UiccCard uiccCard = phone.getUiccCard();
7603 if (uiccCard == null) {
7604 return;
7605 }
7606 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7607 if (uiccProfile == null) {
7608 return;
7609 }
7610 uiccProfile.refresh();
7611 } finally {
7612 Binder.restoreCallingIdentity(identity);
7613 }
7614 }
7615
7616 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007617 * Returns false if the mobile data is disabled by default, otherwise return true.
7618 */
7619 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007620 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007621 }
7622
7623 /**
7624 * Returns true if the data roaming is enabled by default, i.e the system property
7625 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7626 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7627 */
7628 private boolean getDefaultDataRoamingEnabled(int subId) {
7629 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007630 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007631 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007632 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7633 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7634 return isDataRoamingEnabled;
7635 }
7636
7637 /**
7638 * Returns the default network type for the given {@code subId}, if the default network type is
7639 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7640 */
7641 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007642 List<Integer> list = TelephonyProperties.default_network();
7643 int phoneId = mSubscriptionController.getPhoneId(subId);
7644 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7645 return list.get(phoneId);
7646 }
7647 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007648 }
fionaxua13278b2018-03-21 00:08:13 -07007649
7650 @Override
7651 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007652 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007653 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007654
7655 final long identity = Binder.clearCallingIdentity();
7656 try {
7657 final Phone phone = getPhone(subId);
7658 if (phone == null) {
7659 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7660 return;
7661 }
chen xueaba88a2019-03-15 13:15:10 -07007662 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7663 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007664 } finally {
7665 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007666 }
fionaxua13278b2018-03-21 00:08:13 -07007667 }
7668
7669 @Override
7670 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007671 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007672
7673 final long identity = Binder.clearCallingIdentity();
7674 try {
7675 final Phone phone = getPhone(subId);
7676 if (phone == null) {
7677 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7678 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7679 }
7680 return phone.getCarrierIdListVersion();
7681 } finally {
7682 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007683 }
fionaxua13278b2018-03-21 00:08:13 -07007684 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007685
7686 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007687 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7688 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007689 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007690 mApp, subId, callingPackage, callingFeatureId,
7691 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007692 return -1;
7693 }
7694
7695 final long identity = Binder.clearCallingIdentity();
7696 try {
7697 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7698 } finally {
7699 Binder.restoreCallingIdentity(identity);
7700 }
7701 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007702
7703 @Override
7704 public int getCdmaRoamingMode(int subId) {
7705 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7706 mApp, subId, "getCdmaRoamingMode");
7707
7708 final long identity = Binder.clearCallingIdentity();
7709 try {
7710 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7711 } finally {
7712 Binder.restoreCallingIdentity(identity);
7713 }
7714 }
7715
7716 @Override
7717 public boolean setCdmaRoamingMode(int subId, int mode) {
7718 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7719 mApp, subId, "setCdmaRoamingMode");
7720
7721 final long identity = Binder.clearCallingIdentity();
7722 try {
7723 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7724 } finally {
7725 Binder.restoreCallingIdentity(identity);
7726 }
7727 }
7728
7729 @Override
7730 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7731 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7732 mApp, subId, "setCdmaSubscriptionMode");
7733
7734 final long identity = Binder.clearCallingIdentity();
7735 try {
7736 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7737 } finally {
7738 Binder.restoreCallingIdentity(identity);
7739 }
7740 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007741
sqianc5eccab2018-10-19 18:46:41 -07007742 @Override
sqian8c685422019-02-22 15:55:18 -08007743 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007744 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007745 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007746 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7747 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007748 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7749 }
7750 final long identity = Binder.clearCallingIdentity();
7751 try {
sqian854d44b2018-12-12 16:48:18 -08007752 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7753 for (Phone phone: PhoneFactory.getPhones()) {
7754 if (phone.getEmergencyNumberTracker() != null
7755 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7756 emergencyNumberListInternal.put(
7757 phone.getSubId(),
7758 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7759 }
sqian11b7a0e2018-12-05 18:48:28 -08007760 }
sqian854d44b2018-12-12 16:48:18 -08007761 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007762 } finally {
7763 Binder.restoreCallingIdentity(identity);
7764 }
sqianc5eccab2018-10-19 18:46:41 -07007765 }
7766
7767 @Override
sqian8c685422019-02-22 15:55:18 -08007768 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007769 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007770 if (!exactMatch) {
7771 TelephonyPermissions
7772 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007773 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007774 }
7775 final long identity = Binder.clearCallingIdentity();
7776 try {
sqian854d44b2018-12-12 16:48:18 -08007777 for (Phone phone: PhoneFactory.getPhones()) {
7778 if (phone.getEmergencyNumberTracker() != null
7779 && phone.getEmergencyNumberTracker() != null) {
7780 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7781 number, exactMatch)) {
7782 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007783 }
7784 }
sqian11b7a0e2018-12-05 18:48:28 -08007785 }
7786 return false;
7787 } finally {
7788 Binder.restoreCallingIdentity(identity);
7789 }
7790 }
7791
sqianf4ca7ed2019-01-15 18:32:07 -08007792 /**
7793 * Update emergency number list for test mode.
7794 */
7795 @Override
7796 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7797 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7798 "updateEmergencyNumberListTestMode");
7799
7800 final long identity = Binder.clearCallingIdentity();
7801 try {
7802 for (Phone phone: PhoneFactory.getPhones()) {
7803 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7804 if (tracker != null) {
7805 tracker.executeEmergencyNumberTestModeCommand(action, num);
7806 }
7807 }
7808 } finally {
7809 Binder.restoreCallingIdentity(identity);
7810 }
7811 }
7812
7813 /**
7814 * Get the full emergency number list for test mode.
7815 */
7816 @Override
7817 public List<String> getEmergencyNumberListTestMode() {
7818 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7819 "getEmergencyNumberListTestMode");
7820
7821 final long identity = Binder.clearCallingIdentity();
7822 try {
7823 Set<String> emergencyNumbers = new HashSet<>();
7824 for (Phone phone: PhoneFactory.getPhones()) {
7825 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7826 if (tracker != null) {
7827 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7828 emergencyNumbers.add(num.getNumber());
7829 }
7830 }
7831 }
7832 return new ArrayList<>(emergencyNumbers);
7833 } finally {
7834 Binder.restoreCallingIdentity(identity);
7835 }
7836 }
7837
chen xud6b45bd2018-10-30 22:27:10 -07007838 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007839 public int getEmergencyNumberDbVersion(int subId) {
7840 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7841
7842 final long identity = Binder.clearCallingIdentity();
7843 try {
7844 final Phone phone = getPhone(subId);
7845 if (phone == null) {
7846 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7847 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7848 }
7849 return phone.getEmergencyNumberDbVersion();
7850 } finally {
7851 Binder.restoreCallingIdentity(identity);
7852 }
7853 }
7854
7855 @Override
7856 public void notifyOtaEmergencyNumberDbInstalled() {
7857 enforceModifyPermission();
7858
7859 final long identity = Binder.clearCallingIdentity();
7860 try {
7861 for (Phone phone: PhoneFactory.getPhones()) {
7862 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7863 if (tracker != null) {
7864 tracker.updateOtaEmergencyNumberDatabase();
7865 }
7866 }
7867 } finally {
7868 Binder.restoreCallingIdentity(identity);
7869 }
7870 }
7871
7872 @Override
7873 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7874 enforceActiveEmergencySessionPermission();
7875
7876 final long identity = Binder.clearCallingIdentity();
7877 try {
7878 for (Phone phone: PhoneFactory.getPhones()) {
7879 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7880 if (tracker != null) {
7881 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7882 }
7883 }
7884 } finally {
7885 Binder.restoreCallingIdentity(identity);
7886 }
7887 }
7888
7889 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007890 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7891 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7892 Phone phone = getPhone(subId);
7893 if (phone == null) {
7894 return null;
7895 }
7896 final long identity = Binder.clearCallingIdentity();
7897 try {
7898 UiccProfile profile = UiccController.getInstance()
7899 .getUiccProfileForPhone(phone.getPhoneId());
7900 if (profile != null) {
7901 return profile.getCertsFromCarrierPrivilegeAccessRules();
7902 }
7903 } finally {
7904 Binder.restoreCallingIdentity(identity);
7905 }
7906 return null;
7907 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007908
7909 /**
7910 * Enable or disable a modem stack.
7911 */
7912 @Override
7913 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7914 enforceModifyPermission();
7915
7916 final long identity = Binder.clearCallingIdentity();
7917 try {
7918 Phone phone = PhoneFactory.getPhone(slotIndex);
7919 if (phone == null) {
7920 return false;
7921 } else {
7922 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7923 }
7924 } finally {
7925 Binder.restoreCallingIdentity(identity);
7926 }
7927 }
Michelecea4cf22018-12-21 15:00:11 -08007928
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007929 /**
7930 * Whether a modem stack is enabled or not.
7931 */
7932 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007933 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7934 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007935 Phone phone = PhoneFactory.getPhone(slotIndex);
7936 if (phone == null) return false;
7937
7938 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007939 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7940 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007941 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7942 }
7943
7944 final long identity = Binder.clearCallingIdentity();
7945 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007946 try {
7947 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7948 } catch (NoSuchElementException ex) {
7949 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7950 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007951 } finally {
7952 Binder.restoreCallingIdentity(identity);
7953 }
7954 }
7955
Michelecea4cf22018-12-21 15:00:11 -08007956 @Override
Michele0ea7d782019-03-19 14:58:42 -07007957 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007958 enforceModifyPermission();
7959
7960 final long identity = Binder.clearCallingIdentity();
7961 try {
7962 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007963 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007964 .commit();
7965 } finally {
7966 Binder.restoreCallingIdentity(identity);
7967 }
7968 }
7969
7970 @Override
Michele0ea7d782019-03-19 14:58:42 -07007971 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007972 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007973 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007974 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7975 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007976 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007977 }
Michelecea4cf22018-12-21 15:00:11 -08007978
7979 final long identity = Binder.clearCallingIdentity();
7980 try {
Michele0ea7d782019-03-19 14:58:42 -07007981 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007982 } finally {
7983 Binder.restoreCallingIdentity(identity);
7984 }
7985 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007986
Michele0ea7d782019-03-19 14:58:42 -07007987 @TelephonyManager.IsMultiSimSupportedResult
7988 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007989 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7990 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7991 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007992 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7993 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007994 }
7995 // Check if the hardware supports multisim functionality. If usage of multisim is not
7996 // supported by the modem, indicate that it is restricted.
7997 PhoneCapability staticCapability =
7998 mPhoneConfigurationManager.getStaticPhoneCapability();
7999 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008000 loge("isMultiSimSupportedInternal: no static configuration available");
8001 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008002 }
Sarah Chin5f0ecd72019-12-06 10:24:18 -08008003 if (staticCapability.getLogicalModemUuids().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008004 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8005 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008006 }
8007 // Check if support of multiple SIMs is restricted by carrier
8008 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008009 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008010 }
8011
Michele0ea7d782019-03-19 14:58:42 -07008012 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008013 }
8014
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008015 /**
8016 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008017 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8018 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8019 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008020 * @param numOfSims number of active sims we want to switch to
8021 */
8022 @Override
8023 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008024 if (numOfSims == 1) {
8025 enforceModifyPermission();
8026 } else {
8027 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8028 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8029 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008030 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008031
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008032 try {
Michele30b57b22019-03-01 12:01:14 -08008033 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008034 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008035 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8036 return;
8037 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008038 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8039 } finally {
8040 Binder.restoreCallingIdentity(identity);
8041 }
8042 }
8043
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008044 @Override
8045 public boolean isApplicationOnUicc(int subId, int appType) {
8046 enforceReadPrivilegedPermission("isApplicationOnUicc");
8047 Phone phone = getPhone(subId);
8048 if (phone == null) {
8049 return false;
8050 }
8051 final long identity = Binder.clearCallingIdentity();
8052 try {
8053 UiccCard uiccCard = phone.getUiccCard();
8054 if (uiccCard == null) {
8055 return false;
8056 }
8057 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8058 if (uiccProfile == null) {
8059 return false;
8060 }
8061 if (TelephonyManager.APPTYPE_SIM <= appType
8062 && appType <= TelephonyManager.APPTYPE_ISIM) {
8063 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8064 }
8065 return false;
8066 } finally {
8067 Binder.restoreCallingIdentity(identity);
8068 }
8069 }
8070
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008071 /**
chen xub4baa772019-04-03 10:23:41 -07008072 * Get whether making changes to modem configurations will trigger reboot.
8073 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008074 */
8075 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008076 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8077 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008078 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008079 mApp, subId, callingPackage, callingFeatureId,
8080 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008081 return false;
8082 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008083 final long identity = Binder.clearCallingIdentity();
8084 try {
8085 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8086 } finally {
8087 Binder.restoreCallingIdentity(identity);
8088 }
8089 }
8090
Nathan Harold29f5f052019-02-15 13:41:57 -08008091 private void updateModemStateMetrics() {
8092 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8093 // TODO: check the state for each modem if the api is ready.
8094 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8095 }
8096
Pengquan Meng3889a572019-01-23 11:16:29 -08008097 @Override
8098 public int[] getSlotsMapping() {
8099 enforceReadPrivilegedPermission("getSlotsMapping");
8100
8101 final long identity = Binder.clearCallingIdentity();
8102 try {
8103 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8104 // All logical slots should have a mapping to a physical slot.
8105 int[] logicalSlotsMapping = new int[phoneCount];
8106 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8107 for (int i = 0; i < slotInfos.length; i++) {
8108 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8109 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8110 }
8111 }
8112 return logicalSlotsMapping;
8113 } finally {
8114 Binder.restoreCallingIdentity(identity);
8115 }
8116 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008117
8118 /**
8119 * Get the IRadio HAL Version
8120 */
8121 @Override
8122 public int getRadioHalVersion() {
8123 Phone phone = getDefaultPhone();
8124 if (phone == null) return -1;
8125 HalVersion hv = phone.getHalVersion();
8126 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8127 return hv.major * 100 + hv.minor;
8128 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008129
8130 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008131 * Get the current calling package name.
8132 * @return the current calling package name
8133 */
8134 @Override
8135 public String getCurrentPackageName() {
8136 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8137 }
8138
8139 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008140 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8141 * corresponding network requests on a subId.
8142 *
8143 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008144 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008145 * 2) APN is un-metered for this subscription, or
8146 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbetty97defcf2019-12-24 15:40:37 +08008147 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008148 *
8149 * @return whether data is allowed for a apn type.
8150 *
8151 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008152 */
8153 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008154 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008155 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8156 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008157
8158 // Now that all security checks passes, perform the operation as ourselves.
8159 final long identity = Binder.clearCallingIdentity();
8160 try {
8161 Phone phone = getPhone(subId);
8162 if (phone == null) return false;
8163
Jack Yu41407ee2019-05-13 16:54:09 -07008164 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008165 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8166 } finally {
8167 Binder.restoreCallingIdentity(identity);
8168 }
8169 }
8170
8171 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008172 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008173 enforceReadPrivilegedPermission("isApnMetered");
8174
8175 // Now that all security checks passes, perform the operation as ourselves.
8176 final long identity = Binder.clearCallingIdentity();
8177 try {
8178 Phone phone = getPhone(subId);
8179 if (phone == null) return true; // By default return true.
8180
Jack Yu41407ee2019-05-13 16:54:09 -07008181 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008182 } finally {
8183 Binder.restoreCallingIdentity(identity);
8184 }
8185 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008186
8187 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008188 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8189 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8190 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8191 if (iccRecords == null) {
8192 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8193 return false;
8194 }
8195 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8196 }
8197
8198 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07008199 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008200 if (callingPackage == null) {
8201 callingPackage = getCurrentPackageName();
8202 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008203 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8204 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
8205 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
8206 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8207 }
8208 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8209 Intent intent = new Intent();
8210 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8211 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8212 // Bring up choose default SMS subscription dialog right now
8213 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8214 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8215 mApp.startActivity(intent);
8216 }
chen xud5ca2d52019-05-28 15:20:57 -07008217
8218 @Override
8219 public String getMmsUAProfUrl(int subId) {
8220 //TODO investigate if this API should require proper permission check in R b/133791609
8221 final long identity = Binder.clearCallingIdentity();
8222 try {
8223 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8224 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8225 } finally {
8226 Binder.restoreCallingIdentity(identity);
8227 }
8228 }
8229
8230 @Override
8231 public String getMmsUserAgent(int subId) {
8232 //TODO investigate if this API should require proper permission check in R b/133791609
8233 final long identity = Binder.clearCallingIdentity();
8234 try {
8235 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8236 .getString(com.android.internal.R.string.config_mms_user_agent);
8237 } finally {
8238 Binder.restoreCallingIdentity(identity);
8239 }
8240 }
Jack Yub07d4972019-05-28 16:12:25 -07008241
8242 @Override
8243 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8244 enforceModifyPermission();
8245
8246 // Now that all security checks passes, perform the operation as ourselves.
8247 final long identity = Binder.clearCallingIdentity();
8248 try {
8249 Phone phone = getPhone(subId);
8250 if (phone == null) return false;
8251
8252 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8253 } finally {
8254 Binder.restoreCallingIdentity(identity);
8255 }
8256 }
8257
8258 @Override
8259 public boolean isDataAllowedInVoiceCall(int subId) {
8260 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8261
8262 // Now that all security checks passes, perform the operation as ourselves.
8263 final long identity = Binder.clearCallingIdentity();
8264 try {
8265 Phone phone = getPhone(subId);
8266 if (phone == null) return false;
8267
8268 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8269 } finally {
8270 Binder.restoreCallingIdentity(identity);
8271 }
8272 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008273
changbetty97defcf2019-12-24 15:40:37 +08008274 @Override
8275 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8276 enforceModifyPermission();
8277
8278 // Now that all security checks passes, perform the operation as ourselves.
8279 final long identity = Binder.clearCallingIdentity();
8280 try {
8281 Phone phone = getPhone(subId);
8282 if (phone == null) return false;
8283
8284 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8285 } finally {
8286 Binder.restoreCallingIdentity(identity);
8287 }
8288 }
8289
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008290 /**
8291 * Updates whether conference event pacakge handling is enabled.
8292 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8293 * otherwise.
8294 */
8295 @Override
8296 public void setCepEnabled(boolean isCepEnabled) {
8297 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8298
8299 final long identity = Binder.clearCallingIdentity();
8300 try {
8301 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8302 for (Phone phone : PhoneFactory.getPhones()) {
8303 Phone defaultPhone = phone.getImsPhone();
8304 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8305 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8306 ImsPhoneCallTracker imsPhoneCallTracker =
8307 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8308 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8309 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8310 + imsPhone.getMsisdn());
8311 }
8312 }
8313 } finally {
8314 Binder.restoreCallingIdentity(identity);
8315 }
8316 }
allenwtsu46dcc572020-01-08 18:24:03 +08008317
8318 /**
8319 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8320 *
8321 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8322 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8323 * before being read.
8324 */
8325 @Override
8326 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8327 isCompressed) {
8328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8329 mApp, subId, "notifyRcsAutoConfigurationReceived");
8330 try {
8331 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8332 if (configBinder == null) {
8333 Rlog.e(LOG_TAG, "null result for getImsConfig");
8334 } else {
8335 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8336 }
8337 } catch (RemoteException e) {
8338 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8339 }
8340 }
zoey chenf95ca592019-12-30 16:11:23 +08008341
8342 @Override
8343 public boolean isIccLockEnabled(int subId) {
8344 enforceReadPrivilegedPermission("isIccLockEnabled");
8345
8346 // Now that all security checks passes, perform the operation as ourselves.
8347 final long identity = Binder.clearCallingIdentity();
8348 try {
8349 Phone phone = getPhone(subId);
8350 if (phone != null && phone.getIccCard() != null) {
8351 return phone.getIccCard().getIccLockEnabled();
8352 } else {
8353 return false;
8354 }
8355 } finally {
8356 Binder.restoreCallingIdentity(identity);
8357 }
8358 }
8359
8360 /**
8361 * Set the ICC pin lock enabled or disabled..
8362 *
8363 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8364 * 0 or a positive integer as the attempts remaining value.
8365 *
8366 */
8367 @Override
8368 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8369 enforceModifyPermission();
8370
8371 Phone phone = getPhone(subId);
8372 if (phone == null) {
8373 return 0;
8374 }
8375 // Now that all security checks passes, perform the operation as ourselves.
8376 final long identity = Binder.clearCallingIdentity();
8377 try {
8378 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8379 new Pair<Boolean, String>(enabled, password), phone, null);
8380 return attemptsRemaining;
8381
8382 } catch (Exception e) {
8383 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8384 } finally {
8385 Binder.restoreCallingIdentity(identity);
8386 }
8387 return 0;
8388 }
8389
8390 /**
8391 * Change the ICC password used in ICC pin lock.
8392 *
8393 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8394 * 0 or a positive integer as the attempts remaining value.
8395 *
8396 */
8397 @Override
8398 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8399 enforceModifyPermission();
8400
8401 Phone phone = getPhone(subId);
8402 if (phone == null) {
8403 return 0;
8404 }
8405 // Now that all security checks passes, perform the operation as ourselves.
8406 final long identity = Binder.clearCallingIdentity();
8407 try {
8408 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8409 new Pair<String, String>(oldPassword, newPassword), phone, null);
8410 return attemptsRemaining;
8411
8412 } catch (Exception e) {
8413 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8414 } finally {
8415 Binder.restoreCallingIdentity(identity);
8416 }
8417 return 0;
8418 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008419}