blob: 2506903cfb7ff6ad6bc1404b75ab1b95fbb1fa77 [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;
sqian80370722020-01-29 15:02:51 -0800274 private static final int CMD_GET_CALL_FORWARDING = 83;
275 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
276 private static final int CMD_SET_CALL_FORWARDING = 85;
277 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
278 private static final int CMD_GET_CALL_WAITING = 87;
279 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
280 private static final int CMD_SET_CALL_WAITING = 89;
281 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700282
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800283 // Parameters of select command.
284 private static final int SELECT_COMMAND = 0xA4;
285 private static final int SELECT_P1 = 0x04;
286 private static final int SELECT_P2 = 0;
287 private static final int SELECT_P3 = 0x10;
288
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700289 /** The singleton instance. */
290 private static PhoneInterfaceManager sInstance;
291
Wink Saville3ab207e2014-11-20 13:07:20 -0800292 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800293 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800294 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700295 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800296 private AppOpsManager mAppOps;
297 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800298 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800299 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700300 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700301
Derek Tan97ebb422014-09-05 16:55:38 -0700302 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
303 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800304 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800305 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700306
Michelecea4cf22018-12-21 15:00:11 -0800307 // String to store multi SIM allowed
308 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
309
Derek Tan740e1672017-06-27 14:56:27 -0700310 // The AID of ISD-R.
311 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
312
yinxub1bed742017-04-17 11:45:04 -0700313 private NetworkScanRequestTracker mNetworkScanRequestTracker;
314
David Kelly5e06a7f2018-03-12 14:10:59 +0000315 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
316 private static final int MANUFACTURER_CODE_LENGTH = 8;
317
Derek Tan89e89d42014-07-08 17:00:10 -0700318 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700319 * Experiment flag to enable erase modem config on reset network, default value is false
320 */
321 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
322 "reset_network_erase_modem_config_enabled";
323
324 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700325 * A request object to use for transmitting data to an ICC.
326 */
327 private static final class IccAPDUArgument {
328 public int channel, cla, command, p1, p2, p3;
329 public String data;
330
331 public IccAPDUArgument(int channel, int cla, int command,
332 int p1, int p2, int p3, String data) {
333 this.channel = channel;
334 this.cla = cla;
335 this.command = command;
336 this.p1 = p1;
337 this.p2 = p2;
338 this.p3 = p3;
339 this.data = data;
340 }
341 }
342
343 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700344 * A request object to use for transmitting data to an ICC.
345 */
346 private static final class ManualNetworkSelectionArgument {
347 public OperatorInfo operatorInfo;
348 public boolean persistSelection;
349
350 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
351 this.operatorInfo = operatorInfo;
352 this.persistSelection = persistSelection;
353 }
354 }
355
356 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
358 * request after sending. The main thread will notify the request when it is complete.
359 */
360 private static final class MainThreadRequest {
361 /** The argument to use for the request */
362 public Object argument;
363 /** The result of the request that is run on the main thread */
364 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800365 // The subscriber id that this request applies to. Defaults to
366 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
367 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700368
Nathan Harold92bed182018-10-12 18:16:49 -0700369 // In cases where subId is unavailable, the caller needs to specify the phone.
370 public Phone phone;
371
vagdeviaf9a5b92018-08-15 16:01:53 -0700372 public WorkSource workSource;
373
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374 public MainThreadRequest(Object argument) {
375 this.argument = argument;
376 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800377
Nathan Harold92bed182018-10-12 18:16:49 -0700378 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
379 this.argument = argument;
380 if (phone != null) {
381 this.phone = phone;
382 }
383 this.workSource = workSource;
384 }
385
vagdeviaf9a5b92018-08-15 16:01:53 -0700386 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800387 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800388 if (subId != null) {
389 this.subId = subId;
390 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700391 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800392 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700393 }
394
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800395 private static final class IncomingThirdPartyCallArgs {
396 public final ComponentName component;
397 public final String callId;
398 public final String callerDisplayName;
399
400 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
401 String callerDisplayName) {
402 this.component = component;
403 this.callId = callId;
404 this.callerDisplayName = callerDisplayName;
405 }
406 }
407
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700408 /**
409 * A handler that processes messages on the main thread in the phone process. Since many
410 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
411 * inbound binder threads to the main thread in the phone process. The Binder thread
412 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
413 * on, which will be notified when the operation completes and will contain the result of the
414 * request.
415 *
416 * <p>If a MainThreadRequest object is provided in the msg.obj field,
417 * note that request.result must be set to something non-null for the calling thread to
418 * unblock.
419 */
420 private final class MainThreadHandler extends Handler {
421 @Override
422 public void handleMessage(Message msg) {
423 MainThreadRequest request;
424 Message onCompleted;
425 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800426 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700427 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800428 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700429
430 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700431 case CMD_HANDLE_USSD_REQUEST: {
432 request = (MainThreadRequest) msg.obj;
433 final Phone phone = getPhoneFromRequest(request);
434 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
435 String ussdRequest = ussdObject.first;
436 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700437
Pengquan Menga1bb6272018-09-06 09:59:22 -0700438 if (!isUssdApiAllowed(request.subId)) {
439 // Carrier does not support use of this API, return failure.
440 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
441 UssdResponse response = new UssdResponse(ussdRequest, null);
442 Bundle returnData = new Bundle();
443 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
444 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700445
Pengquan Menga1bb6272018-09-06 09:59:22 -0700446 request.result = true;
447 notifyRequester(request);
448 return;
449 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700450
Pengquan Menga1bb6272018-09-06 09:59:22 -0700451 try {
452 request.result = phone != null
453 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
454 } catch (CallStateException cse) {
455 request.result = false;
456 }
457 // Wake up the requesting thread
458 notifyRequester(request);
459 break;
pkanwar32d516d2016-10-14 19:37:38 -0700460 }
461
Yorke Lee716f67e2015-06-17 15:39:16 -0700462 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700463 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700464 final Phone phone = getPhoneFromRequest(request);
465 request.result = phone != null ?
466 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
467 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700468 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700469 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700470 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700471 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700472
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700473 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700474 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700475 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800476 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700477 if (uiccCard == null) {
478 loge("iccTransmitApduLogicalChannel: No UICC");
479 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700480 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700481 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700482 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
483 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700484 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700485 iccArgument.channel, iccArgument.cla, iccArgument.command,
486 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700487 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700488 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700489 break;
490
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700491 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700492 ar = (AsyncResult) msg.obj;
493 request = (MainThreadRequest) ar.userObj;
494 if (ar.exception == null && ar.result != null) {
495 request.result = ar.result;
496 } else {
497 request.result = new IccIoResult(0x6F, 0, (byte[])null);
498 if (ar.result == null) {
499 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800500 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700501 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800502 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700503 } else {
504 loge("iccTransmitApduLogicalChannel: Unknown exception");
505 }
506 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700507 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700508 break;
509
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700510 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
511 request = (MainThreadRequest) msg.obj;
512 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800513 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700514 if (uiccCard == null) {
515 loge("iccTransmitApduBasicChannel: No UICC");
516 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700517 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700518 } else {
519 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
520 request);
521 uiccCard.iccTransmitApduBasicChannel(
522 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
523 iccArgument.p3, iccArgument.data, onCompleted);
524 }
525 break;
526
527 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
528 ar = (AsyncResult) msg.obj;
529 request = (MainThreadRequest) ar.userObj;
530 if (ar.exception == null && ar.result != null) {
531 request.result = ar.result;
532 } else {
533 request.result = new IccIoResult(0x6F, 0, (byte[])null);
534 if (ar.result == null) {
535 loge("iccTransmitApduBasicChannel: Empty response");
536 } else if (ar.exception instanceof CommandException) {
537 loge("iccTransmitApduBasicChannel: CommandException: " +
538 ar.exception);
539 } else {
540 loge("iccTransmitApduBasicChannel: Unknown exception");
541 }
542 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700543 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700544 break;
545
546 case CMD_EXCHANGE_SIM_IO:
547 request = (MainThreadRequest) msg.obj;
548 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800549 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700550 if (uiccCard == null) {
551 loge("iccExchangeSimIO: No UICC");
552 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700553 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700554 } else {
555 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
556 request);
557 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
558 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
559 iccArgument.data, onCompleted);
560 }
561 break;
562
563 case EVENT_EXCHANGE_SIM_IO_DONE:
564 ar = (AsyncResult) msg.obj;
565 request = (MainThreadRequest) ar.userObj;
566 if (ar.exception == null && ar.result != null) {
567 request.result = ar.result;
568 } else {
569 request.result = new IccIoResult(0x6f, 0, (byte[])null);
570 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700571 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700572 break;
573
Derek Tan4d5e5c12014-02-04 11:54:58 -0800574 case CMD_SEND_ENVELOPE:
575 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800576 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700577 if (uiccCard == null) {
578 loge("sendEnvelopeWithStatus: No UICC");
579 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700580 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700581 } else {
582 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
583 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
584 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800585 break;
586
587 case EVENT_SEND_ENVELOPE_DONE:
588 ar = (AsyncResult) msg.obj;
589 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700590 if (ar.exception == null && ar.result != null) {
591 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800592 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700593 request.result = new IccIoResult(0x6F, 0, (byte[])null);
594 if (ar.result == null) {
595 loge("sendEnvelopeWithStatus: Empty response");
596 } else if (ar.exception instanceof CommandException) {
597 loge("sendEnvelopeWithStatus: CommandException: " +
598 ar.exception);
599 } else {
600 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
601 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800602 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700603 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800604 break;
605
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 case CMD_OPEN_CHANNEL:
607 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800608 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800609 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700610 if (uiccCard == null) {
611 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800612 request.result = new IccOpenLogicalChannelResponse(-1,
613 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700614 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700615 } else {
616 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800617 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
618 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700619 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 break;
621
622 case EVENT_OPEN_CHANNEL_DONE:
623 ar = (AsyncResult) msg.obj;
624 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700625 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 int[] result = (int[]) ar.result;
628 int channelId = result[0];
629 byte[] selectResponse = null;
630 if (result.length > 1) {
631 selectResponse = new byte[result.length - 1];
632 for (int i = 1; i < result.length; ++i) {
633 selectResponse[i - 1] = (byte) result[i];
634 }
635 }
636 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700637 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700639 if (ar.result == null) {
640 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700641 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700642 if (ar.exception != null) {
643 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
644 }
645
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700646 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700647 if (ar.exception instanceof CommandException) {
648 CommandException.Error error =
649 ((CommandException) (ar.exception)).getCommandError();
650 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700651 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700652 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700653 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700654 }
655 }
656 openChannelResp = new IccOpenLogicalChannelResponse(
657 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700658 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700659 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700660 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 break;
662
663 case CMD_CLOSE_CHANNEL:
664 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800665 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700666 if (uiccCard == null) {
667 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900668 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700669 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700670 } else {
671 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
672 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
673 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 break;
675
676 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800677 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
678 break;
679
680 case CMD_NV_READ_ITEM:
681 request = (MainThreadRequest) msg.obj;
682 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800683 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
684 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800685 break;
686
687 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 ar = (AsyncResult) msg.obj;
689 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800690 if (ar.exception == null && ar.result != null) {
691 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800693 request.result = "";
694 if (ar.result == null) {
695 loge("nvReadItem: Empty response");
696 } else if (ar.exception instanceof CommandException) {
697 loge("nvReadItem: CommandException: " +
698 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700699 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800700 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700701 }
702 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700703 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700704 break;
705
Jake Hambye994d462014-02-03 13:10:13 -0800706 case CMD_NV_WRITE_ITEM:
707 request = (MainThreadRequest) msg.obj;
708 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
709 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800710 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700711 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800712 break;
713
714 case EVENT_NV_WRITE_ITEM_DONE:
715 handleNullReturnEvent(msg, "nvWriteItem");
716 break;
717
718 case CMD_NV_WRITE_CDMA_PRL:
719 request = (MainThreadRequest) msg.obj;
720 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800721 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800722 break;
723
724 case EVENT_NV_WRITE_CDMA_PRL_DONE:
725 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
726 break;
727
chen xu6dac5ab2018-10-26 17:39:23 -0700728 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800729 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700730 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800731 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800732 break;
733
chen xu6dac5ab2018-10-26 17:39:23 -0700734 case EVENT_RESET_MODEM_CONFIG_DONE:
735 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800736 break;
737
Jake Hamby7c27be32014-03-03 13:25:59 -0800738 case CMD_GET_PREFERRED_NETWORK_TYPE:
739 request = (MainThreadRequest) msg.obj;
740 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700741 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800742 break;
743
744 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
745 ar = (AsyncResult) msg.obj;
746 request = (MainThreadRequest) ar.userObj;
747 if (ar.exception == null && ar.result != null) {
748 request.result = ar.result; // Integer
749 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800750 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800751 if (ar.result == null) {
752 loge("getPreferredNetworkType: Empty response");
753 } else if (ar.exception instanceof CommandException) {
754 loge("getPreferredNetworkType: CommandException: " +
755 ar.exception);
756 } else {
757 loge("getPreferredNetworkType: Unknown exception");
758 }
759 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700760 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800761 break;
762
763 case CMD_SET_PREFERRED_NETWORK_TYPE:
764 request = (MainThreadRequest) msg.obj;
765 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
766 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700767 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800768 break;
769
770 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
771 handleNullReturnEvent(msg, "setPreferredNetworkType");
772 break;
773
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000774 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
775 request = (MainThreadRequest)msg.obj;
776 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800777 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000778 break;
779
780 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
781 ar = (AsyncResult)msg.obj;
782 request = (MainThreadRequest)ar.userObj;
783 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700784 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000785 break;
786
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800787 case CMD_SET_VOICEMAIL_NUMBER:
788 request = (MainThreadRequest) msg.obj;
789 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
790 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800791 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
792 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800793 break;
794
795 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
796 handleNullReturnEvent(msg, "setVoicemailNumber");
797 break;
798
Stuart Scott54788802015-03-30 13:18:01 -0700799 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
800 request = (MainThreadRequest) msg.obj;
801 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
802 request);
803 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
804 break;
805
806 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
807 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
808 break;
809
Shishir Agrawal302c8692015-06-19 13:49:39 -0700810 case CMD_PERFORM_NETWORK_SCAN:
811 request = (MainThreadRequest) msg.obj;
812 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
813 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
814 break;
815
sqian80370722020-01-29 15:02:51 -0800816 case CMD_GET_CALL_FORWARDING:
817 request = (MainThreadRequest) msg.obj;
818 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
819 int callForwardingReason = (Integer) request.argument;
820 getPhoneFromRequest(request).getCallForwardingOption(
821 callForwardingReason, onCompleted);
822 break;
823
824 case EVENT_GET_CALL_FORWARDING_DONE:
825 ar = (AsyncResult) msg.obj;
826 request = (MainThreadRequest) ar.userObj;
827 CallForwardingInfo callForwardingInfo = null;
828 if (ar.exception == null && ar.result != null) {
829 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
830 for (CallForwardInfo callForwardInfo : callForwardInfos) {
831 // Service Class is a bit mask per 3gpp 27.007. Search for
832 // any service for voice call.
833 if ((callForwardInfo.serviceClass
834 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
835 callForwardingInfo = new CallForwardingInfo(
836 callForwardInfo.serviceClass, callForwardInfo.reason,
837 callForwardInfo.number,
838 callForwardInfo.timeSeconds);
839 break;
840 }
841 }
842 // Didn't find a call forward info for voice call.
843 if (callForwardingInfo == null) {
844 callForwardingInfo = new CallForwardingInfo(
845 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
846 0 /* reason */, null /* number */, 0 /* timeout */);
847 }
848 } else {
849 if (ar.result == null) {
850 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
851 }
852 if (ar.exception != null) {
853 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
854 }
855 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
856 if (ar.exception instanceof CommandException) {
857 CommandException.Error error =
858 ((CommandException) (ar.exception)).getCommandError();
859 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
860 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
861 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
862 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
863 }
864 }
865 callForwardingInfo = new CallForwardingInfo(
866 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
867 }
868 request.result = callForwardingInfo;
869 notifyRequester(request);
870 break;
871
872 case CMD_SET_CALL_FORWARDING:
873 request = (MainThreadRequest) msg.obj;
874 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
875 CallForwardingInfo callForwardingInfoToSet =
876 (CallForwardingInfo) request.argument;
877 getPhoneFromRequest(request).setCallForwardingOption(
878 callForwardingInfoToSet.getStatus(),
879 callForwardingInfoToSet.getReason(),
880 callForwardingInfoToSet.getNumber(),
881 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
882 break;
883
884 case EVENT_SET_CALL_FORWARDING_DONE:
885 ar = (AsyncResult) msg.obj;
886 request = (MainThreadRequest) ar.userObj;
887 if (ar.exception == null) {
888 request.result = true;
889 } else {
890 request.result = false;
891 loge("setCallForwarding exception: " + ar.exception);
892 }
893 notifyRequester(request);
894 break;
895
896 case CMD_GET_CALL_WAITING:
897 request = (MainThreadRequest) msg.obj;
898 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
899 getPhoneFromRequest(request).getCallWaiting(onCompleted);
900 break;
901
902 case EVENT_GET_CALL_WAITING_DONE:
903 ar = (AsyncResult) msg.obj;
904 request = (MainThreadRequest) ar.userObj;
905 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
906 if (ar.exception == null && ar.result != null) {
907 ArrayList<Integer> callForwardResults = (ArrayList<Integer>) ar.result;
908 // Service Class is a bit mask per 3gpp 27.007.
909 // Search for any service for voice call.
910 if ((callForwardResults.get(1)
911 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
912 callForwardingStatus = callForwardResults.get(0) == 0
913 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
914 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
915 } else {
916 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
917 }
918 } else {
919 if (ar.result == null) {
920 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
921 }
922 if (ar.exception != null) {
923 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
924 }
925 if (ar.exception instanceof CommandException) {
926 CommandException.Error error =
927 ((CommandException) (ar.exception)).getCommandError();
928 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
929 callForwardingStatus =
930 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
931 }
932 }
933 }
934 request.result = callForwardingStatus;
935 notifyRequester(request);
936 break;
937
938 case CMD_SET_CALL_WAITING:
939 request = (MainThreadRequest) msg.obj;
940 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
941 boolean isEnable = (Boolean) request.argument;
942 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
943 break;
944
945 case EVENT_SET_CALL_WAITING_DONE:
946 ar = (AsyncResult) msg.obj;
947 request = (MainThreadRequest) ar.userObj;
948 if (ar.exception == null) {
949 request.result = true;
950 } else {
951 request.result = false;
952 loge("setCallWaiting exception: " + ar.exception);
953 }
954 notifyRequester(request);
955 break;
956
Shishir Agrawal302c8692015-06-19 13:49:39 -0700957 case EVENT_PERFORM_NETWORK_SCAN_DONE:
958 ar = (AsyncResult) msg.obj;
959 request = (MainThreadRequest) ar.userObj;
960 CellNetworkScanResult cellScanResult;
961 if (ar.exception == null && ar.result != null) {
962 cellScanResult = new CellNetworkScanResult(
963 CellNetworkScanResult.STATUS_SUCCESS,
964 (List<OperatorInfo>) ar.result);
965 } else {
966 if (ar.result == null) {
967 loge("getCellNetworkScanResults: Empty response");
968 }
969 if (ar.exception != null) {
970 loge("getCellNetworkScanResults: Exception: " + ar.exception);
971 }
972 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
973 if (ar.exception instanceof CommandException) {
974 CommandException.Error error =
975 ((CommandException) (ar.exception)).getCommandError();
976 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
977 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
978 } else if (error == CommandException.Error.GENERIC_FAILURE) {
979 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
980 }
981 }
982 cellScanResult = new CellNetworkScanResult(errorCode, null);
983 }
984 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700985 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700986 break;
987
988 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
989 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700990 ManualNetworkSelectionArgument selArg =
991 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700992 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
993 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700994 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
995 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700996 break;
997
998 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700999 ar = (AsyncResult) msg.obj;
1000 request = (MainThreadRequest) ar.userObj;
1001 if (ar.exception == null) {
1002 request.result = true;
1003 } else {
1004 request.result = false;
1005 loge("setNetworkSelectionModeManual " + ar.exception);
1006 }
1007 notifyRequester(request);
1008 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001009 break;
1010
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001011 case CMD_GET_MODEM_ACTIVITY_INFO:
1012 request = (MainThreadRequest) msg.obj;
1013 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001014 if (defaultPhone != null) {
1015 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
1016 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001017 break;
1018
1019 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1020 ar = (AsyncResult) msg.obj;
1021 request = (MainThreadRequest) ar.userObj;
1022 if (ar.exception == null && ar.result != null) {
1023 request.result = ar.result;
1024 } else {
1025 if (ar.result == null) {
1026 loge("queryModemActivityInfo: Empty response");
1027 } else if (ar.exception instanceof CommandException) {
1028 loge("queryModemActivityInfo: CommandException: " +
1029 ar.exception);
1030 } else {
1031 loge("queryModemActivityInfo: Unknown exception");
1032 }
1033 }
Amit Mahajand4766222016-01-28 15:28:28 -08001034 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
1035 if (request.result == null) {
Chen Xu13851032019-09-10 18:49:52 -07001036 request.result = new ModemActivityInfo(0, 0, 0, null, 0);
Amit Mahajand4766222016-01-28 15:28:28 -08001037 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001038 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001039 break;
1040
Meng Wang1a7c35a2016-05-05 20:56:15 -07001041 case CMD_SET_ALLOWED_CARRIERS:
1042 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001043 CarrierRestrictionRules argument =
1044 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001045 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001046 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001047 break;
1048
1049 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1050 ar = (AsyncResult) msg.obj;
1051 request = (MainThreadRequest) ar.userObj;
1052 if (ar.exception == null && ar.result != null) {
1053 request.result = ar.result;
1054 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001055 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1056 if (ar.exception instanceof CommandException) {
1057 loge("setAllowedCarriers: CommandException: " + ar.exception);
1058 CommandException.Error error =
1059 ((CommandException) (ar.exception)).getCommandError();
1060 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1061 request.result =
1062 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1063 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001064 } else {
1065 loge("setAllowedCarriers: Unknown exception");
1066 }
1067 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001068 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001069 break;
1070
1071 case CMD_GET_ALLOWED_CARRIERS:
1072 request = (MainThreadRequest) msg.obj;
1073 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001074 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001075 break;
1076
1077 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1078 ar = (AsyncResult) msg.obj;
1079 request = (MainThreadRequest) ar.userObj;
1080 if (ar.exception == null && ar.result != null) {
1081 request.result = ar.result;
1082 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001083 request.result = new IllegalStateException(
1084 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001085 if (ar.result == null) {
1086 loge("getAllowedCarriers: Empty response");
1087 } else if (ar.exception instanceof CommandException) {
1088 loge("getAllowedCarriers: CommandException: " +
1089 ar.exception);
1090 } else {
1091 loge("getAllowedCarriers: Unknown exception");
1092 }
1093 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001094 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001095 break;
1096
Nathan Haroldb3014052017-01-25 15:57:32 -08001097 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1098 ar = (AsyncResult) msg.obj;
1099 request = (MainThreadRequest) ar.userObj;
1100 if (ar.exception == null && ar.result != null) {
1101 request.result = ar.result;
1102 } else {
1103 request.result = new IllegalArgumentException(
1104 "Failed to retrieve Forbidden Plmns");
1105 if (ar.result == null) {
1106 loge("getForbiddenPlmns: Empty response");
1107 } else {
1108 loge("getForbiddenPlmns: Unknown exception");
1109 }
1110 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001111 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001112 break;
1113
1114 case CMD_GET_FORBIDDEN_PLMNS:
1115 request = (MainThreadRequest) msg.obj;
1116 uiccCard = getUiccCardFromRequest(request);
1117 if (uiccCard == null) {
1118 loge("getForbiddenPlmns() UiccCard is null");
1119 request.result = new IllegalArgumentException(
1120 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001121 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001122 break;
1123 }
1124 Integer appType = (Integer) request.argument;
1125 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1126 if (uiccApp == null) {
1127 loge("getForbiddenPlmns() no app with specified type -- "
1128 + appType);
1129 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001130 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001131 break;
1132 } else {
1133 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1134 + " specified type -- " + appType);
1135 }
1136 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1137 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1138 onCompleted);
1139 break;
1140
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001141 case CMD_SWITCH_SLOTS:
1142 request = (MainThreadRequest) msg.obj;
1143 int[] physicalSlots = (int[]) request.argument;
1144 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1145 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1146 break;
1147
1148 case EVENT_SWITCH_SLOTS_DONE:
1149 ar = (AsyncResult) msg.obj;
1150 request = (MainThreadRequest) ar.userObj;
1151 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001152 notifyRequester(request);
1153 break;
1154 case CMD_GET_NETWORK_SELECTION_MODE:
1155 request = (MainThreadRequest) msg.obj;
1156 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1157 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1158 break;
1159
1160 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1161 ar = (AsyncResult) msg.obj;
1162 request = (MainThreadRequest) ar.userObj;
1163 if (ar.exception != null) {
1164 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1165 } else {
1166 int mode = ((int[]) ar.result)[0];
1167 if (mode == 0) {
1168 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1169 } else {
1170 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1171 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001172 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001173 notifyRequester(request);
1174 break;
1175 case CMD_GET_CDMA_ROAMING_MODE:
1176 request = (MainThreadRequest) msg.obj;
1177 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1178 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1179 break;
1180 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1181 ar = (AsyncResult) msg.obj;
1182 request = (MainThreadRequest) ar.userObj;
1183 if (ar.exception != null) {
1184 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1185 } else {
1186 request.result = ((int[]) ar.result)[0];
1187 }
1188 notifyRequester(request);
1189 break;
1190 case CMD_SET_CDMA_ROAMING_MODE:
1191 request = (MainThreadRequest) msg.obj;
1192 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1193 int mode = (int) request.argument;
1194 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1195 break;
1196 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1197 ar = (AsyncResult) msg.obj;
1198 request = (MainThreadRequest) ar.userObj;
1199 request.result = ar.exception == null;
1200 notifyRequester(request);
1201 break;
1202 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1203 request = (MainThreadRequest) msg.obj;
1204 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1205 int subscriptionMode = (int) request.argument;
1206 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1207 break;
1208 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1209 ar = (AsyncResult) msg.obj;
1210 request = (MainThreadRequest) ar.userObj;
1211 request.result = ar.exception == null;
1212 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001213 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001214 case CMD_GET_ALL_CELL_INFO:
1215 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001216 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001217 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001218 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001219 case EVENT_GET_ALL_CELL_INFO_DONE:
1220 ar = (AsyncResult) msg.obj;
1221 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001222 // If a timeout occurs, the response will be null
1223 request.result = (ar.exception == null && ar.result != null)
1224 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001225 synchronized (request) {
1226 request.notifyAll();
1227 }
1228 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001229 case CMD_REQUEST_CELL_INFO_UPDATE:
1230 request = (MainThreadRequest) msg.obj;
1231 request.phone.requestCellInfoUpdate(request.workSource,
1232 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1233 break;
1234 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1235 ar = (AsyncResult) msg.obj;
1236 request = (MainThreadRequest) ar.userObj;
1237 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1238 try {
1239 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001240 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001241 cb.onError(
1242 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1243 ar.exception.getClass().getName(),
1244 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001245 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001246 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001247 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001248 } else {
1249 // use the result as returned
1250 cb.onCellInfo((List<CellInfo>) ar.result);
1251 }
1252 } catch (RemoteException re) {
1253 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1254 }
1255 break;
1256 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001257 request = (MainThreadRequest) msg.obj;
1258 WorkSource ws = (WorkSource) request.argument;
1259 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001260 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001261 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001262 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001263 ar = (AsyncResult) msg.obj;
1264 request = (MainThreadRequest) ar.userObj;
1265 if (ar.exception == null) {
1266 request.result = ar.result;
1267 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001268 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001269 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001270 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001271 }
1272
1273 synchronized (request) {
1274 request.notifyAll();
1275 }
1276 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001277 case CMD_MODEM_REBOOT:
1278 request = (MainThreadRequest) msg.obj;
1279 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001280 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001281 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001282 case EVENT_CMD_MODEM_REBOOT_DONE:
1283 handleNullReturnEvent(msg, "rebootModem");
1284 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001285 case CMD_REQUEST_ENABLE_MODEM:
1286 request = (MainThreadRequest) msg.obj;
1287 boolean enable = (boolean) request.argument;
1288 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001289 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001290 PhoneConfigurationManager.getInstance()
1291 .enablePhone(request.phone, enable, onCompleted);
1292 break;
1293 case EVENT_ENABLE_MODEM_DONE:
1294 ar = (AsyncResult) msg.obj;
1295 request = (MainThreadRequest) ar.userObj;
1296 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001297 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001298 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001299 if ((boolean) request.result) {
1300 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1301 updateModemStateMetrics();
1302 } else {
1303 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1304 + ar.exception);
1305 }
1306 notifyRequester(request);
1307 break;
1308 case CMD_GET_MODEM_STATUS:
1309 request = (MainThreadRequest) msg.obj;
1310 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1311 PhoneConfigurationManager.getInstance()
1312 .getPhoneStatusFromModem(request.phone, onCompleted);
1313 break;
1314 case EVENT_GET_MODEM_STATUS_DONE:
1315 ar = (AsyncResult) msg.obj;
1316 request = (MainThreadRequest) ar.userObj;
1317 int id = request.phone.getPhoneId();
1318 if (ar.exception == null && ar.result != null) {
1319 request.result = ar.result;
1320 //update the cache as modem status has changed
1321 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1322 (boolean) request.result);
1323 } else {
1324 // Return true if modem status cannot be retrieved. For most cases,
1325 // modem status is on. And for older version modems, GET_MODEM_STATUS
1326 // and disable modem are not supported. Modem is always on.
1327 // TODO: this should be fixed in R to support a third
1328 // status UNKNOWN b/131631629
1329 request.result = true;
1330 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1331 + ar.exception);
1332 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001333 notifyRequester(request);
1334 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001335 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1336 ar = (AsyncResult) msg.obj;
1337 request = (MainThreadRequest) ar.userObj;
1338 if (ar.exception == null && ar.result != null) {
1339 request.result = ar.result;
1340 } else {
1341 request.result = -1;
1342 loge("Failed to set Forbidden Plmns");
1343 if (ar.result == null) {
1344 loge("setForbidenPlmns: Empty response");
1345 } else if (ar.exception != null) {
1346 loge("setForbiddenPlmns: Exception: " + ar.exception);
1347 request.result = -1;
1348 } else {
1349 loge("setForbiddenPlmns: Unknown exception");
1350 }
1351 }
1352 notifyRequester(request);
1353 break;
1354 case CMD_SET_FORBIDDEN_PLMNS:
1355 request = (MainThreadRequest) msg.obj;
1356 uiccCard = getUiccCardFromRequest(request);
1357 if (uiccCard == null) {
1358 loge("setForbiddenPlmns: UiccCard is null");
1359 request.result = -1;
1360 notifyRequester(request);
1361 break;
1362 }
1363 Pair<Integer, List<String>> setFplmnsArgs =
1364 (Pair<Integer, List<String>>) request.argument;
1365 appType = setFplmnsArgs.first;
1366 List<String> fplmns = setFplmnsArgs.second;
1367 uiccApp = uiccCard.getApplicationByType(appType);
1368 if (uiccApp == null) {
1369 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1370 request.result = -1;
1371 loge("Failed to get UICC App");
1372 notifyRequester(request);
1373 } else {
1374 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1375 ((SIMRecords) uiccApp.getIccRecords())
1376 .setForbiddenPlmns(onCompleted, fplmns);
1377 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001378 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001379 case CMD_ERASE_MODEM_CONFIG:
1380 request = (MainThreadRequest) msg.obj;
1381 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1382 defaultPhone.eraseModemConfig(onCompleted);
1383 break;
1384 case EVENT_ERASE_MODEM_CONFIG_DONE:
1385 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001386 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001387 default:
1388 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1389 break;
1390 }
1391 }
Jake Hambye994d462014-02-03 13:10:13 -08001392
Pengquan Menga1bb6272018-09-06 09:59:22 -07001393 private void notifyRequester(MainThreadRequest request) {
1394 synchronized (request) {
1395 request.notifyAll();
1396 }
1397 }
1398
Jake Hambye994d462014-02-03 13:10:13 -08001399 private void handleNullReturnEvent(Message msg, String command) {
1400 AsyncResult ar = (AsyncResult) msg.obj;
1401 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1402 if (ar.exception == null) {
1403 request.result = true;
1404 } else {
1405 request.result = false;
1406 if (ar.exception instanceof CommandException) {
1407 loge(command + ": CommandException: " + ar.exception);
1408 } else {
1409 loge(command + ": Unknown exception");
1410 }
1411 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001412 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001413 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001414 }
1415
1416 /**
1417 * Posts the specified command to be executed on the main thread,
1418 * waits for the request to complete, and returns the result.
1419 * @see #sendRequestAsync
1420 */
1421 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001422 return sendRequest(
1423 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001424 }
1425
1426 /**
1427 * Posts the specified command to be executed on the main thread,
1428 * waits for the request to complete, and returns the result.
1429 * @see #sendRequestAsync
1430 */
1431 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1432 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001433 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001434 }
1435
1436 /**
1437 * Posts the specified command to be executed on the main thread,
1438 * waits for the request to complete, and returns the result.
1439 * @see #sendRequestAsync
1440 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001441 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001442 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001443 }
1444
1445 /**
1446 * Posts the specified command to be executed on the main thread,
1447 * waits for the request to complete, and returns the result.
1448 * @see #sendRequestAsync
1449 */
Nathan Harold92bed182018-10-12 18:16:49 -07001450 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1451 return sendRequest(command, argument, subId, null, workSource);
1452 }
1453
1454 /**
1455 * Posts the specified command to be executed on the main thread,
1456 * waits for the request to complete, and returns the result.
1457 * @see #sendRequestAsync
1458 */
1459 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1460 return sendRequest(
1461 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1462 }
1463
1464 /**
1465 * Posts the specified command to be executed on the main thread,
1466 * waits for the request to complete, and returns the result.
1467 * @see #sendRequestAsync
1468 */
1469 private Object sendRequest(
1470 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001471 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1472 throw new RuntimeException("This method will deadlock if called from the main thread.");
1473 }
1474
Nathan Harold92bed182018-10-12 18:16:49 -07001475 MainThreadRequest request = null;
1476 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1477 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1478 } else if (phone != null) {
1479 request = new MainThreadRequest(argument, phone, workSource);
1480 } else {
1481 request = new MainThreadRequest(argument, subId, workSource);
1482 }
1483
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001484 Message msg = mMainThreadHandler.obtainMessage(command, request);
1485 msg.sendToTarget();
1486
1487 // Wait for the request to complete
1488 synchronized (request) {
1489 while (request.result == null) {
1490 try {
1491 request.wait();
1492 } catch (InterruptedException e) {
1493 // Do nothing, go back and wait until the request is complete
1494 }
1495 }
1496 }
1497 return request.result;
1498 }
1499
1500 /**
1501 * Asynchronous ("fire and forget") version of sendRequest():
1502 * Posts the specified command to be executed on the main thread, and
1503 * returns immediately.
1504 * @see #sendRequest
1505 */
1506 private void sendRequestAsync(int command) {
1507 mMainThreadHandler.sendEmptyMessage(command);
1508 }
1509
1510 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001511 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001512 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001513 */
1514 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001515 sendRequestAsync(command, argument, null, null);
1516 }
1517
1518 /**
1519 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1520 * @see {@link #sendRequest(int,Object)}
1521 */
1522 private void sendRequestAsync(
1523 int command, Object argument, Phone phone, WorkSource workSource) {
1524 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001525 Message msg = mMainThreadHandler.obtainMessage(command, request);
1526 msg.sendToTarget();
1527 }
1528
1529 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001530 * Initialize the singleton PhoneInterfaceManager instance.
1531 * This is only done once, at startup, from PhoneApp.onCreate().
1532 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001533 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001534 synchronized (PhoneInterfaceManager.class) {
1535 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001536 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001537 } else {
1538 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1539 }
1540 return sInstance;
1541 }
1542 }
1543
1544 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001545 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001546 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001547 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001548 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001549 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001550 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1551 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001552 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001553 mTelephonySharedPreferences =
1554 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001555 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001556 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001557
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001558 publish();
1559 }
1560
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001561 private Phone getDefaultPhone() {
1562 Phone thePhone = getPhone(getDefaultSubscription());
1563 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1564 }
1565
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001566 private void publish() {
1567 if (DBG) log("publish: " + this);
1568
1569 ServiceManager.addService("phone", this);
1570 }
1571
Stuart Scott584921c2015-01-15 17:10:34 -08001572 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001573 if (request.phone != null) {
1574 return request.phone;
1575 } else {
1576 return getPhoneFromSubId(request.subId);
1577 }
1578 }
1579
1580 private Phone getPhoneFromSubId(int subId) {
1581 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1582 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001583 }
1584
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001585 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1586 Phone phone = getPhoneFromRequest(request);
1587 return phone == null ? null :
1588 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1589 }
1590
Wink Saville36469e72014-06-11 15:17:00 -07001591 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001592 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001593 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001594 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001595
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001596 private void sendEraseModemConfig(Phone phone) {
1597 if (phone != null) {
1598 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1599 mApp, phone.getSubId(), "eraseModemConfig");
1600 final long identity = Binder.clearCallingIdentity();
1601 try {
1602 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1603 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1604 } finally {
1605 Binder.restoreCallingIdentity(identity);
1606 }
1607 }
1608 }
1609
Peter Wang050bb052020-01-13 23:33:09 -08001610 private boolean isImsAvailableOnDevice() {
1611 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1612 if (pm == null) {
1613 // For some reason package manger is not available.. This will fail internally anyway,
1614 // so do not throw error and allow.
1615 return true;
1616 }
1617 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1618 }
1619
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001620 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001621 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001622 }
1623
Wink Savilleb564aae2014-10-23 10:18:09 -07001624 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001625 if (DBG) log("dial: " + number);
1626 // No permission check needed here: This is just a wrapper around the
1627 // ACTION_DIAL intent, which is available to any app since it puts up
1628 // the UI before it does anything.
1629
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001630 final long identity = Binder.clearCallingIdentity();
1631 try {
1632 String url = createTelUrl(number);
1633 if (url == null) {
1634 return;
1635 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001636
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001637 // PENDING: should we just silently fail if phone is offhook or ringing?
1638 PhoneConstants.State state = mCM.getState(subId);
1639 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1640 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1641 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1642 mApp.startActivity(intent);
1643 }
1644 } finally {
1645 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001646 }
1647 }
1648
1649 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001650 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001651 }
1652
Wink Savilleb564aae2014-10-23 10:18:09 -07001653 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654 if (DBG) log("call: " + number);
1655
1656 // This is just a wrapper around the ACTION_CALL intent, but we still
1657 // need to do a permission check since we're calling startActivity()
1658 // from the context of the phone app.
1659 enforceCallPermission();
1660
Jordan Liu1617b712019-07-10 15:06:26 -07001661 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001662 != AppOpsManager.MODE_ALLOWED) {
1663 return;
1664 }
1665
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001666 final long identity = Binder.clearCallingIdentity();
1667 try {
1668 String url = createTelUrl(number);
1669 if (url == null) {
1670 return;
1671 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001672
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001673 boolean isValid = false;
1674 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1675 if (slist != null) {
1676 for (SubscriptionInfo subInfoRecord : slist) {
1677 if (subInfoRecord.getSubscriptionId() == subId) {
1678 isValid = true;
1679 break;
1680 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001681 }
Wink Saville08874612014-08-31 19:19:58 -07001682 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001683 if (!isValid) {
1684 return;
1685 }
Wink Saville08874612014-08-31 19:19:58 -07001686
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001687 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1688 intent.putExtra(SUBSCRIPTION_KEY, subId);
1689 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1690 mApp.startActivity(intent);
1691 } finally {
1692 Binder.restoreCallingIdentity(identity);
1693 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001694 }
1695
Wink Savilleb564aae2014-10-23 10:18:09 -07001696 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001697 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001698 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1699 }
1700
Wink Savilleb564aae2014-10-23 10:18:09 -07001701 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001702 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001703 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1704 }
1705
Wink Savilleb564aae2014-10-23 10:18:09 -07001706 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001707 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001708
1709 final long identity = Binder.clearCallingIdentity();
1710 try {
1711 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1712 checkSimPin.start();
1713 return checkSimPin.unlockSim(null, pin);
1714 } finally {
1715 Binder.restoreCallingIdentity(identity);
1716 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001717 }
1718
Wink Savilleb564aae2014-10-23 10:18:09 -07001719 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001720 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001721
1722 final long identity = Binder.clearCallingIdentity();
1723 try {
1724 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1725 checkSimPuk.start();
1726 return checkSimPuk.unlockSim(puk, pin);
1727 } finally {
1728 Binder.restoreCallingIdentity(identity);
1729 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001730 }
1731
1732 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001733 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 * a synchronous one.
1735 */
1736 private static class UnlockSim extends Thread {
1737
1738 private final IccCard mSimCard;
1739
1740 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001741 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1742 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001743
1744 // For replies from SimCard interface
1745 private Handler mHandler;
1746
1747 // For async handler to identify request type
1748 private static final int SUPPLY_PIN_COMPLETE = 100;
1749
1750 public UnlockSim(IccCard simCard) {
1751 mSimCard = simCard;
1752 }
1753
1754 @Override
1755 public void run() {
1756 Looper.prepare();
1757 synchronized (UnlockSim.this) {
1758 mHandler = new Handler() {
1759 @Override
1760 public void handleMessage(Message msg) {
1761 AsyncResult ar = (AsyncResult) msg.obj;
1762 switch (msg.what) {
1763 case SUPPLY_PIN_COMPLETE:
1764 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1765 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001766 mRetryCount = msg.arg1;
1767 if (ar.exception != null) {
1768 if (ar.exception instanceof CommandException &&
1769 ((CommandException)(ar.exception)).getCommandError()
1770 == CommandException.Error.PASSWORD_INCORRECT) {
1771 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1772 } else {
1773 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1774 }
1775 } else {
1776 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1777 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001778 mDone = true;
1779 UnlockSim.this.notifyAll();
1780 }
1781 break;
1782 }
1783 }
1784 };
1785 UnlockSim.this.notifyAll();
1786 }
1787 Looper.loop();
1788 }
1789
1790 /*
1791 * Use PIN or PUK to unlock SIM card
1792 *
1793 * If PUK is null, unlock SIM card with PIN
1794 *
1795 * If PUK is not null, unlock SIM card with PUK and set PIN code
1796 */
Wink Saville9de0f752013-10-22 19:04:03 -07001797 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001798
1799 while (mHandler == null) {
1800 try {
1801 wait();
1802 } catch (InterruptedException e) {
1803 Thread.currentThread().interrupt();
1804 }
1805 }
1806 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1807
1808 if (puk == null) {
1809 mSimCard.supplyPin(pin, callback);
1810 } else {
1811 mSimCard.supplyPuk(puk, pin, callback);
1812 }
1813
1814 while (!mDone) {
1815 try {
1816 Log.d(LOG_TAG, "wait for done");
1817 wait();
1818 } catch (InterruptedException e) {
1819 // Restore the interrupted status
1820 Thread.currentThread().interrupt();
1821 }
1822 }
1823 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001824 int[] resultArray = new int[2];
1825 resultArray[0] = mResult;
1826 resultArray[1] = mRetryCount;
1827 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 }
1829 }
1830
1831 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001832 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001833
1834 }
1835
Wink Savilleb564aae2014-10-23 10:18:09 -07001836 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001837 // No permission check needed here: this call is harmless, and it's
1838 // needed for the ServiceState.requestStateUpdate() call (which is
1839 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001840 final long identity = Binder.clearCallingIdentity();
1841 try {
1842 final Phone phone = getPhone(subId);
1843 if (phone != null) {
1844 phone.updateServiceLocation();
1845 }
1846 } finally {
1847 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001848 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001849 }
1850
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001851 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001852 @Override
1853 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001854 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001855 }
1856
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001857 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001858 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1859 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1860 callingFeatureId);
1861 }
1862
1863 @Deprecated
1864 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001865 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001866 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
1867 }
1868
1869 @Override
1870 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1871 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001872 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001873 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001874 return false;
1875 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001876
1877 final long identity = Binder.clearCallingIdentity();
1878 try {
1879 return isRadioOnForSubscriber(subId);
1880 } finally {
1881 Binder.restoreCallingIdentity(identity);
1882 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001883 }
1884
1885 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001886 final long identity = Binder.clearCallingIdentity();
1887 try {
1888 final Phone phone = getPhone(subId);
1889 if (phone != null) {
1890 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1891 } else {
1892 return false;
1893 }
1894 } finally {
1895 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001896 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 }
1898
1899 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001900 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001901 }
Wink Saville36469e72014-06-11 15:17:00 -07001902
Wink Savilleb564aae2014-10-23 10:18:09 -07001903 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001904 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001905
1906 final long identity = Binder.clearCallingIdentity();
1907 try {
1908 final Phone phone = getPhone(subId);
1909 if (phone != null) {
1910 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1911 }
1912 } finally {
1913 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001914 }
Wink Saville36469e72014-06-11 15:17:00 -07001915 }
1916
1917 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001918 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001919 }
1920
Wink Savilleb564aae2014-10-23 10:18:09 -07001921 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001922 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001923
1924 final long identity = Binder.clearCallingIdentity();
1925 try {
1926 final Phone phone = getPhone(subId);
1927 if (phone == null) {
1928 return false;
1929 }
1930 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1931 toggleRadioOnOffForSubscriber(subId);
1932 }
1933 return true;
1934 } finally {
1935 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001936 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001937 }
Wink Saville36469e72014-06-11 15:17:00 -07001938
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001939 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08001940 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001941 /*
1942 * If any of the Radios are available, it will need to be
1943 * shutdown. So return true if any Radio is available.
1944 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001945 final long identity = Binder.clearCallingIdentity();
1946 try {
1947 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1948 Phone phone = PhoneFactory.getPhone(i);
1949 if (phone != null && phone.isRadioAvailable()) return true;
1950 }
1951 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1952 return false;
1953 } finally {
1954 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001955 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001956 }
1957
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001958 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001959 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001960 enforceModifyPermission();
1961
1962 final long identity = Binder.clearCallingIdentity();
1963 try {
1964 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1965 logv("Shutting down Phone " + i);
1966 shutdownRadioUsingPhoneId(i);
1967 }
1968 } finally {
1969 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001970 }
1971 }
1972
1973 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001974 Phone phone = PhoneFactory.getPhone(phoneId);
1975 if (phone != null && phone.isRadioAvailable()) {
1976 phone.shutdownRadio();
1977 }
1978 }
1979
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001980 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001981 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001982
1983 final long identity = Binder.clearCallingIdentity();
1984 try {
1985 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1986 if (defaultPhone != null) {
1987 defaultPhone.setRadioPower(turnOn);
1988 return true;
1989 } else {
1990 loge("There's no default phone.");
1991 return false;
1992 }
1993 } finally {
1994 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001995 }
Wink Saville36469e72014-06-11 15:17:00 -07001996 }
1997
Wink Savilleb564aae2014-10-23 10:18:09 -07001998 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002000
2001 final long identity = Binder.clearCallingIdentity();
2002 try {
2003 final Phone phone = getPhone(subId);
2004 if (phone != null) {
2005 phone.setRadioPower(turnOn);
2006 return true;
2007 } else {
2008 return false;
2009 }
2010 } finally {
2011 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002012 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002013 }
2014
Wink Saville36469e72014-06-11 15:17:00 -07002015 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002016 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 public boolean enableDataConnectivity() {
2018 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002019
2020 final long identity = Binder.clearCallingIdentity();
2021 try {
2022 int subId = mSubscriptionController.getDefaultDataSubId();
2023 final Phone phone = getPhone(subId);
2024 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002025 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002026 return true;
2027 } else {
2028 return false;
2029 }
2030 } finally {
2031 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002032 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002033 }
2034
Wink Saville36469e72014-06-11 15:17:00 -07002035 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002036 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002037 public boolean disableDataConnectivity() {
2038 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002039
2040 final long identity = Binder.clearCallingIdentity();
2041 try {
2042 int subId = mSubscriptionController.getDefaultDataSubId();
2043 final Phone phone = getPhone(subId);
2044 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002045 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002046 return true;
2047 } else {
2048 return false;
2049 }
2050 } finally {
2051 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002052 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002053 }
2054
Sanket Padawe356d7632015-06-22 14:03:32 -07002055 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002056 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002057 final long identity = Binder.clearCallingIdentity();
2058 try {
2059 final Phone phone = getPhone(subId);
2060 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002061 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002062 } else {
2063 return false;
2064 }
2065 } finally {
2066 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002067 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002068 }
2069
2070 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002071 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002072 }
2073
pkanwarae03a6b2016-11-06 20:37:09 -08002074 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002075 enforceCallPermission();
2076
2077 final long identity = Binder.clearCallingIdentity();
2078 try {
2079 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2080 return;
2081 }
2082 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2083 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2084 } finally {
2085 Binder.restoreCallingIdentity(identity);
2086 }
pkanwar32d516d2016-10-14 19:37:38 -07002087 };
2088
Wink Savilleb564aae2014-10-23 10:18:09 -07002089 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002090 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002091
2092 final long identity = Binder.clearCallingIdentity();
2093 try {
2094 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2095 return false;
2096 }
2097 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2098 } finally {
2099 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002100 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002101 }
2102
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002103 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002104 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002105 }
2106
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002107 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002108 final long identity = Binder.clearCallingIdentity();
2109 try {
2110 Phone phone = PhoneFactory.getPhone(slotIndex);
2111 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2112 PhoneConstantConversions.convertCallState(phone.getState());
2113 } finally {
2114 Binder.restoreCallingIdentity(identity);
2115 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002116 }
2117
Sanket Padawe356d7632015-06-22 14:03:32 -07002118 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002119 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002120 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2121 }
2122
2123 @Override
2124 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002125 final long identity = Binder.clearCallingIdentity();
2126 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002127 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002128 if (phone != null) {
2129 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2130 } else {
2131 return PhoneConstantConversions.convertDataState(
2132 PhoneConstants.DataState.DISCONNECTED);
2133 }
2134 } finally {
2135 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002136 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002137 }
2138
Sanket Padawe356d7632015-06-22 14:03:32 -07002139 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002140 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002141 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2142 }
2143
2144 @Override
2145 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002146 final long identity = Binder.clearCallingIdentity();
2147 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002148 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002149 if (phone != null) {
2150 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2151 } else {
2152 return TelephonyManager.DATA_ACTIVITY_NONE;
2153 }
2154 } finally {
2155 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002156 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002157 }
2158
2159 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002160 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002161 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002162 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002163
2164 LocationAccessPolicy.LocationPermissionResult locationResult =
2165 LocationAccessPolicy.checkLocationPermission(mApp,
2166 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2167 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002168 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002169 .setCallingPid(Binder.getCallingPid())
2170 .setCallingUid(Binder.getCallingUid())
2171 .setMethod("getCellLocation")
2172 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2173 .build());
2174 switch (locationResult) {
2175 case DENIED_HARD:
2176 throw new SecurityException("Not allowed to access cell location");
2177 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002178 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2179 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002180 }
2181
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002182 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002183 final long identity = Binder.clearCallingIdentity();
2184 try {
2185 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002186 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002187 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002188 } finally {
2189 Binder.restoreCallingIdentity(identity);
2190 }
Svetoslav64fad262015-04-14 14:35:21 -07002191 }
2192
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002193 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002194 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2195 String callingFeatureId) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002196 if (!TextUtils.isEmpty(callingPackage)) {
2197 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002198 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2199 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002200 return "";
2201 }
2202 }
2203
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002204 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2205 // registered cell info, so return a NULL country instead.
2206 final long identity = Binder.clearCallingIdentity();
2207 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002208 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2209 // Get default phone in this case.
2210 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2211 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002212 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002213 // Todo: fix this when we can get the actual cellular network info when the device
2214 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002215 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002216 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2217 null)) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002218 return "";
2219 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002220 Phone phone = PhoneFactory.getPhone(phoneId);
2221 if (phone != null) {
2222 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002223 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002224 if (sst != null) {
2225 LocaleTracker lt = sst.getLocaleTracker();
2226 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002227 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2228 return lt.getCurrentCountry();
2229 } else if (emergencyNumberTracker != null) {
2230 return emergencyNumberTracker.getEmergencyCountryIso();
2231 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002232 }
2233 }
2234 }
2235 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002236 } finally {
2237 Binder.restoreCallingIdentity(identity);
2238 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002239 }
2240
2241 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002243 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002244 }
2245
Sanket Padawe356d7632015-06-22 14:03:32 -07002246 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002247 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002248 mApp.enforceCallingOrSelfPermission(
2249 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002250
2251 final long identity = Binder.clearCallingIdentity();
2252 try {
2253 final Phone phone = getPhone(subId);
2254 if (phone != null) {
2255 phone.enableLocationUpdates();
2256 }
2257 } finally {
2258 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002259 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002260 }
2261
2262 @Override
2263 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002264 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002265 }
2266
Sanket Padawe356d7632015-06-22 14:03:32 -07002267 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002268 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002269 mApp.enforceCallingOrSelfPermission(
2270 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002271
2272 final long identity = Binder.clearCallingIdentity();
2273 try {
2274 final Phone phone = getPhone(subId);
2275 if (phone != null) {
2276 phone.disableLocationUpdates();
2277 }
2278 } finally {
2279 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002280 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281 }
2282
Nathan Harold31d7ff32018-10-15 20:20:30 -07002283 /**
2284 * Returns the target SDK version number for a given package name.
2285 *
Nathan Haroldec184742019-07-10 17:04:16 -07002286 * This call MUST be invoked before clearing the calling UID.
2287 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002288 * @return target SDK if the package is found or INT_MAX.
2289 */
2290 private int getTargetSdk(String packageName) {
2291 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002292 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002293 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002294 if (ai != null) return ai.targetSdkVersion;
2295 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002296 loge("Failed to get package info for pkg="
2297 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002298 }
2299 return Integer.MAX_VALUE;
2300 }
2301
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002302 @Override
2303 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002304 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2305 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002306 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002307 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2308 throw new SecurityException(
2309 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2310 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002311
Jordan Liu1617b712019-07-10 15:06:26 -07002312 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002313 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2314 return null;
2315 }
Svetoslav64fad262015-04-14 14:35:21 -07002316
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002317 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002318
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002319 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002320 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002321
Nathan Haroldf180aac2018-06-01 18:43:55 -07002322 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2323 for (CellInfo ci : info) {
2324 if (ci instanceof CellInfoGsm) {
2325 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2326 } else if (ci instanceof CellInfoWcdma) {
2327 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2328 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002330 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 }
2332
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002333 private List<CellInfo> getCachedCellInfo() {
2334 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2335 for (Phone phone : PhoneFactory.getPhones()) {
2336 List<CellInfo> info = phone.getAllCellInfo();
2337 if (info != null) cellInfos.addAll(info);
2338 }
2339 return cellInfos;
2340 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002341
2342 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002343 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002344 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002345 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002346
2347 LocationAccessPolicy.LocationPermissionResult locationResult =
2348 LocationAccessPolicy.checkLocationPermission(mApp,
2349 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2350 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002351 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002352 .setCallingPid(Binder.getCallingPid())
2353 .setCallingUid(Binder.getCallingUid())
2354 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002355 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002356 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2357 .build());
2358 switch (locationResult) {
2359 case DENIED_HARD:
2360 throw new SecurityException("Not allowed to access cell info");
2361 case DENIED_SOFT:
2362 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002363 }
2364
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002365 final int targetSdk = getTargetSdk(callingPackage);
2366 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2367 return getCachedCellInfo();
2368 }
2369
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002370 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002371 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002372 final long identity = Binder.clearCallingIdentity();
2373 try {
2374 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2375 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002376 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002377 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002378 if (info != null) cellInfos.addAll(info);
2379 }
2380 return cellInfos;
2381 } finally {
2382 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002383 }
2384 }
2385
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002386 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002387 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2388 String callingFeatureId) {
2389 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2390 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002391 }
2392
2393 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002394 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2395 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002396 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002397 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002398 }
2399
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002400 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2401 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002402 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002403 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002404
2405 LocationAccessPolicy.LocationPermissionResult locationResult =
2406 LocationAccessPolicy.checkLocationPermission(mApp,
2407 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2408 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002409 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002410 .setCallingPid(Binder.getCallingPid())
2411 .setCallingUid(Binder.getCallingUid())
2412 .setMethod("requestCellInfoUpdate")
2413 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2414 .build());
2415 switch (locationResult) {
2416 case DENIED_HARD:
2417 throw new SecurityException("Not allowed to access cell info");
2418 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002419 try {
2420 cb.onCellInfo(new ArrayList<CellInfo>());
2421 } catch (RemoteException re) {
2422 // Drop without consequences
2423 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002424 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002425 }
2426
Nathan Harolda939a962019-05-09 10:13:47 -07002427
2428 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002429 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2430
2431 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2432 }
2433
2434 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002436 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002437 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002438
2439 final long identity = Binder.clearCallingIdentity();
2440 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002441 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002442 } finally {
2443 Binder.restoreCallingIdentity(identity);
2444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 }
2446
Shishir Agrawala9f32182016-04-12 12:00:16 -07002447 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002448 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002449 Phone phone = PhoneFactory.getPhone(slotIndex);
2450 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002451 return null;
2452 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002453 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002454 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002455 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002456 return null;
2457 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002458
2459 final long identity = Binder.clearCallingIdentity();
2460 try {
2461 return phone.getImei();
2462 } finally {
2463 Binder.restoreCallingIdentity(identity);
2464 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002465 }
2466
2467 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002468 public String getTypeAllocationCodeForSlot(int slotIndex) {
2469 Phone phone = PhoneFactory.getPhone(slotIndex);
2470 String tac = null;
2471 if (phone != null) {
2472 String imei = phone.getImei();
2473 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2474 }
2475 return tac;
2476 }
2477
2478 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002479 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002480 Phone phone = PhoneFactory.getPhone(slotIndex);
2481 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002482 return null;
2483 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002484
Jeff Davidson913390f2018-02-23 17:11:49 -08002485 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002486 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002487 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002488 return null;
2489 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002490
2491 final long identity = Binder.clearCallingIdentity();
2492 try {
2493 return phone.getMeid();
2494 } finally {
2495 Binder.restoreCallingIdentity(identity);
2496 }
Jack Yu2af8d712017-03-15 17:14:14 -07002497 }
2498
2499 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002500 public String getManufacturerCodeForSlot(int slotIndex) {
2501 Phone phone = PhoneFactory.getPhone(slotIndex);
2502 String manufacturerCode = null;
2503 if (phone != null) {
2504 String meid = phone.getMeid();
2505 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2506 }
2507 return manufacturerCode;
2508 }
2509
2510 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002511 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2512 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002513 Phone phone = PhoneFactory.getPhone(slotIndex);
2514 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002515 return null;
2516 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002517 int subId = phone.getSubId();
2518 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002519 mApp, subId, callingPackage, callingFeatureId,
2520 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002521 return null;
2522 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002523
2524 final long identity = Binder.clearCallingIdentity();
2525 try {
2526 return phone.getDeviceSvn();
2527 } finally {
2528 Binder.restoreCallingIdentity(identity);
2529 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002530 }
2531
fionaxu43304da2017-11-27 22:51:16 -08002532 @Override
2533 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002534 final long identity = Binder.clearCallingIdentity();
2535 try {
2536 final Phone phone = getPhone(subId);
2537 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2538 } finally {
2539 Binder.restoreCallingIdentity(identity);
2540 }
fionaxu43304da2017-11-27 22:51:16 -08002541 }
2542
2543 @Override
2544 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002545 final long identity = Binder.clearCallingIdentity();
2546 try {
2547 final Phone phone = getPhone(subId);
2548 return phone == null ? null : phone.getCarrierName();
2549 } finally {
2550 Binder.restoreCallingIdentity(identity);
2551 }
fionaxu43304da2017-11-27 22:51:16 -08002552 }
2553
calvinpanffe225e2018-11-01 19:43:06 +08002554 @Override
chen xu0026ca62019-03-06 15:28:50 -08002555 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002556 final long identity = Binder.clearCallingIdentity();
2557 try {
2558 final Phone phone = getPhone(subId);
2559 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002560 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002561 } finally {
2562 Binder.restoreCallingIdentity(identity);
2563 }
2564 }
2565
2566 @Override
chen xu0026ca62019-03-06 15:28:50 -08002567 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002568 final long identity = Binder.clearCallingIdentity();
2569 try {
2570 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002571 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002572 } finally {
2573 Binder.restoreCallingIdentity(identity);
2574 }
2575 }
2576
chen xu651eec72018-11-11 19:03:44 -08002577 @Override
chen xu864e11c2018-12-06 22:10:03 -08002578 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2579 if (!isSubscriptionMccMnc) {
2580 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2581 }
chen xu651eec72018-11-11 19:03:44 -08002582 final Phone phone = PhoneFactory.getPhone(slotIndex);
2583 if (phone == null) {
2584 return TelephonyManager.UNKNOWN_CARRIER_ID;
2585 }
2586 final long identity = Binder.clearCallingIdentity();
2587 try {
2588 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2589 } finally {
2590 Binder.restoreCallingIdentity(identity);
2591 }
2592 }
2593
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002594 //
2595 // Internal helper methods.
2596 //
2597
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002598 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002599 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2600 *
2601 * @throws SecurityException if the caller does not have the required permission
2602 */
2603 private void enforceModifyPermission() {
2604 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2605 }
2606
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002607 /**
2608 * Make sure the caller is system.
2609 *
2610 * @throws SecurityException if the caller is not system.
2611 */
2612 private void enforceSystemCaller() {
2613 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2614 throw new SecurityException("Caller must be system");
2615 }
2616 }
2617
Shuo Qianf2b2df42019-11-13 17:43:31 -08002618 private void enforceActiveEmergencySessionPermission() {
2619 mApp.enforceCallingOrSelfPermission(
2620 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2621 }
2622
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002623 /**
2624 * Make sure the caller has the CALL_PHONE permission.
2625 *
2626 * @throws SecurityException if the caller does not have the required permission
2627 */
2628 private void enforceCallPermission() {
2629 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2630 }
2631
paulhu423b5f22019-08-23 19:17:33 +08002632 private void enforceSettingsPermission() {
2633 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002634 }
2635
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002636 private String createTelUrl(String number) {
2637 if (TextUtils.isEmpty(number)) {
2638 return null;
2639 }
2640
Jake Hambye994d462014-02-03 13:10:13 -08002641 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002642 }
2643
Ihab Awadf9e92732013-12-05 18:02:52 -08002644 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002645 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2646 }
2647
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002648 private static void logv(String msg) {
2649 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2650 }
2651
Ihab Awadf9e92732013-12-05 18:02:52 -08002652 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002653 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2654 }
2655
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002656 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002657 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002658 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002659 }
2660
Sanket Padawe356d7632015-06-22 14:03:32 -07002661 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002662 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663 final long identity = Binder.clearCallingIdentity();
2664 try {
2665 final Phone phone = PhoneFactory.getPhone(slotIndex);
2666 if (phone == null) {
2667 return PhoneConstants.PHONE_TYPE_NONE;
2668 } else {
2669 return phone.getPhoneType();
2670 }
2671 } finally {
2672 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002674 }
2675
2676 /**
2677 * Returns the CDMA ERI icon index to display
2678 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002679 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002680 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2681 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2682 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002683 }
2684
Sanket Padawe356d7632015-06-22 14:03:32 -07002685 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002686 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2687 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002688 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002689 mApp, subId, callingPackage, callingFeatureId,
2690 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002691 return -1;
2692 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002693
2694 final long identity = Binder.clearCallingIdentity();
2695 try {
2696 final Phone phone = getPhone(subId);
2697 if (phone != null) {
2698 return phone.getCdmaEriIconIndex();
2699 } else {
2700 return -1;
2701 }
2702 } finally {
2703 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002704 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002705 }
2706
2707 /**
2708 * Returns the CDMA ERI icon mode,
2709 * 0 - ON
2710 * 1 - FLASHING
2711 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002712 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002713 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2714 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2715 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002716 }
2717
Sanket Padawe356d7632015-06-22 14:03:32 -07002718 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002719 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2720 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002721 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002722 mApp, subId, callingPackage, callingFeatureId,
2723 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002724 return -1;
2725 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002726
2727 final long identity = Binder.clearCallingIdentity();
2728 try {
2729 final Phone phone = getPhone(subId);
2730 if (phone != null) {
2731 return phone.getCdmaEriIconMode();
2732 } else {
2733 return -1;
2734 }
2735 } finally {
2736 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002737 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002738 }
2739
2740 /**
2741 * Returns the CDMA ERI text,
2742 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002743 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002744 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2745 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2746 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002747 }
2748
Sanket Padawe356d7632015-06-22 14:03:32 -07002749 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002750 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2751 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002752 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002753 mApp, subId, callingPackage, callingFeatureId,
2754 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002755 return null;
2756 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002757
2758 final long identity = Binder.clearCallingIdentity();
2759 try {
2760 final Phone phone = getPhone(subId);
2761 if (phone != null) {
2762 return phone.getCdmaEriText();
2763 } else {
2764 return null;
2765 }
2766 } finally {
2767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002769 }
2770
2771 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002772 * Returns the CDMA MDN.
2773 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002774 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002775 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002776 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2777 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002778
2779 final long identity = Binder.clearCallingIdentity();
2780 try {
2781 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002782 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002783 return phone.getLine1Number();
2784 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002785 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786 return null;
2787 }
2788 } finally {
2789 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002790 }
2791 }
2792
2793 /**
2794 * Returns the CDMA MIN.
2795 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002796 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002797 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002798 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2799 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002800
2801 final long identity = Binder.clearCallingIdentity();
2802 try {
2803 final Phone phone = getPhone(subId);
2804 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2805 return phone.getCdmaMin();
2806 } else {
2807 return null;
2808 }
2809 } finally {
2810 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002811 }
2812 }
2813
Hall Liud892bec2018-11-30 14:51:45 -08002814 @Override
2815 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2816 INumberVerificationCallback callback, String callingPackage) {
2817 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2818 != PERMISSION_GRANTED) {
2819 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2820 }
2821 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2822
2823 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2824 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2825 throw new SecurityException("Calling package must be configured in the device config");
2826 }
2827
2828 if (range == null) {
2829 throw new NullPointerException("Range must be non-null");
2830 }
2831
2832 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002833 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002834
2835 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2836 }
2837
Junda Liuca05d5d2014-08-14 22:36:34 -07002838 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002839 * Returns true if CDMA provisioning needs to run.
2840 */
2841 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002842 final long identity = Binder.clearCallingIdentity();
2843 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002844 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002845 } finally {
2846 Binder.restoreCallingIdentity(identity);
2847 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002848 }
2849
2850 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002851 * Sets the voice mail number of a given subId.
2852 */
2853 @Override
2854 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08002855 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2856 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002857
2858 final long identity = Binder.clearCallingIdentity();
2859 try {
2860 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2861 new Pair<String, String>(alphaTag, number), new Integer(subId));
2862 return success;
2863 } finally {
2864 Binder.restoreCallingIdentity(identity);
2865 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002866 }
2867
Ta-wei Yen87c49842016-05-13 21:19:52 -07002868 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002869 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2870 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002871 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2872 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002873 if (!TextUtils.equals(callingPackage, systemDialer)) {
2874 throw new SecurityException("caller must be system dialer");
2875 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002876
2877 final long identity = Binder.clearCallingIdentity();
2878 try {
2879 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2880 if (phoneAccountHandle == null) {
2881 return null;
2882 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002883 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002884 } finally {
2885 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002886 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002887 }
2888
2889 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002890 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2891 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002892 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002893 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002894 mApp, subId, callingPackage, callingFeatureId,
2895 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002896 return null;
2897 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002898
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002899 final long identity = Binder.clearCallingIdentity();
2900 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002901 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002902 } finally {
2903 Binder.restoreCallingIdentity(identity);
2904 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002905 }
2906
2907 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002908 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2909 VisualVoicemailSmsFilterSettings settings) {
2910 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002911
2912 final long identity = Binder.clearCallingIdentity();
2913 try {
2914 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002915 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002916 } finally {
2917 Binder.restoreCallingIdentity(identity);
2918 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002919 }
2920
2921 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002922 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2923 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002924
2925 final long identity = Binder.clearCallingIdentity();
2926 try {
2927 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002928 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002929 } finally {
2930 Binder.restoreCallingIdentity(identity);
2931 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002932 }
2933
2934 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002935 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2936 String callingPackage, int subId) {
2937 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938
2939 final long identity = Binder.clearCallingIdentity();
2940 try {
2941 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002942 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002943 } finally {
2944 Binder.restoreCallingIdentity(identity);
2945 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002946 }
2947
2948 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002949 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002950 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951
2952 final long identity = Binder.clearCallingIdentity();
2953 try {
2954 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002955 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002956 } finally {
2957 Binder.restoreCallingIdentity(identity);
2958 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002959 }
2960
2961 @Override
2962 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2963 String number, int port, String text, PendingIntent sentIntent) {
2964 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002965 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002966 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002967 SmsController smsController = PhoneFactory.getSmsController();
2968 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2969 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002970 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002971
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002972 /**
fionaxu0152e512016-11-14 13:36:14 -08002973 * Sets the voice activation state of a given subId.
2974 */
2975 @Override
2976 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2978 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002979
2980 final long identity = Binder.clearCallingIdentity();
2981 try {
2982 final Phone phone = getPhone(subId);
2983 if (phone != null) {
2984 phone.setVoiceActivationState(activationState);
2985 } else {
2986 loge("setVoiceActivationState fails with invalid subId: " + subId);
2987 }
2988 } finally {
2989 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002990 }
2991 }
2992
2993 /**
2994 * Sets the data activation state of a given subId.
2995 */
2996 @Override
2997 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002998 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2999 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003000
3001 final long identity = Binder.clearCallingIdentity();
3002 try {
3003 final Phone phone = getPhone(subId);
3004 if (phone != null) {
3005 phone.setDataActivationState(activationState);
3006 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003007 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003008 }
3009 } finally {
3010 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003011 }
3012 }
3013
3014 /**
3015 * Returns the voice activation state of a given subId.
3016 */
3017 @Override
3018 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003019 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003020
fionaxu0152e512016-11-14 13:36:14 -08003021 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003022 final long identity = Binder.clearCallingIdentity();
3023 try {
3024 if (phone != null) {
3025 return phone.getVoiceActivationState();
3026 } else {
3027 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3028 }
3029 } finally {
3030 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003031 }
3032 }
3033
3034 /**
3035 * Returns the data activation state of a given subId.
3036 */
3037 @Override
3038 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003039 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003040
fionaxu0152e512016-11-14 13:36:14 -08003041 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003042 final long identity = Binder.clearCallingIdentity();
3043 try {
3044 if (phone != null) {
3045 return phone.getDataActivationState();
3046 } else {
3047 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3048 }
3049 } finally {
3050 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003051 }
3052 }
3053
3054 /**
Wink Saville36469e72014-06-11 15:17:00 -07003055 * Returns the unread count of voicemails for a subId
3056 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003057 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003058 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3059 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003060 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003061 mApp, subId, callingPackage, callingFeatureId,
3062 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003063 return 0;
3064 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003065 final long identity = Binder.clearCallingIdentity();
3066 try {
3067 final Phone phone = getPhone(subId);
3068 if (phone != null) {
3069 return phone.getVoiceMessageCount();
3070 } else {
3071 return 0;
3072 }
3073 } finally {
3074 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003075 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003076 }
3077
3078 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003079 * returns true, if the device is in a state where both voice and data
3080 * are supported simultaneously. This can change based on location or network condition.
3081 */
3082 @Override
3083 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003084 final long identity = Binder.clearCallingIdentity();
3085 try {
3086 final Phone phone = getPhone(subId);
3087 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3088 } finally {
3089 Binder.restoreCallingIdentity(identity);
3090 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003091 }
3092
3093 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003094 * Send the dialer code if called from the current default dialer or the caller has
3095 * carrier privilege.
3096 * @param inputCode The dialer code to send
3097 */
3098 @Override
3099 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003100 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003101 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003102 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3103 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003104 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003105 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003106 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003107 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003108
3109 final long identity = Binder.clearCallingIdentity();
3110 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003111 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003112 } finally {
3113 Binder.restoreCallingIdentity(identity);
3114 }
fionaxu235cc5e2017-03-06 22:25:57 -08003115 }
3116
Pengquan Menga1bb6272018-09-06 09:59:22 -07003117 @Override
3118 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003119 TelephonyPermissions
3120 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3121 mApp, subId, "getNetworkSelectionMode");
3122 final long identity = Binder.clearCallingIdentity();
3123 try {
3124 if (!isActiveSubscription(subId)) {
3125 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3126 }
3127 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3128 } finally {
3129 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003130 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003131 }
3132
Brad Ebinger35c841c2018-10-01 10:40:55 -07003133 @Override
Sarah Chin5f0ecd72019-12-06 10:24:18 -08003134 public PhoneCapability getPhoneCapability(int subId, String callingPackage,
3135 String callingFeatureId) {
3136 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3137 mApp, subId, callingPackage, callingFeatureId, "getPhoneCapability")) {
3138 return null;
3139 }
3140 final long identity = Binder.clearCallingIdentity();
3141 try {
3142 return mPhoneConfigurationManager.getStaticPhoneCapability();
3143 } finally {
3144 Binder.restoreCallingIdentity(identity);
3145 }
3146 }
3147
3148 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003149 public boolean isInEmergencySmsMode() {
3150 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3151 final long identity = Binder.clearCallingIdentity();
3152 try {
3153 for (Phone phone : PhoneFactory.getPhones()) {
3154 if (phone.isInEmergencySmsMode()) {
3155 return true;
3156 }
3157 }
3158 } finally {
3159 Binder.restoreCallingIdentity(identity);
3160 }
3161 return false;
3162 }
3163
shilu366312e2019-12-17 09:28:10 -08003164 /**
3165 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3166 * @param subId The subscription to use to check the configuration.
3167 * @param c The callback that will be used to send the result.
3168 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003169 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003170 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3171 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003172 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003173 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003174
Brad Ebinger77b832e2019-10-17 17:03:22 -07003175 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3176 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3177 "IMS not available on device.");
3178 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003179 final long token = Binder.clearCallingIdentity();
3180 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003181 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003182 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003183 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003184 } catch (ImsException e) {
3185 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003186 } finally {
3187 Binder.restoreCallingIdentity(token);
3188 }
3189 }
3190
shilu366312e2019-12-17 09:28:10 -08003191 /**
3192 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3193 * @param subId The subscription to use to check the configuration.
3194 * @param c The callback that will be used to send the result.
3195 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003196 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003197 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
shilu366312e2019-12-17 09:28:10 -08003198 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003199 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003200 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3201 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3202 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003203 final long token = Binder.clearCallingIdentity();
3204 try {
3205 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3206 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3207 .removeRegistrationCallbackForSubscription(c, subId);
3208 } catch (ImsException e) {
3209 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3210 + "is inactive, ignoring unregister.");
3211 // If the subscription is no longer active, just return, since the callback
3212 // will already have been removed internally.
3213 } finally {
3214 Binder.restoreCallingIdentity(token);
3215 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003216 }
3217
Brad Ebinger774ba362019-10-22 17:36:18 -07003218 /**
3219 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3220 */
3221 @Override
3222 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3223 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3224 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3225 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3226 "IMS not available on device.");
3227 }
3228 final long token = Binder.clearCallingIdentity();
3229 try {
3230 Phone phone = getPhone(subId);
3231 if (phone == null) {
3232 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3233 + subId + "'");
3234 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3235 }
3236 phone.getImsRegistrationState(regState -> {
3237 try {
3238 consumer.accept((regState == null)
3239 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3240 } catch (RemoteException e) {
3241 // Ignore if the remote process is no longer available to call back.
3242 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3243 }
3244 });
3245 } finally {
3246 Binder.restoreCallingIdentity(token);
3247 }
3248 }
3249
3250 /**
3251 * Get the transport type for the IMS service registration state.
3252 */
3253 @Override
3254 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
shilu366312e2019-12-17 09:28:10 -08003255 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger774ba362019-10-22 17:36:18 -07003256 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3257 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3258 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3259 "IMS not available on device.");
3260 }
3261 final long token = Binder.clearCallingIdentity();
3262 try {
3263 Phone phone = getPhone(subId);
3264 if (phone == null) {
3265 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3266 + subId + "'");
3267 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3268 }
3269 phone.getImsRegistrationTech(regTech -> {
3270 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3271 int regTechConverted = (regTech == null)
3272 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3273 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3274 regTechConverted);
3275 try {
3276 consumer.accept(regTechConverted);
3277 } catch (RemoteException e) {
3278 // Ignore if the remote process is no longer available to call back.
3279 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3280 }
3281 });
3282 } finally {
3283 Binder.restoreCallingIdentity(token);
3284 }
3285 }
3286
shilu366312e2019-12-17 09:28:10 -08003287 /**
3288 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3289 * @param subId The subscription to use to check the configuration.
3290 * @param c The callback that will be used to send the result.
3291 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003292 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003293 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3294 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003295 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003296 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003297 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3298 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3299 "IMS not available on device.");
3300 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003301 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3302 final long token = Binder.clearCallingIdentity();
3303 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003304 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003305 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003306 } catch (ImsException e) {
3307 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003308 } finally {
3309 Binder.restoreCallingIdentity(token);
3310 }
3311 }
3312
shilu366312e2019-12-17 09:28:10 -08003313 /**
3314 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3315 * @param subId The subscription to use to check the configuration.
3316 * @param c The callback that will be used to send the result.
3317 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003318 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003319 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
shilu366312e2019-12-17 09:28:10 -08003320 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003321 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003322 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3323 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3324 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003325
3326 final long token = Binder.clearCallingIdentity();
3327 try {
3328 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3329 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003330 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003331 } catch (ImsException e) {
3332 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3333 + "is inactive, ignoring unregister.");
3334 // If the subscription is no longer active, just return, since the callback
3335 // will already have been removed internally.
3336 } finally {
3337 Binder.restoreCallingIdentity(token);
3338 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003339 }
3340
3341 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003342 public boolean isCapable(int subId, int capability, int regTech) {
3343 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003344 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3345 final long token = Binder.clearCallingIdentity();
3346 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003347 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003348 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003349 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003350 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3351 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003352 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003353 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3354 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003355 } finally {
3356 Binder.restoreCallingIdentity(token);
3357 }
3358 }
3359
3360 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003361 public boolean isAvailable(int subId, int capability, int regTech) {
3362 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003363 final long token = Binder.clearCallingIdentity();
3364 try {
3365 Phone phone = getPhone(subId);
3366 if (phone == null) return false;
3367 return phone.isImsCapabilityAvailable(capability, regTech);
3368 } finally {
3369 Binder.restoreCallingIdentity(token);
3370 }
3371 }
3372
Brad Ebinger77b832e2019-10-17 17:03:22 -07003373 /**
3374 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3375 * subscription.
3376 * @param subId The subscription to use to check the configuration.
3377 * @param callback The callback that will be used to send the result.
3378 * @param capability The MmTelFeature capability that will be used to send the result.
3379 * @param transportType The transport type of the MmTelFeature capability.
3380 */
3381 @Override
3382 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3383 int transportType) {
3384 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3385 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3386 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3387 "IMS not available on device.");
3388 }
3389 final long token = Binder.clearCallingIdentity();
3390 try {
3391 int slotId = getSlotIndex(subId);
3392 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3393 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3394 + subId + "'");
3395 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3396 }
3397 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3398 transportType, aBoolean -> {
3399 try {
3400 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3401 } catch (RemoteException e) {
3402 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3403 + "running. Ignore");
3404 }
3405 });
3406 } finally {
3407 Binder.restoreCallingIdentity(token);
3408 }
3409 }
3410
shilu366312e2019-12-17 09:28:10 -08003411 /**
3412 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3413 * @param subId The subscription to use to check the configuration.
3414 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003415 @Override
3416 public boolean isAdvancedCallingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003417 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
3418 enforceReadPrivilegedPermission("isAdvancedCallingSettingEnabled");
3419
Brad Ebinger35c841c2018-10-01 10:40:55 -07003420 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3421 final long token = Binder.clearCallingIdentity();
3422 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003423 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003424 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003425 } catch (ImsException e) {
3426 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003427 } finally {
3428 Binder.restoreCallingIdentity(token);
3429 }
3430 }
3431
3432 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003433 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003434 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003435 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003436 final long identity = Binder.clearCallingIdentity();
3437 try {
3438 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003439 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003440 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003441 } catch (ImsException e) {
3442 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003443 } finally {
3444 Binder.restoreCallingIdentity(identity);
3445 }
3446 }
3447
shilu366312e2019-12-17 09:28:10 -08003448 /**
3449 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3450 * @param subId The subscription to use to check the configuration.
3451 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003452 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003453 public boolean isVtSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003454 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003455 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003456 final long identity = Binder.clearCallingIdentity();
3457 try {
3458 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003459 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3460 } catch (ImsException e) {
3461 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003462 } finally {
3463 Binder.restoreCallingIdentity(identity);
3464 }
3465 }
3466
3467 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003468 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003469 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003470 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003471 final long identity = Binder.clearCallingIdentity();
3472 try {
3473 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003474 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003475 } catch (ImsException e) {
3476 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003477 } finally {
3478 Binder.restoreCallingIdentity(identity);
3479 }
3480 }
3481
shilu366312e2019-12-17 09:28:10 -08003482 /**
3483 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3484 * @param subId The subscription to use to check the configuration.
3485 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003486 @Override
3487 public boolean isVoWiFiSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003488 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003489 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3490 final long identity = Binder.clearCallingIdentity();
3491 try {
3492 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003493 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003494 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003495 } catch (ImsException e) {
3496 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003497 } finally {
3498 Binder.restoreCallingIdentity(identity);
3499 }
3500 }
3501
3502 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003503 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003504 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003505 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003506 final long identity = Binder.clearCallingIdentity();
3507 try {
3508 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003509 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003510 } catch (ImsException e) {
3511 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003512 } finally {
3513 Binder.restoreCallingIdentity(identity);
3514 }
3515 }
3516
shilu366312e2019-12-17 09:28:10 -08003517 /**
3518 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3519 * @param subId The subscription to use to check the configuration.
3520 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003521 @Override
3522 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003523 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003524 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3525 final long identity = Binder.clearCallingIdentity();
3526 try {
3527 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003528 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003529 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003530 } catch (ImsException e) {
3531 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003532 } finally {
3533 Binder.restoreCallingIdentity(identity);
3534 }
3535 }
3536
3537 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003538 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003539 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003540 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003541 final long identity = Binder.clearCallingIdentity();
3542 try {
3543 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003544 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003545 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003546 } catch (ImsException e) {
3547 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003548 } finally {
3549 Binder.restoreCallingIdentity(identity);
3550 }
3551 }
3552
3553 @Override
3554 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3556 "setVoWiFiNonPersistent");
3557 final long identity = Binder.clearCallingIdentity();
3558 try {
3559 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003560 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003561 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003562 } catch (ImsException e) {
3563 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003564 } finally {
3565 Binder.restoreCallingIdentity(identity);
3566 }
3567 }
3568
shilu366312e2019-12-17 09:28:10 -08003569 /**
3570 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3571 * @param subId The subscription to use to check the configuration.
3572 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003573 @Override
3574 public int getVoWiFiModeSetting(int subId) {
shilu366312e2019-12-17 09:28:10 -08003575 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003576 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3577 final long identity = Binder.clearCallingIdentity();
3578 try {
3579 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003580 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003581 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003582 } catch (ImsException e) {
3583 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003584 } finally {
3585 Binder.restoreCallingIdentity(identity);
3586 }
3587 }
3588
3589 @Override
3590 public void setVoWiFiModeSetting(int subId, int mode) {
3591 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3592 "setVoWiFiModeSetting");
3593 final long identity = Binder.clearCallingIdentity();
3594 try {
3595 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003596 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003597 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003598 } catch (ImsException e) {
3599 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003600 } finally {
3601 Binder.restoreCallingIdentity(identity);
3602 }
3603 }
3604
3605 @Override
3606 public int getVoWiFiRoamingModeSetting(int subId) {
3607 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3608 final long identity = Binder.clearCallingIdentity();
3609 try {
3610 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003611 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003612 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003613 } catch (ImsException e) {
3614 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003615 } finally {
3616 Binder.restoreCallingIdentity(identity);
3617 }
3618 }
3619
3620 @Override
3621 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3622 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3623 "setVoWiFiRoamingModeSetting");
3624 final long identity = Binder.clearCallingIdentity();
3625 try {
3626 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003627 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003628 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003629 } catch (ImsException e) {
3630 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003631 } finally {
3632 Binder.restoreCallingIdentity(identity);
3633 }
3634 }
3635
3636 @Override
3637 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3638 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3639 "setRttCapabilityEnabled");
3640 final long identity = Binder.clearCallingIdentity();
3641 try {
3642 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003643 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3644 } catch (ImsException e) {
3645 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003646 } finally {
3647 Binder.restoreCallingIdentity(identity);
3648 }
3649 }
3650
shilu366312e2019-12-17 09:28:10 -08003651 /**
3652 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3653 * @param subId The subscription to use to check the configuration.
3654 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003655 @Override
3656 public boolean isTtyOverVolteEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003657 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003658 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3659 final long identity = Binder.clearCallingIdentity();
3660 try {
3661 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003662 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003663 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003664 } catch (ImsException e) {
3665 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003666 } finally {
3667 Binder.restoreCallingIdentity(identity);
3668 }
3669 }
3670
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003671 @Override
3672 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3673 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3674 final long identity = Binder.clearCallingIdentity();
3675 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003676 if (!isImsAvailableOnDevice()) {
3677 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3678 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003679 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003680 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003681 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003682 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003683 } catch (ImsException e) {
3684 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003685 } finally {
3686 Binder.restoreCallingIdentity(identity);
3687 }
3688 }
3689
3690 @Override
3691 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3692 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3693 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003694 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3695 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3696 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003697 try {
3698 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003699 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003700 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003701 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003702 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3703 + "is inactive, ignoring unregister.");
3704 // If the subscription is no longer active, just return, since the callback will already
3705 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003706 } finally {
3707 Binder.restoreCallingIdentity(identity);
3708 }
3709 }
3710
allenwtsu99c623b2020-01-03 18:24:23 +08003711
3712 private void checkModifyPhoneStatePermission(int subId, String message) {
3713 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3714 message);
3715 }
3716
3717 private boolean isImsProvisioningRequired(int subId, int capability,
3718 boolean isMmtelCapability) {
3719 Phone phone = getPhone(subId);
3720 if (phone == null) {
3721 loge("phone instance null for subid " + subId);
3722 return false;
3723 }
3724 if (isMmtelCapability) {
3725 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3726 return false;
3727 }
3728 } else {
3729 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3730 return false;
3731 }
3732 }
3733 return true;
3734 }
3735
3736 @Override
3737 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3738 boolean isProvisioned) {
3739 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3740
3741 final long identity = Binder.clearCallingIdentity();
3742 try {
3743 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3744 if (!isImsProvisioningRequired(subId, capability, false)) {
3745 return;
3746 }
3747
3748 // this capability requires provisioning, route to the correct API.
3749 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3750 switch (capability) {
3751 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3752 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3753 ims.setEabProvisioned(isProvisioned);
3754 break;
3755 default: {
3756 throw new IllegalArgumentException("Tried to set provisioning for "
3757 + "rcs capability '" + capability + "', which does not require "
3758 + "provisioning.");
3759 }
3760 }
3761 } finally {
3762 Binder.restoreCallingIdentity(identity);
3763 }
3764
3765 }
3766
3767
3768 @Override
3769 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3770 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3771 final long identity = Binder.clearCallingIdentity();
3772 try {
3773 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3774 if (!isImsProvisioningRequired(subId, capability, false)) {
3775 return true;
3776 }
3777
3778 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3779 switch (capability) {
3780 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3781 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3782 return ims.isEabProvisionedOnDevice();
3783
3784 default: {
3785 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3786 + "capability '" + capability + "', which does not require "
3787 + "provisioning.");
3788 }
3789 }
3790
3791 } finally {
3792 Binder.restoreCallingIdentity(identity);
3793 }
3794 }
3795
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003796 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003797 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3798 boolean isProvisioned) {
3799 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3800 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3801 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3802 }
allenwtsu99c623b2020-01-03 18:24:23 +08003803 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003804 final long identity = Binder.clearCallingIdentity();
3805 try {
3806 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003807 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003808 return;
3809 }
3810
3811 // this capability requires provisioning, route to the correct API.
3812 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3813 switch (capability) {
3814 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3815 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3816 ims.setVolteProvisioned(isProvisioned);
3817 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3818 ims.setWfcProvisioned(isProvisioned);
3819 }
3820 break;
3821 }
3822 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3823 // There is currently no difference in VT provisioning type.
3824 ims.setVtProvisioned(isProvisioned);
3825 break;
3826 }
3827 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3828 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3829 // change the capability of the feature instead if needed.
3830 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3831 == isProvisioned) {
3832 // No change in provisioning.
3833 return;
3834 }
3835 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3836 try {
3837 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003838 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003839 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3840 + ", Exception" + e.getMessage());
3841 }
3842 break;
3843 }
3844 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003845 throw new IllegalArgumentException("Tried to set provisioning for "
3846 + "MmTel capability '" + capability + "', which does not require "
3847 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003848 }
3849 }
3850
3851 } finally {
3852 Binder.restoreCallingIdentity(identity);
3853 }
3854 }
3855
3856 @Override
3857 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3858 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3859 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3860 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3861 }
3862 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3863 final long identity = Binder.clearCallingIdentity();
3864 try {
3865 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003866 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003867 return true;
3868 }
3869
3870 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3871 switch (capability) {
3872 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3873 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3874 return ims.isVolteProvisionedOnDevice();
3875 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3876 return ims.isWfcProvisionedOnDevice();
3877 }
3878 // This should never happen, since we are checking tech above to make sure it
3879 // is either LTE or IWLAN.
3880 throw new IllegalArgumentException("Invalid radio technology for voice "
3881 + "capability.");
3882 }
3883 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3884 // There is currently no difference in VT provisioning type.
3885 return ims.isVtProvisionedOnDevice();
3886 }
3887 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3888 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3889 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3890 }
3891 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003892 throw new IllegalArgumentException(
3893 "Tried to get provisioning for MmTel capability '" + capability
3894 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003895 }
3896 }
3897
3898 } finally {
3899 Binder.restoreCallingIdentity(identity);
3900 }
3901 }
3902
3903 @Override
3904 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3905 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3906 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3907 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3908 }
3909 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3910 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3911 return (provisionedBits & capability) > 0;
3912 }
3913
3914 @Override
3915 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3916 boolean isProvisioned) {
3917 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3918 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3919 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3920 }
3921 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3922 "setProvisioningStatusForCapability");
3923 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3924 // If the current provisioning status for capability already matches isProvisioned,
3925 // do nothing.
3926 if (((provisionedBits & capability) > 0) == isProvisioned) {
3927 return;
3928 }
3929 if (isProvisioned) {
3930 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3931 } else {
3932 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3933 }
3934 }
3935
3936 /**
3937 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3938 * technology. The bitfield should mirror the bitfield defined by
3939 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3940 */
3941 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3942 String key = getMmTelProvisioningKey(subId, tech);
3943 // Default is no capabilities are provisioned.
3944 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3945 }
3946
3947 /**
3948 * Sets the MmTel capability provisioning bitfield (defined by
3949 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3950 * technology specified.
3951 *
3952 * Note: This is a synchronous command and should not be called on UI thread.
3953 */
3954 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3955 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3956 String key = getMmTelProvisioningKey(subId, tech);
3957 editor.putInt(key, newField);
3958 editor.commit();
3959 }
3960
3961 private static String getMmTelProvisioningKey(int subId, int tech) {
3962 // resulting key is provision_ims_mmtel_{subId}_{tech}
3963 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3964 }
3965
3966 /**
3967 * Query CarrierConfig to see if the specified capability requires provisioning for the
3968 * carrier associated with the subscription id.
3969 */
3970 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3971 int capability) {
3972 CarrierConfigManager configManager = new CarrierConfigManager(context);
3973 PersistableBundle c = configManager.getConfigForSubId(subId);
3974 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003975 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003976 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3977 false);
3978 boolean requireVoiceVtProvisioning = c.getBoolean(
3979 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3980
3981 // First check to make sure that the capability requires provisioning.
3982 switch (capability) {
3983 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3984 // intentional fallthrough
3985 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3986 if (requireVoiceVtProvisioning) {
3987 // Voice and Video requires provisioning
3988 return true;
3989 }
3990 break;
3991 }
3992 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3993 if (requireUtProvisioning) {
3994 // UT requires provisioning
3995 return true;
3996 }
3997 break;
3998 }
3999 }
4000 return false;
4001 }
4002
allenwtsu99c623b2020-01-03 18:24:23 +08004003 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4004 int capability) {
4005 CarrierConfigManager configManager = new CarrierConfigManager(context);
4006 PersistableBundle c = configManager.getConfigForSubId(subId);
4007
4008 boolean requireRcsProvisioning = c.getBoolean(
4009 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4010
4011 // First check to make sure that the capability requires provisioning.
4012 switch (capability) {
4013 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4014 // intentional fallthrough
4015 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4016 if (requireRcsProvisioning) {
4017 // OPTION or PRESENCE requires provisioning
4018 return true;
4019 }
4020 break;
4021 }
4022 }
4023 return false;
4024 }
4025
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004026 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004027 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004028 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4029 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4030 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004031 enforceReadPrivilegedPermission("getImsProvisioningInt");
4032 final long identity = Binder.clearCallingIdentity();
4033 try {
4034 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004035 int slotId = getSlotIndex(subId);
4036 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4037 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4038 + subId + "' for key:" + key);
4039 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4040 }
4041 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004042 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004043 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4044 + subId + "' for key:" + key);
4045 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004046 } finally {
4047 Binder.restoreCallingIdentity(identity);
4048 }
4049 }
4050
4051 @Override
4052 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004053 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4054 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4055 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004056 enforceReadPrivilegedPermission("getImsProvisioningString");
4057 final long identity = Binder.clearCallingIdentity();
4058 try {
4059 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004060 int slotId = getSlotIndex(subId);
4061 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4062 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4063 + subId + "' for key:" + key);
4064 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4065 }
4066 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004067 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004068 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4069 + subId + "' for key:" + key);
4070 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004071 } finally {
4072 Binder.restoreCallingIdentity(identity);
4073 }
4074 }
4075
4076 @Override
4077 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004078 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4079 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4080 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004081 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4082 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004083 final long identity = Binder.clearCallingIdentity();
4084 try {
4085 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004086 int slotId = getSlotIndex(subId);
4087 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4088 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4089 + subId + "' for key:" + key);
4090 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4091 }
4092 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004093 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004094 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4095 + "' for key:" + key);
4096 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004097 } finally {
4098 Binder.restoreCallingIdentity(identity);
4099 }
4100 }
4101
4102 @Override
4103 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004104 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4105 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4106 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004107 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4108 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004109 final long identity = Binder.clearCallingIdentity();
4110 try {
4111 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004112 int slotId = getSlotIndex(subId);
4113 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4114 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4115 + subId + "' for key:" + key);
4116 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4117 }
4118 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004119 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004120 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4121 + "' for key:" + key);
4122 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004123 } finally {
4124 Binder.restoreCallingIdentity(identity);
4125 }
4126 }
4127
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004128 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004129 int slotId = SubscriptionManager.getSlotIndex(subId);
4130 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004131 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4132 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004133 }
4134 return slotId;
4135 }
4136
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004137 private int getSlotIndex(int subId) {
4138 int slotId = SubscriptionManager.getSlotIndex(subId);
4139 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4140 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4141 }
4142 return slotId;
4143 }
4144
Wink Saville36469e72014-06-11 15:17:00 -07004145 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004146 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004147 */
4148 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004149 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4150 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004151 final int targetSdk = getTargetSdk(callingPackage);
4152 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004153 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004154 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004155 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004156 mApp, subId, callingPackage, callingFeatureId,
4157 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004158 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4159 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004160
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004161 final long identity = Binder.clearCallingIdentity();
4162 try {
4163 final Phone phone = getPhone(subId);
4164 if (phone != null) {
4165 return phone.getServiceState().getDataNetworkType();
4166 } else {
4167 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4168 }
4169 } finally {
4170 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004171 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004172 }
4173
4174 /**
4175 * Returns the data network type
4176 */
4177 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004178 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4179 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4180 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004181 }
4182
4183 /**
4184 * Returns the data network type for a subId
4185 */
4186 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004187 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4188 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004189 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004190 mApp, subId, callingPackage, callingFeatureId,
4191 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004192 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4193 }
4194
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004195 final long identity = Binder.clearCallingIdentity();
4196 try {
4197 final Phone phone = getPhone(subId);
4198 if (phone != null) {
4199 return phone.getServiceState().getDataNetworkType();
4200 } else {
4201 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4202 }
4203 } finally {
4204 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004205 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004206 }
4207
4208 /**
Wink Saville36469e72014-06-11 15:17:00 -07004209 * Returns the Voice network type for a subId
4210 */
4211 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004212 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4213 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004214 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004215 mApp, subId, callingPackage, callingFeatureId,
4216 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004217 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4218 }
4219
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004220 final long identity = Binder.clearCallingIdentity();
4221 try {
4222 final Phone phone = getPhone(subId);
4223 if (phone != null) {
4224 return phone.getServiceState().getVoiceNetworkType();
4225 } else {
4226 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4227 }
4228 } finally {
4229 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004230 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004231 }
4232
4233 /**
4234 * @return true if a ICC card is present
4235 */
4236 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004237 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004238 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4239 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004240 }
4241
4242 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004243 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004244 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004245 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004246 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004247 final long identity = Binder.clearCallingIdentity();
4248 try {
4249 final Phone phone = PhoneFactory.getPhone(slotIndex);
4250 if (phone != null) {
4251 return phone.getIccCard().hasIccCard();
4252 } else {
4253 return false;
4254 }
4255 } finally {
4256 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004258 }
4259
4260 /**
4261 * Return if the current radio is LTE on CDMA. This
4262 * is a tri-state return value as for a period of time
4263 * the mode may be unknown.
4264 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004265 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004266 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004267 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004268 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004269 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004270 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4271 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4272 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004273 }
4274
Sanket Padawe356d7632015-06-22 14:03:32 -07004275 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004276 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4277 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004278 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004279 mApp, subId, callingPackage, callingFeatureId,
4280 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004281 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4282 }
4283
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004284 final long identity = Binder.clearCallingIdentity();
4285 try {
4286 final Phone phone = getPhone(subId);
4287 if (phone == null) {
4288 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4289 } else {
4290 return phone.getLteOnCdmaMode();
4291 }
4292 } finally {
4293 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004294 }
Wink Saville36469e72014-06-11 15:17:00 -07004295 }
4296
Wink Saville36469e72014-06-11 15:17:00 -07004297 /**
4298 * {@hide}
4299 * Returns Default subId, 0 in the case of single standby.
4300 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004301 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004302 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004303 }
4304
Shishir Agrawala9f32182016-04-12 12:00:16 -07004305 private int getSlotForDefaultSubscription() {
4306 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4307 }
4308
Wink Savilleb564aae2014-10-23 10:18:09 -07004309 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004310 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004311 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004312
Pengquan Menge92a50d2018-09-21 15:54:48 -07004313 private boolean isActiveSubscription(int subId) {
4314 return mSubscriptionController.isActiveSubId(subId);
4315 }
4316
Ihab Awadf2177b72013-11-25 13:33:23 -08004317 /**
4318 * @see android.telephony.TelephonyManager.WifiCallingChoices
4319 */
4320 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004321 final long identity = Binder.clearCallingIdentity();
4322 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004323 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004324 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4325 getWhenToMakeWifiCallsDefaultPreference());
4326 } finally {
4327 Binder.restoreCallingIdentity(identity);
4328 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004329 }
4330
4331 /**
4332 * @see android.telephony.TelephonyManager.WifiCallingChoices
4333 */
4334 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004335 final long identity = Binder.clearCallingIdentity();
4336 try {
4337 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004338 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004339 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4340 } finally {
4341 Binder.restoreCallingIdentity(identity);
4342 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004343 }
4344
Sailesh Nepald1e68152013-12-12 19:08:02 -08004345 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004346 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004347 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004348 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004349
Jordan Liu4c733742019-02-28 12:03:40 -08004350 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4351 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4352 if (phoneId == -1) {
4353 throw new IllegalArgumentException("Given slot index: " + slotIndex
4354 + " does not correspond to an active phone");
4355 }
4356 return PhoneFactory.getPhone(phoneId);
4357 }
4358
Shishir Agrawal566b7612013-10-28 14:41:00 -07004359 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004360 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4361 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004362 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4363 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004364 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004365 if (DBG) {
4366 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4367 }
4368 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4369 p2);
4370 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004371
Jordan Liu4c733742019-02-28 12:03:40 -08004372
4373 @Override
4374 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4375 int slotIndex, String callingPackage, String aid, int p2) {
4376 enforceModifyPermission();
4377 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4378 if (DBG) {
4379 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4380 }
4381 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4382 callingPackage, aid, p2);
4383 }
4384
4385 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4386 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004387 final long identity = Binder.clearCallingIdentity();
4388 try {
4389 if (TextUtils.equals(ISDR_AID, aid)) {
4390 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004391 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4392 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004393 if (bestComponent == null
4394 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4395 loge("The calling package is not allowed to access ISD-R.");
4396 throw new SecurityException(
4397 "The calling package is not allowed to access ISD-R.");
4398 }
Derek Tan740e1672017-06-27 14:56:27 -07004399 }
Derek Tan740e1672017-06-27 14:56:27 -07004400
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004401 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004402 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4403 null /* workSource */);
4404 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004405 return response;
4406 } finally {
4407 Binder.restoreCallingIdentity(identity);
4408 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004409 }
4410
4411 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004412 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004413 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4414 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004415 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4416 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4417 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004418
Jordan Liu4c733742019-02-28 12:03:40 -08004419 @Override
4420 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4421 enforceModifyPermission();
4422 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4423 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4424 channel);
4425 }
4426
4427 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004428 final long identity = Binder.clearCallingIdentity();
4429 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004430 if (channel < 0) {
4431 return false;
4432 }
Jordan Liu4c733742019-02-28 12:03:40 -08004433 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4434 null /* workSource */);
4435 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004436 return success;
4437 } finally {
4438 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004439 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004440 }
4441
4442 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004443 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004444 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4446 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004447 if (DBG) {
4448 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4449 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4450 + p3 + " data=" + data);
4451 }
4452 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4453 command, p1, p2, p3, data);
4454 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004455
Jordan Liu4c733742019-02-28 12:03:40 -08004456 @Override
4457 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4458 int command, int p1, int p2, int p3, String data) {
4459 enforceModifyPermission();
4460 if (DBG) {
4461 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4462 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4463 + p3 + " data=" + data);
4464 }
4465 return iccTransmitApduLogicalChannelWithPermission(
4466 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4467 data);
4468 }
4469
4470 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4471 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004472 final long identity = Binder.clearCallingIdentity();
4473 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004474 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004475 return "";
4476 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004477
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004478 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004479 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4480 null /* workSource */);
4481 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004482
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004483 // Append the returned status code to the end of the response payload.
4484 String s = Integer.toHexString(
4485 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4486 if (response.payload != null) {
4487 s = IccUtils.bytesToHexString(response.payload) + s;
4488 }
4489 return s;
4490 } finally {
4491 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004492 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004493 }
Jake Hambye994d462014-02-03 13:10:13 -08004494
Evan Charltonc66da362014-05-16 14:06:40 -07004495 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004496 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4497 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004498 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4499 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004500 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004501 if (DBG) {
4502 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4503 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4504 }
4505 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4506 cla, command, p1, p2, p3, data);
4507 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004508
Jordan Liu4c733742019-02-28 12:03:40 -08004509 @Override
4510 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4511 int command, int p1, int p2, int p3, String data) {
4512 enforceModifyPermission();
4513 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4514 if (DBG) {
4515 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4516 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4517 + " data=" + data);
4518 }
4519
4520 return iccTransmitApduBasicChannelWithPermission(
4521 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4522 p2, p3, data);
4523 }
4524
4525 // open APDU basic channel assuming the caller has sufficient permissions
4526 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4527 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004528 final long identity = Binder.clearCallingIdentity();
4529 try {
4530 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4531 && TextUtils.equals(ISDR_AID, data)) {
4532 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004533 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4534 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004535 if (bestComponent == null
4536 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4537 loge("The calling package is not allowed to select ISD-R.");
4538 throw new SecurityException(
4539 "The calling package is not allowed to select ISD-R.");
4540 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004541 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004542
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004543 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004544 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4545 null /* workSource */);
4546 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004547
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004548 // Append the returned status code to the end of the response payload.
4549 String s = Integer.toHexString(
4550 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4551 if (response.payload != null) {
4552 s = IccUtils.bytesToHexString(response.payload) + s;
4553 }
4554 return s;
4555 } finally {
4556 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004557 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004558 }
4559
4560 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004561 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004562 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004563 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4564 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004565
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004566 final long identity = Binder.clearCallingIdentity();
4567 try {
4568 if (DBG) {
4569 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4570 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4571 }
4572
4573 IccIoResult response =
4574 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4575 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4576 subId);
4577
4578 if (DBG) {
4579 log("Exchange SIM_IO [R]" + response);
4580 }
4581
4582 byte[] result = null;
4583 int length = 2;
4584 if (response.payload != null) {
4585 length = 2 + response.payload.length;
4586 result = new byte[length];
4587 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4588 } else {
4589 result = new byte[length];
4590 }
4591
4592 result[length - 1] = (byte) response.sw2;
4593 result[length - 2] = (byte) response.sw1;
4594 return result;
4595 } finally {
4596 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004597 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004598 }
4599
Nathan Haroldb3014052017-01-25 15:57:32 -08004600 /**
4601 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4602 * on a particular subscription
4603 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004604 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4605 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004606 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004607 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004608 return null;
4609 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004610
4611 final long identity = Binder.clearCallingIdentity();
4612 try {
4613 if (appType != TelephonyManager.APPTYPE_USIM
4614 && appType != TelephonyManager.APPTYPE_SIM) {
4615 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4616 return null;
4617 }
4618 Object response = sendRequest(
4619 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4620 if (response instanceof String[]) {
4621 return (String[]) response;
4622 }
yincheng zhaod698b842019-09-06 17:06:54 -07004623 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004624 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004625 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004626 } finally {
4627 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004628 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004629 }
4630
yincheng zhaod698b842019-09-06 17:06:54 -07004631 /**
4632 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4633 * subscription.
4634 *
4635 * @param subId the id of the subscription.
4636 * @param appType the uicc app type, must be USIM or SIM.
4637 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4638 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004639 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004640 * @return number of fplmns that is successfully written to the SIM.
4641 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004642 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4643 String callingFeatureId) {
4644 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4645 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004646 if (DBG) logv("no permissions for setForbiddenplmns");
4647 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4648 }
4649 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4650 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4651 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4652 }
4653 if (fplmns == null) {
4654 throw new IllegalArgumentException("Fplmn List provided is null");
4655 }
4656 for (String fplmn : fplmns) {
4657 if (!CellIdentity.isValidPlmn(fplmn)) {
4658 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4659 }
4660 }
4661 final long identity = Binder.clearCallingIdentity();
4662 try {
4663 Object response = sendRequest(
4664 CMD_SET_FORBIDDEN_PLMNS,
4665 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4666 subId);
4667 return (int) response;
4668 } finally {
4669 Binder.restoreCallingIdentity(identity);
4670 }
4671 }
4672
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004673 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004674 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4676 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004677
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004678 final long identity = Binder.clearCallingIdentity();
4679 try {
4680 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4681 if (response.payload == null) {
4682 return "";
4683 }
Evan Charltonc66da362014-05-16 14:06:40 -07004684
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004685 // Append the returned status code to the end of the response payload.
4686 String s = Integer.toHexString(
4687 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4688 s = IccUtils.bytesToHexString(response.payload) + s;
4689 return s;
4690 } finally {
4691 Binder.restoreCallingIdentity(identity);
4692 }
Evan Charltonc66da362014-05-16 14:06:40 -07004693 }
4694
Jake Hambye994d462014-02-03 13:10:13 -08004695 /**
4696 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4697 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4698 *
4699 * @param itemID the ID of the item to read
4700 * @return the NV item as a String, or null on error.
4701 */
4702 @Override
4703 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004704 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004705 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4706 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004707
4708 final long identity = Binder.clearCallingIdentity();
4709 try {
4710 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004711 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004712 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4713 return value;
4714 } finally {
4715 Binder.restoreCallingIdentity(identity);
4716 }
Jake Hambye994d462014-02-03 13:10:13 -08004717 }
4718
4719 /**
4720 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4721 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4722 *
4723 * @param itemID the ID of the item to read
4724 * @param itemValue the value to write, as a String
4725 * @return true on success; false on any failure
4726 */
4727 @Override
4728 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004729 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4731 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004732
4733 final long identity = Binder.clearCallingIdentity();
4734 try {
4735 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4736 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004737 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004738 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4739 return success;
4740 } finally {
4741 Binder.restoreCallingIdentity(identity);
4742 }
Jake Hambye994d462014-02-03 13:10:13 -08004743 }
4744
4745 /**
4746 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4747 * Used for device configuration by some CDMA operators.
4748 *
4749 * @param preferredRoamingList byte array containing the new PRL
4750 * @return true on success; false on any failure
4751 */
4752 @Override
4753 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004754 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4755 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004756
4757 final long identity = Binder.clearCallingIdentity();
4758 try {
4759 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4760 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4761 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4762 return success;
4763 } finally {
4764 Binder.restoreCallingIdentity(identity);
4765 }
Jake Hambye994d462014-02-03 13:10:13 -08004766 }
4767
4768 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004769 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004770 * Used for device configuration by some CDMA operators.
4771 *
chen xu6dac5ab2018-10-26 17:39:23 -07004772 * @param slotIndex - device slot.
4773 *
Jake Hambye994d462014-02-03 13:10:13 -08004774 * @return true on success; false on any failure
4775 */
4776 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004777 public boolean resetModemConfig(int slotIndex) {
4778 Phone phone = PhoneFactory.getPhone(slotIndex);
4779 if (phone != null) {
4780 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4781 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004782
chen xu6dac5ab2018-10-26 17:39:23 -07004783 final long identity = Binder.clearCallingIdentity();
4784 try {
4785 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4786 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4787 return success;
4788 } finally {
4789 Binder.restoreCallingIdentity(identity);
4790 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004791 }
chen xu6dac5ab2018-10-26 17:39:23 -07004792 return false;
4793 }
4794
4795 /**
4796 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4797 *
4798 * @param slotIndex - device slot.
4799 *
4800 * @return true on success; false on any failure
4801 */
4802 @Override
4803 public boolean rebootModem(int slotIndex) {
4804 Phone phone = PhoneFactory.getPhone(slotIndex);
4805 if (phone != null) {
4806 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4807 mApp, phone.getSubId(), "rebootModem");
4808
4809 final long identity = Binder.clearCallingIdentity();
4810 try {
4811 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4812 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4813 return success;
4814 } finally {
4815 Binder.restoreCallingIdentity(identity);
4816 }
4817 }
4818 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004819 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004820
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004821 public String[] getPcscfAddress(String apnType, String callingPackage,
4822 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004823 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004824 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4825 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004826 return new String[0];
4827 }
4828
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004829 final long identity = Binder.clearCallingIdentity();
4830 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004831 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004832 } finally {
4833 Binder.restoreCallingIdentity(identity);
4834 }
Wink Saville36469e72014-06-11 15:17:00 -07004835 }
4836
Brad Ebinger51f743a2017-01-23 13:50:20 -08004837 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004838 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4839 * {@link #disableIms(int)}.
4840 * @param slotIndex device slot.
4841 */
4842 public void resetIms(int slotIndex) {
4843 enforceModifyPermission();
4844
4845 final long identity = Binder.clearCallingIdentity();
4846 try {
4847 if (mImsResolver == null) {
4848 // may happen if the does not support IMS.
4849 return;
4850 }
4851 mImsResolver.disableIms(slotIndex);
4852 mImsResolver.enableIms(slotIndex);
4853 } finally {
4854 Binder.restoreCallingIdentity(identity);
4855 }
4856 }
4857
4858 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004859 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4860 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004861 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004862 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004863 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004864
4865 final long identity = Binder.clearCallingIdentity();
4866 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004867 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004868 // may happen if the device does not support IMS.
4869 return;
4870 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004871 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004872 } finally {
4873 Binder.restoreCallingIdentity(identity);
4874 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004875 }
4876
4877 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004878 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4879 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004880 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004881 public void disableIms(int slotId) {
4882 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004883
4884 final long identity = Binder.clearCallingIdentity();
4885 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004886 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004887 // may happen if the device does not support IMS.
4888 return;
4889 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004890 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004891 } finally {
4892 Binder.restoreCallingIdentity(identity);
4893 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004894 }
4895
4896 /**
4897 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4898 * feature or {@link null} if the service is not available. If the feature is available, the
4899 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4900 */
4901 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004902 IImsServiceFeatureCallback callback) {
4903 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004904
4905 final long identity = Binder.clearCallingIdentity();
4906 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004907 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004908 // may happen if the device does not support IMS.
4909 return null;
4910 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004911 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004912 } finally {
4913 Binder.restoreCallingIdentity(identity);
4914 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004915 }
4916
4917 /**
4918 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4919 * feature during emergency calling or {@link null} if the service is not available. If the
4920 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4921 * listener for feature updates.
4922 */
4923 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
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 null;
4931 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004932 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004933 } finally {
4934 Binder.restoreCallingIdentity(identity);
4935 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004936 }
4937
Brad Ebinger5f64b052017-12-14 14:26:15 -08004938 /**
4939 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004940 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004941 */
4942 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4943 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004944
4945 final long identity = Binder.clearCallingIdentity();
4946 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004947 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004948 // may happen if the device does not support IMS.
4949 return null;
4950 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004951 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004952 } finally {
4953 Binder.restoreCallingIdentity(identity);
4954 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004955 }
4956
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004957 /**
4958 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004959 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004960 */
4961 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4962 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004963
4964 final long identity = Binder.clearCallingIdentity();
4965 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004966 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004967 // may happen if the device does not support IMS.
4968 return null;
4969 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004970 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004971 } finally {
4972 Binder.restoreCallingIdentity(identity);
4973 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004974 }
4975
Brad Ebinger884c07b2018-02-15 16:17:40 -08004976 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004977 * Sets the ImsService Package Name that Telephony will bind to.
4978 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08004979 * @param slotIndex the slot ID that the ImsService should bind for.
4980 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004981 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004982 * @param featureTypes An integer array of feature types associated with a packageName.
4983 * @param packageName The name of the package that the current configuration will be replaced
4984 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004985 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004986 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004987 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4988 int[] featureTypes, String packageName) {
4989 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4990 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004991 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4992 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08004993 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004994
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004995 final long identity = Binder.clearCallingIdentity();
4996 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004997 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004998 // may happen if the device does not support IMS.
4999 return false;
5000 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005001 Map<Integer, String> featureConfig = new HashMap<>();
5002 for (int featureType : featureTypes) {
5003 featureConfig.put(featureType, packageName);
5004 }
5005 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5006 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005007 } finally {
5008 Binder.restoreCallingIdentity(identity);
5009 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005010 }
5011
5012 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005013 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005014 *
5015 * @param slotId The slot that the ImsService is associated with.
5016 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5017 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005018 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005019 * @return the package name of the ImsService configuration.
5020 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005021 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5022 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005023 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005024 TelephonyPermissions
5025 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5026 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5027 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005028
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005029 final long identity = Binder.clearCallingIdentity();
5030 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005031 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005032 // may happen if the device does not support IMS.
5033 return "";
5034 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005035 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005036 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5037 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005038 } finally {
5039 Binder.restoreCallingIdentity(identity);
5040 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005041 }
5042
Brad Ebinger77b832e2019-10-17 17:03:22 -07005043 /**
5044 * Get the MmTelFeature state associated with the requested subscription id.
5045 * @param subId The subscription that the MmTelFeature is associated with.
5046 * @param callback A callback with an integer containing the
5047 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5048 */
5049 @Override
5050 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5051 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5052 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5053 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5054 "IMS not available on device.");
5055 }
5056 final long token = Binder.clearCallingIdentity();
5057 try {
5058 int slotId = getSlotIndex(subId);
5059 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5060 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5061 + subId + "'");
5062 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5063 }
5064 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5065 try {
5066 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5067 } catch (RemoteException e) {
5068 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5069 + "Ignore");
5070 }
5071 });
5072 } finally {
5073 Binder.restoreCallingIdentity(token);
5074 }
5075 }
5076
Wink Saville36469e72014-06-11 15:17:00 -07005077 public void setImsRegistrationState(boolean registered) {
5078 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005079
5080 final long identity = Binder.clearCallingIdentity();
5081 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005082 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005083 } finally {
5084 Binder.restoreCallingIdentity(identity);
5085 }
Wink Saville36469e72014-06-11 15:17:00 -07005086 }
5087
5088 /**
Stuart Scott54788802015-03-30 13:18:01 -07005089 * Set the network selection mode to automatic.
5090 *
5091 */
5092 @Override
5093 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5095 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005096
5097 final long identity = Binder.clearCallingIdentity();
5098 try {
shilufc958392020-01-20 11:36:01 -08005099 if (!isActiveSubscription(subId)) {
5100 return;
5101 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005102 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5103 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5104 } finally {
5105 Binder.restoreCallingIdentity(identity);
5106 }
Stuart Scott54788802015-03-30 13:18:01 -07005107 }
5108
Pengquan Mengea84e042018-09-20 14:57:26 -07005109 /**
5110 * Ask the radio to connect to the input network and change selection mode to manual.
5111 *
5112 * @param subId the id of the subscription.
5113 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5114 * the operator to attach to.
5115 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5116 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5117 * normal network selection next time.
5118 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005119 */
5120 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005121 public boolean setNetworkSelectionModeManual(
5122 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005123 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5124 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005125
5126 if (!isActiveSubscription(subId)) {
5127 return false;
5128 }
5129
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005130 final long identity = Binder.clearCallingIdentity();
5131 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005132 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005133 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005134 if (DBG) {
5135 log("setNetworkSelectionModeManual: subId: " + subId
5136 + " operator: " + operatorInfo);
5137 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005138 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5139 } finally {
5140 Binder.restoreCallingIdentity(identity);
5141 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005142 }
5143
5144 /**
5145 * Scans for available networks.
5146 */
5147 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005148 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5149 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5151 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005152 LocationAccessPolicy.LocationPermissionResult locationResult =
5153 LocationAccessPolicy.checkLocationPermission(mApp,
5154 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5155 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005156 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005157 .setCallingPid(Binder.getCallingPid())
5158 .setCallingUid(Binder.getCallingUid())
5159 .setMethod("getCellNetworkScanResults")
5160 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5161 .build());
5162 switch (locationResult) {
5163 case DENIED_HARD:
5164 throw new SecurityException("Not allowed to access scan results -- location");
5165 case DENIED_SOFT:
5166 return null;
5167 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005168
Pengquan Menga1bb6272018-09-06 09:59:22 -07005169 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005170 try {
5171 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005172 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005173 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005174 } finally {
5175 Binder.restoreCallingIdentity(identity);
5176 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005177 }
5178
5179 /**
sqian80370722020-01-29 15:02:51 -08005180 * Get the call forwarding info, given the call forwarding reason.
5181 */
5182 @Override
5183 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5184 enforceReadPrivilegedPermission("getCallForwarding");
5185 long identity = Binder.clearCallingIdentity();
5186 try {
5187 if (DBG) {
5188 log("getCallForwarding: subId " + subId
5189 + " callForwardingReason" + callForwardingReason);
5190 }
5191 return (CallForwardingInfo) sendRequest(
5192 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5193 } finally {
5194 Binder.restoreCallingIdentity(identity);
5195 }
5196 }
5197
5198 /**
5199 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5200 * reason, the number to forward, and the timeout before the forwarding is attempted.
5201 */
5202 @Override
5203 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5204 enforceModifyPermission();
5205 long identity = Binder.clearCallingIdentity();
5206 try {
5207 if (DBG) {
5208 log("setCallForwarding: subId " + subId
5209 + " callForwardingInfo" + callForwardingInfo);
5210 }
5211 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5212 } finally {
5213 Binder.restoreCallingIdentity(identity);
5214 }
5215 }
5216
5217 /**
5218 * Get the call forwarding info, given the call forwarding reason.
5219 */
5220 @Override
5221 public int getCallWaitingStatus(int subId) {
5222 enforceReadPrivilegedPermission("getCallForwarding");
5223 long identity = Binder.clearCallingIdentity();
5224 try {
5225 if (DBG) log("getCallWaitingStatus: subId " + subId);
5226 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5227 } finally {
5228 Binder.restoreCallingIdentity(identity);
5229 }
5230 }
5231
5232 /**
5233 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5234 * reason, the number to forward, and the timeout before the forwarding is attempted.
5235 */
5236 @Override
5237 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5238 enforceModifyPermission();
5239 long identity = Binder.clearCallingIdentity();
5240 try {
5241 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5242 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5243 } finally {
5244 Binder.restoreCallingIdentity(identity);
5245 }
5246 }
5247
5248 /**
yinxub1bed742017-04-17 11:45:04 -07005249 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005250 *
yinxub1bed742017-04-17 11:45:04 -07005251 * @param subId id of the subscription
5252 * @param request contains the radio access networks with bands/channels to scan
5253 * @param messenger callback messenger for scan results or errors
5254 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005255 * @return the id of the requested scan which can be used to stop the scan.
5256 */
5257 @Override
5258 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005259 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005260 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5261 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005262 LocationAccessPolicy.LocationPermissionResult locationResult =
5263 LocationAccessPolicy.checkLocationPermission(mApp,
5264 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5265 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005266 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005267 .setCallingPid(Binder.getCallingPid())
5268 .setCallingUid(Binder.getCallingUid())
5269 .setMethod("requestNetworkScan")
5270 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5271 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005272 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005273 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005274 if (e != null) {
5275 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5276 throw e;
5277 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005278 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005279 return TelephonyScanManager.INVALID_SCAN_ID;
5280 }
5281 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005282 }
Hall Liu912dfd32019-04-25 14:02:26 -07005283 int callingUid = Binder.getCallingUid();
5284 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005285 final long identity = Binder.clearCallingIdentity();
5286 try {
5287 return mNetworkScanRequestTracker.startNetworkScan(
5288 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005289 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005290 } finally {
5291 Binder.restoreCallingIdentity(identity);
5292 }
yinxu504e1392017-04-12 16:03:22 -07005293 }
5294
Hall Liub2ac8ef2019-02-28 15:56:23 -08005295 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005296 NetworkScanRequest request, int subId) {
5297 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5298 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5299 boolean hasNetworkScanPermission =
5300 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5301 == PERMISSION_GRANTED;
5302
5303 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5304 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5305 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005306 }
5307
5308 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5309 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005310 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5311 return new SecurityException("Specific channels must not be"
5312 + " scanned without location access.");
5313 }
5314 }
5315 }
5316
Hall Liub2ac8ef2019-02-28 15:56:23 -08005317 return null;
5318 }
5319
yinxu504e1392017-04-12 16:03:22 -07005320 /**
5321 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005322 *
5323 * @param subId id of the subscription
5324 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005325 */
5326 @Override
5327 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5329 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005330
Hall Liu912dfd32019-04-25 14:02:26 -07005331 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005332 final long identity = Binder.clearCallingIdentity();
5333 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005334 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005335 } finally {
5336 Binder.restoreCallingIdentity(identity);
5337 }
yinxu504e1392017-04-12 16:03:22 -07005338 }
5339
5340 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005341 * Get the calculated preferred network type.
5342 * Used for debugging incorrect network type.
5343 *
5344 * @return the preferred network type, defined in RILConstants.java.
5345 */
5346 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005347 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005348 final Phone defaultPhone = getDefaultPhone();
5349 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005350 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005351 return RILConstants.PREFERRED_NETWORK_MODE;
5352 }
5353
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005354 final long identity = Binder.clearCallingIdentity();
5355 try {
5356 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005357 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358 } finally {
5359 Binder.restoreCallingIdentity(identity);
5360 }
Junda Liu84d15a22014-07-02 11:21:04 -07005361 }
5362
5363 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005364 * Get the preferred network type.
5365 * Used for device configuration by some CDMA operators.
5366 *
5367 * @return the preferred network type, defined in RILConstants.java.
5368 */
5369 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005370 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005371 TelephonyPermissions
5372 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5373 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005374
5375 final long identity = Binder.clearCallingIdentity();
5376 try {
5377 if (DBG) log("getPreferredNetworkType");
5378 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5379 int networkType = (result != null ? result[0] : -1);
5380 if (DBG) log("getPreferredNetworkType: " + networkType);
5381 return networkType;
5382 } finally {
5383 Binder.restoreCallingIdentity(identity);
5384 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005385 }
5386
5387 /**
5388 * Set the preferred network type.
5389 * Used for device configuration by some CDMA operators.
5390 *
5391 * @param networkType the preferred network type, defined in RILConstants.java.
5392 * @return true on success; false on any failure.
5393 */
5394 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005395 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005396 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5397 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005398
5399 final long identity = Binder.clearCallingIdentity();
5400 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005401 Settings.Global.putInt(mApp.getContentResolver(),
5402 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5403 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005404 } finally {
5405 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005406 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005407 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005408
5409 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005410 * Get the allowed network types that store in the telephony provider.
5411 *
5412 * @param subId the id of the subscription.
5413 * @return allowedNetworkTypes the allowed network types.
5414 */
5415 @Override
5416 public long getAllowedNetworkTypes(int subId) {
5417 TelephonyPermissions
5418 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5419 mApp, subId, "getAllowedNetworkTypes");
5420
5421 final long identity = Binder.clearCallingIdentity();
5422 try {
5423 return SubscriptionManager.getLongSubscriptionProperty(
5424 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5425 } finally {
5426 Binder.restoreCallingIdentity(identity);
5427 }
5428 }
5429
5430 /**
5431 * Set the allowed network types.
5432 *
5433 * @param subId the id of the subscription.
5434 * @param allowedNetworkTypes the allowed network types.
5435 * @return true on success; false on any failure.
5436 */
5437 @Override
5438 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5439 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5440 mApp, subId, "setAllowedNetworkTypes");
5441 final long identity = Binder.clearCallingIdentity();
5442 try {
5443 SubscriptionManager.setSubscriptionProperty(subId,
5444 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5445 String.valueOf(allowedNetworkTypes));
5446 return setPreferredNetworkTypesInternal(subId);
5447 } finally {
5448 Binder.restoreCallingIdentity(identity);
5449 }
5450 }
5451
5452 private boolean setPreferredNetworkTypesInternal(int subId) {
5453 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5454 Settings.Global.getInt(mApp.getContentResolver(),
5455 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5456 RILConstants.PREFERRED_NETWORK_MODE));
5457 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5458 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5459 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5460 (int) (networkTypeBitMask & allowedNetworkTypes));
5461
5462 if (DBG) {
5463 log("setPreferredNetworkTypesInternal: subId " + subId
5464 + " networkTypes " + networkTypeBitMask
5465 + " allowedNetworkTypes " + allowedNetworkTypes
5466 + " networkMode " + networkMode);
5467 }
5468
5469 Boolean success = (Boolean) sendRequest(
5470 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5471 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5472 return success;
5473 }
5474
5475 /**
Miaoa84611c2019-03-15 09:21:10 +08005476 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005477 *
Miaoa84611c2019-03-15 09:21:10 +08005478 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005479 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005480 * @hide
5481 */
5482 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005483 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005484 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005485 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005486 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005487 try {
Miaoa84611c2019-03-15 09:21:10 +08005488 if (phone != null) {
5489 return phone.hasMatchedTetherApnSetting();
5490 } else {
5491 return false;
5492 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005493 } finally {
5494 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005495 }
Junda Liu475951f2014-11-07 16:45:03 -08005496 }
5497
5498 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005499 * Set mobile data enabled
5500 * Used by the user through settings etc to turn on/off mobile data
5501 *
5502 * @param enable {@code true} turn turn data on, else {@code false}
5503 */
5504 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005505 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005506 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5507 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005508
5509 final long identity = Binder.clearCallingIdentity();
5510 try {
5511 int phoneId = mSubscriptionController.getPhoneId(subId);
5512 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5513 Phone phone = PhoneFactory.getPhone(phoneId);
5514 if (phone != null) {
5515 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005516 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005517 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005518 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005519 }
5520 } finally {
5521 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005522 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005523 }
5524
5525 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005526 * Enable or disable always reporting signal strength changes from radio.
5527 *
5528 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5529 */
5530 @Override
5531 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5532 enforceModifyPermission();
5533 enforceSystemCaller();
5534
5535 final long identity = Binder.clearCallingIdentity();
5536 final Phone phone = getPhone(subId);
5537 try {
5538 if (phone != null) {
5539 if (DBG) {
5540 log("setAlwaysReportSignalStrength: subId=" + subId
5541 + " isEnable=" + isEnable);
5542 }
5543 phone.setAlwaysReportSignalStrength(isEnable);
5544 } else {
5545 loge("setAlwaysReportSignalStrength: no phone found for subId="
5546 + subId);
5547 }
5548 } finally {
5549 Binder.restoreCallingIdentity(identity);
5550 }
5551 }
5552
5553 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005554 * Get the user enabled state of Mobile Data.
5555 *
5556 * TODO: remove and use isUserDataEnabled.
5557 * This can't be removed now because some vendor codes
5558 * calls through ITelephony directly while they should
5559 * use TelephonyManager.
5560 *
5561 * @return true on enabled
5562 */
5563 @Override
5564 public boolean getDataEnabled(int subId) {
5565 return isUserDataEnabled(subId);
5566 }
5567
5568 /**
5569 * Get whether mobile data is enabled per user setting.
5570 *
5571 * There are other factors deciding whether mobile data is actually enabled, but they are
5572 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005573 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005574 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005575 *
5576 * @return {@code true} if data is enabled else {@code false}
5577 */
5578 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005579 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005580 try {
5581 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5582 null);
5583 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005584 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5585 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005586 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005587
5588 final long identity = Binder.clearCallingIdentity();
5589 try {
5590 int phoneId = mSubscriptionController.getPhoneId(subId);
5591 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5592 Phone phone = PhoneFactory.getPhone(phoneId);
5593 if (phone != null) {
5594 boolean retVal = phone.isUserDataEnabled();
5595 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5596 return retVal;
5597 } else {
5598 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5599 return false;
5600 }
5601 } finally {
5602 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005603 }
5604 }
5605
5606 /**
5607 * Get whether mobile data is enabled.
5608 *
5609 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5610 * whether mobile data is actually enabled.
5611 *
5612 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5613 *
5614 * @return {@code true} if data is enabled else {@code false}
5615 */
5616 @Override
5617 public boolean isDataEnabled(int subId) {
5618 try {
5619 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5620 null);
5621 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005622 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5623 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005624 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005625
5626 final long identity = Binder.clearCallingIdentity();
5627 try {
5628 int phoneId = mSubscriptionController.getPhoneId(subId);
5629 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5630 Phone phone = PhoneFactory.getPhone(phoneId);
5631 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005632 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005633 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5634 return retVal;
5635 } else {
5636 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5637 return false;
5638 }
5639 } finally {
5640 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005641 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005642 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005643
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005644 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5645 Phone phone) {
5646 //load access rules from carrier configs, and check those as well: b/139133814
5647 SubscriptionController subController = SubscriptionController.getInstance();
5648 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5649 || subController == null) return privilegeFromSim;
5650
5651 int uid = Binder.getCallingUid();
5652 PackageManager pkgMgr = phone.getContext().getPackageManager();
5653 String[] packages = pkgMgr.getPackagesForUid(uid);
5654
5655 final long identity = Binder.clearCallingIdentity();
5656 try {
5657 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5658 SubscriptionManager subManager = (SubscriptionManager)
5659 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5660 for (String pkg : packages) {
5661 if (subManager.canManageSubscription(subInfo, pkg)) {
5662 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5663 }
5664 }
5665 return privilegeFromSim;
5666 } finally {
5667 Binder.restoreCallingIdentity(identity);
5668 }
5669 }
5670
5671 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5672 String pkgName) {
5673 //load access rules from carrier configs, and check those as well: b/139133814
5674 SubscriptionController subController = SubscriptionController.getInstance();
5675 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5676 || subController == null) return privilegeFromSim;
5677
5678 final long identity = Binder.clearCallingIdentity();
5679 try {
5680 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5681 SubscriptionManager subManager = (SubscriptionManager)
5682 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5683 return subManager.canManageSubscription(subInfo, pkgName)
5684 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5685 } finally {
5686 Binder.restoreCallingIdentity(identity);
5687 }
5688 }
5689
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005690 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005691 public int getCarrierPrivilegeStatus(int subId) {
5692 final Phone phone = getPhone(subId);
5693 if (phone == null) {
5694 loge("getCarrierPrivilegeStatus: Invalid subId");
5695 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5696 }
5697 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005698 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005699 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005700 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5701 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005702
5703 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5704 card.getCarrierPrivilegeStatusForCurrentTransaction(
5705 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005706 }
Junda Liu29340342014-07-10 15:23:27 -07005707
5708 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005709 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005710 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005711 final Phone phone = getPhone(subId);
5712 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005713 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005714 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5715 }
5716 UiccProfile profile =
5717 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5718 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005719 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005720 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5721 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005722 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005723 profile.getCarrierPrivilegeStatusForUid(
5724 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005725 }
5726
5727 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005728 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5729 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005730 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005731 }
5732
5733 int phoneId = SubscriptionManager.getPhoneId(subId);
5734 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005735 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005736 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005737 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5738 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005739 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5740 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5741 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005742 }
5743
5744 @Override
5745 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005746 if (TextUtils.isEmpty(pkgName))
5747 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005748 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5749 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5750 UiccCard card = UiccController.getInstance().getUiccCard(i);
5751 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005752 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005753 continue;
5754 }
5755
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005756 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5757 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5758 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005759 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5760 break;
5761 }
5762 }
5763
5764 return result;
Junda Liu29340342014-07-10 15:23:27 -07005765 }
Derek Tan89e89d42014-07-08 17:00:10 -07005766
5767 @Override
Junda Liue64de782015-04-16 17:19:16 -07005768 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5769 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5770 loge("phoneId " + phoneId + " is not valid.");
5771 return null;
5772 }
5773 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005774 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005775 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005776 return null ;
5777 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005778 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005779 }
5780
Amith Yamasani6e118872016-02-19 12:53:51 -08005781 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005782 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005783 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005784 List<String> privilegedPackages = new ArrayList<>();
5785 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005786 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5787 // has UICC in that slot.
5788 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005789 if (card.hasCarrierPrivilegeRules()) {
5790 if (packages == null) {
5791 // Only check packages in user 0 for now
5792 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005793 PackageManager.MATCH_DISABLED_COMPONENTS
5794 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005795 | PackageManager.GET_SIGNING_CERTIFICATES,
5796 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005797 }
5798 for (int p = packages.size() - 1; p >= 0; p--) {
5799 PackageInfo pkgInfo = packages.get(p);
5800 if (pkgInfo != null && pkgInfo.packageName != null
5801 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005802 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005803 privilegedPackages.add(pkgInfo.packageName);
5804 }
5805 }
5806 }
5807 }
5808 return privilegedPackages;
5809 }
5810
chen xuf7e9fe82019-05-09 19:31:02 -07005811 @Override
5812 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005813 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5814
5815 final long identity = Binder.clearCallingIdentity();
5816
chen xuf7e9fe82019-05-09 19:31:02 -07005817 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005818 try {
5819 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5820 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5821 }
5822 } finally {
5823 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005824 }
5825 return privilegedPackages;
5826 }
5827
Wink Savilleb564aae2014-10-23 10:18:09 -07005828 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005829 final Phone phone = getPhone(subId);
5830 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005831 if (card == null) {
5832 loge("getIccId: No UICC");
5833 return null;
5834 }
5835 String iccId = card.getIccId();
5836 if (TextUtils.isEmpty(iccId)) {
5837 loge("getIccId: ICC ID is null or empty.");
5838 return null;
5839 }
5840 return iccId;
5841 }
5842
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005843 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005844 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5845 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08005846 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005847 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005848
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005849 final long identity = Binder.clearCallingIdentity();
5850 try {
5851 final String iccId = getIccId(subId);
5852 final Phone phone = getPhone(subId);
5853 if (phone == null) {
5854 return false;
5855 }
5856 final String subscriberId = phone.getSubscriberId();
5857
5858 if (DBG_MERGE) {
5859 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5860 + subscriberId + " to " + number);
5861 }
5862
5863 if (TextUtils.isEmpty(iccId)) {
5864 return false;
5865 }
5866
5867 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5868
5869 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5870 if (alphaTag == null) {
5871 editor.remove(alphaTagPrefKey);
5872 } else {
5873 editor.putString(alphaTagPrefKey, alphaTag);
5874 }
5875
5876 // Record both the line number and IMSI for this ICCID, since we need to
5877 // track all merged IMSIs based on line number
5878 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5879 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5880 if (number == null) {
5881 editor.remove(numberPrefKey);
5882 editor.remove(subscriberPrefKey);
5883 } else {
5884 editor.putString(numberPrefKey, number);
5885 editor.putString(subscriberPrefKey, subscriberId);
5886 }
5887
5888 editor.commit();
5889 return true;
5890 } finally {
5891 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005892 }
Derek Tan7226c842014-07-02 17:42:23 -07005893 }
5894
5895 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005896 public String getLine1NumberForDisplay(int subId, String callingPackage,
5897 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005898 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005899 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005900 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005901 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005902 return null;
5903 }
Derek Tan97ebb422014-09-05 16:55:38 -07005904
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005905 final long identity = Binder.clearCallingIdentity();
5906 try {
5907 String iccId = getIccId(subId);
5908 if (iccId != null) {
5909 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5910 if (DBG_MERGE) {
5911 log("getLine1NumberForDisplay returning "
5912 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5913 }
5914 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005915 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005916 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5917 return null;
5918 } finally {
5919 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005920 }
Derek Tan7226c842014-07-02 17:42:23 -07005921 }
5922
5923 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005924 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5925 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005926 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005927 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005928 return null;
5929 }
Derek Tan97ebb422014-09-05 16:55:38 -07005930
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005931 final long identity = Binder.clearCallingIdentity();
5932 try {
5933 String iccId = getIccId(subId);
5934 if (iccId != null) {
5935 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5936 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5937 }
5938 return null;
5939 } finally {
5940 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005941 }
Derek Tan7226c842014-07-02 17:42:23 -07005942 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005943
5944 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005945 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5946 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005947 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5948 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005949 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005950 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005951 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005952 return null;
5953 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005954
Jordan Liub49b04b2019-05-06 14:45:15 -07005955 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5956 // the process, where TelephonyManager was instantiated.
5957 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005958 final long identity = Binder.clearCallingIdentity();
5959 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005960 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005961 final TelephonyManager tele = TelephonyManager.from(context);
5962 final SubscriptionManager sub = SubscriptionManager.from(context);
5963
5964 // Figure out what subscribers are currently active
5965 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005966
Jordan Liub49b04b2019-05-06 14:45:15 -07005967 // Only consider subs which match the current subId
5968 // This logic can be simplified. See b/131189269 for progress.
5969 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005970 activeSubscriberIds.add(tele.getSubscriberId(subId));
5971 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005972
5973 // First pass, find a number override for an active subscriber
5974 String mergeNumber = null;
5975 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5976 for (String key : prefs.keySet()) {
5977 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5978 final String subscriberId = (String) prefs.get(key);
5979 if (activeSubscriberIds.contains(subscriberId)) {
5980 final String iccId = key.substring(
5981 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5982 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5983 mergeNumber = (String) prefs.get(numberKey);
5984 if (DBG_MERGE) {
5985 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5986 + " for active subscriber " + subscriberId);
5987 }
5988 if (!TextUtils.isEmpty(mergeNumber)) {
5989 break;
5990 }
5991 }
5992 }
5993 }
5994
5995 // Shortcut when no active merged subscribers
5996 if (TextUtils.isEmpty(mergeNumber)) {
5997 return null;
5998 }
5999
6000 // Second pass, find all subscribers under that line override
6001 final ArraySet<String> result = new ArraySet<>();
6002 for (String key : prefs.keySet()) {
6003 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6004 final String number = (String) prefs.get(key);
6005 if (mergeNumber.equals(number)) {
6006 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6007 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6008 final String subscriberId = (String) prefs.get(subscriberKey);
6009 if (!TextUtils.isEmpty(subscriberId)) {
6010 result.add(subscriberId);
6011 }
6012 }
6013 }
6014 }
6015
6016 final String[] resultArray = result.toArray(new String[result.size()]);
6017 Arrays.sort(resultArray);
6018 if (DBG_MERGE) {
6019 Slog.d(LOG_TAG,
6020 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6021 }
6022 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006023 } finally {
6024 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006025 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006026 }
6027
6028 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07006029 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
6030 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
6031
6032 final long identity = Binder.clearCallingIdentity();
6033 try {
6034 final TelephonyManager telephonyManager = mApp.getSystemService(
6035 TelephonyManager.class);
6036 String subscriberId = telephonyManager.getSubscriberId(subId);
6037 if (subscriberId == null) {
6038 if (DBG) {
6039 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
6040 + subId);
6041 }
6042 return null;
6043 }
6044
6045 final SubscriptionInfo info = SubscriptionController.getInstance()
6046 .getSubscriptionInfo(subId);
6047 final ParcelUuid groupUuid = info.getGroupUuid();
6048 // If it doesn't belong to any group, return just subscriberId of itself.
6049 if (groupUuid == null) {
6050 return new String[]{subscriberId};
6051 }
6052
6053 // Get all subscriberIds from the group.
6054 final List<String> mergedSubscriberIds = new ArrayList<>();
6055 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006056 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
6057 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07006058 for (SubscriptionInfo subInfo : groupInfos) {
6059 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6060 if (subscriberId != null) {
6061 mergedSubscriberIds.add(subscriberId);
6062 }
6063 }
6064
6065 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6066 } finally {
6067 Binder.restoreCallingIdentity(identity);
6068
6069 }
6070 }
6071
6072 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006073 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006074 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006075 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006076
6077 final long identity = Binder.clearCallingIdentity();
6078 try {
6079 final Phone phone = getPhone(subId);
6080 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6081 } finally {
6082 Binder.restoreCallingIdentity(identity);
6083 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006084 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006085
6086 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006087 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006088 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6089 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006090 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6091 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006092
6093 final long identity = Binder.clearCallingIdentity();
6094 try {
6095 final Phone phone = getPhone(subId);
6096 if (phone == null) {
6097 return false;
6098 }
6099 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6100 cdmaNonRoamingList);
6101 } finally {
6102 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006103 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006104 }
6105
6106 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006107 @Deprecated
6108 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6109 enforceModifyPermission();
6110
6111 int returnValue = 0;
6112 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006113 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006114 if(result.exception == null) {
6115 if (result.result != null) {
6116 byte[] responseData = (byte[])(result.result);
6117 if(responseData.length > oemResp.length) {
6118 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6119 responseData.length + "bytes. Buffer Size is " +
6120 oemResp.length + "bytes.");
6121 }
6122 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6123 returnValue = responseData.length;
6124 }
6125 } else {
6126 CommandException ex = (CommandException) result.exception;
6127 returnValue = ex.getCommandError().ordinal();
6128 if(returnValue > 0) returnValue *= -1;
6129 }
6130 } catch (RuntimeException e) {
6131 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6132 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6133 if(returnValue > 0) returnValue *= -1;
6134 }
6135
6136 return returnValue;
6137 }
6138
6139 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006140 public void setRadioCapability(RadioAccessFamily[] rafs) {
6141 try {
6142 ProxyController.getInstance().setRadioCapability(rafs);
6143 } catch (RuntimeException e) {
6144 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6145 }
6146 }
6147
6148 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006149 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006150 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006151 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006152 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006153 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006154 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006155 final long identity = Binder.clearCallingIdentity();
6156 try {
chen xub97461a2018-10-26 14:17:57 -07006157 TelephonyPermissions
6158 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6159 mApp, phone.getSubId(), "getRadioAccessFamily");
6160 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006161 } finally {
6162 Binder.restoreCallingIdentity(identity);
6163 }
chen xub97461a2018-10-26 14:17:57 -07006164 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006165 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006166
6167 @Override
6168 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006169 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006170 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006171
6172 final long identity = Binder.clearCallingIdentity();
6173 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006174 ImsManager.getInstance(defaultPhone.getContext(),
6175 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006176 } finally {
6177 Binder.restoreCallingIdentity(identity);
6178 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006179 }
6180
6181 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006182 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006183 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006184 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6185 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006186 return false;
6187 }
Svet Ganovb320e182015-04-16 12:30:10 -07006188
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006189 final long identity = Binder.clearCallingIdentity();
6190 try {
6191 // Check the user preference and the system-level IMS setting. Even if the user has
6192 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6193 // In the long run, we may instead need to check if there exists a connection service
6194 // which can support video calling.
6195 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006196 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006197 return imsManager.isVtEnabledByPlatform()
6198 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6199 && imsManager.isVtEnabledByUser();
6200 } finally {
6201 Binder.restoreCallingIdentity(identity);
6202 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006203 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006204
Andrew Leea1239f22015-03-02 17:44:07 -08006205 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006206 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6207 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006208 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006209 mApp, subId, callingPackage, callingFeatureId,
6210 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006211 return false;
6212 }
6213
6214 final long identity = Binder.clearCallingIdentity();
6215 try {
6216 CarrierConfigManager configManager =
6217 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006218 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006219 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6220 } finally {
6221 Binder.restoreCallingIdentity(identity);
6222 }
Andrew Leea1239f22015-03-02 17:44:07 -08006223 }
6224
6225 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006226 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006227 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006228 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006229 return false;
6230 }
6231
6232 final long identity = Binder.clearCallingIdentity();
6233 try {
6234 CarrierConfigManager configManager =
6235 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006236 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006237 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6238 } finally {
6239 Binder.restoreCallingIdentity(identity);
6240 }
Andrew Leea1239f22015-03-02 17:44:07 -08006241 }
6242
Andrew Lee9431b832015-03-09 18:46:45 -07006243 @Override
6244 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006245 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006246 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006247 }
6248
6249 @Override
6250 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006251 final long identity = Binder.clearCallingIdentity();
6252 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006253 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006254 } finally {
6255 Binder.restoreCallingIdentity(identity);
6256 }
Andrew Lee9431b832015-03-09 18:46:45 -07006257 }
6258
Hall Liuf6668912018-10-31 17:05:23 -07006259 /**
6260 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6261 * support for the feature and device firmware support.
6262 *
6263 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6264 */
6265 @Override
6266 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006267 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006268 final Phone phone = getPhone(subscriptionId);
6269 if (phone == null) {
6270 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6271 return false;
6272 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006273 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006274 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006275 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6276 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006277 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006278 return isCarrierSupported && isDeviceSupported;
6279 } finally {
6280 Binder.restoreCallingIdentity(identity);
6281 }
Hall Liu98187582018-01-22 19:15:32 -08006282 }
6283
Hall Liuf6668912018-10-31 17:05:23 -07006284 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006285 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6286 * RTT setting, will return true if the device and carrier both support RTT.
6287 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006288 */
6289 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006290 final long identity = Binder.clearCallingIdentity();
6291 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006292 boolean isRttSupported = isRttSupported(subscriptionId);
6293 boolean isUserRttSettingOn = Settings.Secure.getInt(
6294 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6295 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6296 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6297 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006298 } finally {
6299 Binder.restoreCallingIdentity(identity);
6300 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006301 }
6302
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006303 @Deprecated
6304 @Override
6305 public String getDeviceId(String callingPackage) {
6306 return getDeviceIdWithFeature(callingPackage, null);
6307 }
6308
Sanket Padawe7310cc72015-01-14 09:53:20 -08006309 /**
6310 * Returns the unique device ID of phone, for example, the IMEI for
6311 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6312 *
6313 * <p>Requires Permission:
6314 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6315 */
6316 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006317 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006318 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006319 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006320 return null;
6321 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006322 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006323 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006324 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006325 return null;
6326 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006327
6328 final long identity = Binder.clearCallingIdentity();
6329 try {
6330 return phone.getDeviceId();
6331 } finally {
6332 Binder.restoreCallingIdentity(identity);
6333 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006334 }
6335
Ping Sunc67b7c22016-03-02 19:16:45 +08006336 /**
6337 * {@hide}
6338 * Returns the IMS Registration Status on a particular subid
6339 *
6340 * @param subId
6341 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006342 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006343 Phone phone = getPhone(subId);
6344 if (phone != null) {
6345 return phone.isImsRegistered();
6346 } else {
6347 return false;
6348 }
6349 }
6350
Santos Cordon7a1885b2015-02-03 11:15:19 -08006351 @Override
6352 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006353 final long identity = Binder.clearCallingIdentity();
6354 try {
6355 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6356 } finally {
6357 Binder.restoreCallingIdentity(identity);
6358 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006359 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006360
Tyler Gunnf70ed162019-04-03 15:28:53 -07006361 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006362 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006363 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006364 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006365 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006366 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6367 }
6368 final long identity = Binder.clearCallingIdentity();
6369 try {
6370 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6371 } finally {
6372 Binder.restoreCallingIdentity(identity);
6373 }
6374 }
6375
6376 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006377 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6378 final long identity = Binder.clearCallingIdentity();
6379 try {
6380 Phone phone = getPhone(subscriptionId);
6381 if (phone == null) {
6382 return null;
6383 }
6384 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6385 } finally {
6386 Binder.restoreCallingIdentity(identity);
6387 }
6388 }
6389
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006390 /**
6391 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006392 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006393 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006394 final long identity = Binder.clearCallingIdentity();
6395 try {
6396 Phone phone = getPhone(subId);
6397 if (phone != null) {
6398 return phone.isWifiCallingEnabled();
6399 } else {
6400 return false;
6401 }
6402 } finally {
6403 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006404 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006405 }
6406
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006407 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006408 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006409 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006410 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006411 final long identity = Binder.clearCallingIdentity();
6412 try {
6413 Phone phone = getPhone(subId);
6414 if (phone != null) {
6415 return phone.isVideoEnabled();
6416 } else {
6417 return false;
6418 }
6419 } finally {
6420 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006421 }
6422 }
6423
6424 /**
6425 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6426 * defined in {@link ImsRegistrationImplBase}.
6427 */
6428 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006429 final long identity = Binder.clearCallingIdentity();
6430 try {
6431 Phone phone = getPhone(subId);
6432 if (phone != null) {
6433 return phone.getImsRegistrationTech();
6434 } else {
6435 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6436 }
6437 } finally {
6438 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006439 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006440 }
6441
Stuart Scott8eef64f2015-04-08 15:13:54 -07006442 @Override
6443 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006444 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006445 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6446 return;
6447 }
6448
Svet Ganovcc087f82015-05-12 20:35:54 -07006449 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006450
Svet Ganovcc087f82015-05-12 20:35:54 -07006451 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006452 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6453 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006454 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006455 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006456 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006457 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6458 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006459 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006460 // There has been issues when Sms raw table somehow stores orphan
6461 // fragments. They lead to garbled message when new fragments come
6462 // in and combined with those stale ones. In case this happens again,
6463 // user can reset all network settings which will clean up this table.
6464 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006465 // Clean up IMS settings as well here.
6466 int slotId = getSlotIndex(subId);
6467 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6468 ImsManager.getInstance(mApp, slotId).factoryReset();
6469 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006470
6471 // Erase modem config if erase modem on network setting is enabled.
6472 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6473 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6474 if (configValue != null && Boolean.parseBoolean(configValue)) {
6475 sendEraseModemConfig(getDefaultPhone());
6476 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006477 } finally {
6478 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006479 }
6480 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006481
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006482 private void cleanUpSmsRawTable(Context context) {
6483 ContentResolver resolver = context.getContentResolver();
6484 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6485 resolver.delete(uri, null, null);
6486 }
6487
Narayan Kamath1c496c22015-04-16 14:40:19 +01006488 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006489 public String getSimLocaleForSubscriber(int subId) {
6490 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6491 final Phone phone = getPhone(subId);
6492 if (phone == null) {
6493 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006494 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006495 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006496 final long identity = Binder.clearCallingIdentity();
6497 try {
chen xu5d3637b2019-01-21 23:31:38 -08006498 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006499 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08006500 if (info == null) {
6501 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6502 return null;
6503 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006504 // Try and fetch the locale from the carrier properties or from the SIM language
6505 // preferences (EF-PL and EF-LI)...
6506 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006507 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006508 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6509 if (localeFromDefaultSim != null) {
6510 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6511 if (DBG) log("Using locale from subId: " + subId + " locale: "
6512 + localeFromDefaultSim);
6513 return localeFromDefaultSim.toLanguageTag();
6514 } else {
6515 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006516 }
6517 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006518
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006519 // The SIM language preferences only store a language (e.g. fr = French), not an
6520 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6521 // the SIM and carrier preferences does not include a country we add the country
6522 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006523 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006524 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006525 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006526 return mccLocale.toLanguageTag();
6527 }
6528
6529 if (DBG) log("No locale found - returning null");
6530 return null;
6531 } finally {
6532 Binder.restoreCallingIdentity(identity);
6533 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006534 }
6535
6536 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006537 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6538 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006539 }
6540
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006541 /**
6542 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6543 */
6544 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006545 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6546 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006547 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006548
Chenjie Yu1ba97252018-01-11 18:16:20 -08006549 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006550 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006551
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006552 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006553 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6554 * representing the state of the modem.
6555 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006556 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6557 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006558 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006559 */
6560 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006561 public void requestModemActivityInfo(ResultReceiver result) {
6562 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006563 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006564
6565 final long identity = Binder.clearCallingIdentity();
6566 try {
6567 ModemActivityInfo ret = null;
6568 synchronized (mLastModemActivityInfo) {
6569 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6570 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006571 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006572 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006573 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xu13851032019-09-10 18:49:52 -07006574 int[] txTimeMs = info.getTransmitTimeMillis();
6575 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006576 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xu13851032019-09-10 18:49:52 -07006577 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006578 }
6579 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006580 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6581 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006582 mLastModemActivityInfo.setIdleTimeMillis(
6583 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xu13851032019-09-10 18:49:52 -07006584 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6585 mLastModemActivityInfo.setReceiveTimeMillis(
6586 info.getReceiveTimeMillis() + mLastModemActivityInfo
6587 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006588 }
Chen Xu13851032019-09-10 18:49:52 -07006589
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006590 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6591 mLastModemActivityInfo.getSleepTimeMillis(),
6592 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xu13851032019-09-10 18:49:52 -07006593 mLastModemActivityInfo.getTransmitTimeMillis(),
6594 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006595 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006596 Bundle bundle = new Bundle();
6597 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6598 result.send(0, bundle);
6599 } finally {
6600 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006601 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006602 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006603
Siddharth Rayb8114062018-06-17 15:02:38 -07006604 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6605 // less than total activity duration.
6606 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6607 if (info == null) {
6608 return false;
6609 }
6610 int activityDurationMs =
6611 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6612 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006613 int[] txTimeMs = info.getTransmitTimeMillis();
6614 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6615 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006616 }
6617 return (info.isValid()
6618 && (info.getSleepTimeMillis() <= activityDurationMs)
6619 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006620 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006621 && (totalTxTimeMs <= activityDurationMs));
6622 }
6623
Jack Yu85bd38a2015-11-09 11:34:32 -08006624 /**
6625 * {@hide}
6626 * Returns the service state information on specified subscription.
6627 */
6628 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006629 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6630 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006631 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006632 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006633 return null;
6634 }
6635
Hall Liuf19c44f2018-11-27 14:38:17 -08006636 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6637 LocationAccessPolicy.checkLocationPermission(mApp,
6638 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6639 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006640 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006641 .setCallingPid(Binder.getCallingPid())
6642 .setCallingUid(Binder.getCallingUid())
6643 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006644 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006645 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6646 .build());
6647
6648 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6649 LocationAccessPolicy.checkLocationPermission(mApp,
6650 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6651 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006652 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006653 .setCallingPid(Binder.getCallingPid())
6654 .setCallingUid(Binder.getCallingUid())
6655 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006656 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006657 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6658 .build());
6659 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6660 boolean hasFinePermission =
6661 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6662 boolean hasCoarsePermission =
6663 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6664
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006665 final long identity = Binder.clearCallingIdentity();
6666 try {
6667 final Phone phone = getPhone(subId);
6668 if (phone == null) {
6669 return null;
6670 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006671
Hall Liuf19c44f2018-11-27 14:38:17 -08006672 ServiceState ss = phone.getServiceState();
6673
6674 // Scrub out the location info in ServiceState depending on what level of access
6675 // the caller has.
6676 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006677 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6678 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006679 } finally {
6680 Binder.restoreCallingIdentity(identity);
6681 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006682 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006683
6684 /**
6685 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6686 *
6687 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6688 * voicemail ringtone.
6689 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6690 * PhoneAccount.
6691 */
6692 @Override
6693 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006694 final long identity = Binder.clearCallingIdentity();
6695 try {
6696 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6697 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006698 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006699 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006700
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006701 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6702 } finally {
6703 Binder.restoreCallingIdentity(identity);
6704 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006705 }
6706
6707 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006708 * Sets the per-account voicemail ringtone.
6709 *
6710 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6711 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6712 *
6713 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6714 * voicemail ringtone.
6715 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6716 * PhoneAccount.
6717 */
6718 @Override
6719 public void setVoicemailRingtoneUri(String callingPackage,
6720 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006721 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006722 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006723 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6724 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006725 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6726 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6727 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006728 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006729
6730 final long identity = Binder.clearCallingIdentity();
6731 try {
6732 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6733 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006734 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006735 }
6736 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6737 } finally {
6738 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006739 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006740 }
6741
6742 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006743 * Returns whether vibration is set for voicemail notification in Phone settings.
6744 *
6745 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6746 * voicemail vibration setting.
6747 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6748 */
6749 @Override
6750 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006751 final long identity = Binder.clearCallingIdentity();
6752 try {
6753 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6754 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006755 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006756 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006757
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006758 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6759 } finally {
6760 Binder.restoreCallingIdentity(identity);
6761 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006762 }
6763
Youhan Wange64578a2016-05-02 15:32:42 -07006764 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006765 * Sets the per-account voicemail vibration.
6766 *
6767 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6768 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6769 *
6770 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6771 * voicemail vibration setting.
6772 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6773 * specific PhoneAccount.
6774 */
6775 @Override
6776 public void setVoicemailVibrationEnabled(String callingPackage,
6777 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006778 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006779 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006780 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6781 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6783 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6784 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006785 }
6786
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006787 final long identity = Binder.clearCallingIdentity();
6788 try {
6789 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6790 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006791 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006792 }
6793 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6794 } finally {
6795 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006796 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006797 }
6798
6799 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006800 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6801 *
6802 * @throws SecurityException if the caller does not have the required permission
6803 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006804 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006805 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006806 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006807 }
6808
6809 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006810 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6811 * permission.
6812 *
6813 * @throws SecurityException if the caller does not have the required permission
6814 */
6815 private void enforceSendSmsPermission() {
6816 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6817 }
6818
6819 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006820 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006821 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006822 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006823 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006824 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006825 final long identity = Binder.clearCallingIdentity();
6826 try {
6827 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006828 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006829 if (componentName == null) {
6830 throw new SecurityException(
6831 "Caller not current active visual voicemail package[null]");
6832 }
6833 String vvmPackage = componentName.getPackageName();
6834 if (!callingPackage.equals(vvmPackage)) {
6835 throw new SecurityException("Caller not current active visual voicemail package["
6836 + vvmPackage + "]");
6837 }
6838 } finally {
6839 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006840 }
6841 }
6842
6843 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006844 * Return the application ID for the app type.
6845 *
6846 * @param subId the subscription ID that this request applies to.
6847 * @param appType the uicc app type.
6848 * @return Application ID for specificied app type, or null if no uicc.
6849 */
6850 @Override
6851 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006852 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006853 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006854
6855 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006856 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006857 if (phone == null) {
6858 return null;
6859 }
6860 String aid = null;
6861 try {
6862 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6863 .getApplicationByType(appType).getAid();
6864 } catch (Exception e) {
6865 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6866 }
6867 return aid;
6868 } finally {
6869 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006870 }
Youhan Wange64578a2016-05-02 15:32:42 -07006871 }
6872
Youhan Wang4001d252016-05-11 10:29:41 -07006873 /**
6874 * Return the Electronic Serial Number.
6875 *
6876 * @param subId the subscription ID that this request applies to.
6877 * @return ESN or null if error.
6878 */
6879 @Override
6880 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006881 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006882 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006883
6884 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006885 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006886 if (phone == null) {
6887 return null;
6888 }
6889 String esn = null;
6890 try {
6891 esn = phone.getEsn();
6892 } catch (Exception e) {
6893 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6894 }
6895 return esn;
6896 } finally {
6897 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006898 }
Youhan Wang4001d252016-05-11 10:29:41 -07006899 }
6900
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006901 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006902 * Return the Preferred Roaming List Version.
6903 *
6904 * @param subId the subscription ID that this request applies to.
6905 * @return PRLVersion or null if error.
6906 */
6907 @Override
6908 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006909 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006910 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006911
6912 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006913 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006914 if (phone == null) {
6915 return null;
6916 }
6917 String cdmaPrlVersion = null;
6918 try {
6919 cdmaPrlVersion = phone.getCdmaPrlVersion();
6920 } catch (Exception e) {
6921 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6922 }
6923 return cdmaPrlVersion;
6924 } finally {
6925 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006926 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006927 }
6928
6929 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006930 * Get snapshot of Telephony histograms
6931 * @return List of Telephony histograms
6932 * @hide
6933 */
6934 @Override
6935 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006936 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6937 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006938
6939 final long identity = Binder.clearCallingIdentity();
6940 try {
6941 return RIL.getTelephonyRILTimingHistograms();
6942 } finally {
6943 Binder.restoreCallingIdentity(identity);
6944 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006945 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006946
6947 /**
6948 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006949 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6950 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006951 * Require system privileges. In the future we may add this to carrier APIs.
6952 *
Michele Berionne482f8202018-11-27 18:57:59 -08006953 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006954 */
6955 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006956 @TelephonyManager.SetCarrierRestrictionResult
6957 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006958 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006959 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006960
Michele Berionne482f8202018-11-27 18:57:59 -08006961 if (carrierRestrictionRules == null) {
6962 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006963 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006964
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006965 final long identity = Binder.clearCallingIdentity();
6966 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006967 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006968 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006969 } finally {
6970 Binder.restoreCallingIdentity(identity);
6971 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006972 }
6973
6974 /**
6975 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006976 * Get the allowed carrier list and the excluded carrier list, including the priority between
6977 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006978 * Require system privileges. In the future we may add this to carrier APIs.
6979 *
Michele Berionne482f8202018-11-27 18:57:59 -08006980 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006981 */
6982 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006983 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006984 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006985 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006986
6987 final long identity = Binder.clearCallingIdentity();
6988 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006989 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6990 if (response instanceof CarrierRestrictionRules) {
6991 return (CarrierRestrictionRules) response;
6992 }
6993 // Response is an Exception of some kind,
6994 // which is signalled to the user as a NULL retval
6995 return null;
6996 } catch (Exception e) {
6997 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6998 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006999 } finally {
7000 Binder.restoreCallingIdentity(identity);
7001 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007002 }
7003
fionaxu59545b42016-05-25 15:53:37 -07007004 /**
7005 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7006 * @param subId the subscription ID that this action applies to.
7007 * @param enabled control enable or disable metered apns.
7008 * {@hide}
7009 */
7010 @Override
7011 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7012 enforceModifyPermission();
7013 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007014
7015 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007016 if (phone == null) {
7017 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7018 return;
7019 }
7020 try {
7021 phone.carrierActionSetMeteredApnsEnabled(enabled);
7022 } catch (Exception e) {
7023 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007024 } finally {
7025 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007026 }
7027 }
7028
7029 /**
7030 * Action set from carrier signalling broadcast receivers to enable/disable radio
7031 * @param subId the subscription ID that this action applies to.
7032 * @param enabled control enable or disable radio.
7033 * {@hide}
7034 */
7035 @Override
7036 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7037 enforceModifyPermission();
7038 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007039
7040 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007041 if (phone == null) {
7042 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7043 return;
7044 }
7045 try {
7046 phone.carrierActionSetRadioEnabled(enabled);
7047 } catch (Exception e) {
7048 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007049 } finally {
7050 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007051 }
7052 }
7053
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007054 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007055 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7056 * network status based on which carrier apps could apply actions accordingly,
7057 * enable/disable default url handler for example.
7058 *
7059 * @param subId the subscription ID that this action applies to.
7060 * @param report control start/stop reporting the default network status.
7061 * {@hide}
7062 */
7063 @Override
7064 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7065 enforceModifyPermission();
7066 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007067
7068 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007069 if (phone == null) {
7070 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7071 return;
7072 }
7073 try {
7074 phone.carrierActionReportDefaultNetworkStatus(report);
7075 } catch (Exception e) {
7076 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007077 } finally {
7078 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007079 }
7080 }
7081
7082 /**
fionaxud9622282017-07-17 17:51:30 -07007083 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7084 * @param subId the subscription ID that this action applies to.
7085 * {@hide}
7086 */
7087 @Override
7088 public void carrierActionResetAll(int subId) {
7089 enforceModifyPermission();
7090 final Phone phone = getPhone(subId);
7091 if (phone == null) {
7092 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7093 return;
7094 }
7095 try {
7096 phone.carrierActionResetAll();
7097 } catch (Exception e) {
7098 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7099 }
7100 }
7101
7102 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007103 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7104 * bug report is being generated.
7105 */
7106 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007107 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007108 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7109 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007110 writer.println("Permission Denial: can't dump Phone from pid="
7111 + Binder.getCallingPid()
7112 + ", uid=" + Binder.getCallingUid()
7113 + "without permission "
7114 + android.Manifest.permission.DUMP);
7115 return;
7116 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007117 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007118 }
Jack Yueb89b242016-06-22 13:27:47 -07007119
Brad Ebingerdac2f002018-04-03 15:17:52 -07007120 @Override
7121 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
7122 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
7123 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01007124 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
7125 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007126 }
7127
Jack Yueb89b242016-06-22 13:27:47 -07007128 /**
Jack Yu84291ec2017-05-26 16:07:50 -07007129 * Get aggregated video call data usage since boot.
7130 *
7131 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
7132 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07007133 * {@hide}
7134 */
7135 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07007136 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07007137 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
7138 null);
7139
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007140 final long identity = Binder.clearCallingIdentity();
7141 try {
7142 // NetworkStatsService keeps tracking the active network interface and identity. It
7143 // records the delta with the corresponding network identity.
7144 // We just return the total video call data usage snapshot since boot.
7145 Phone phone = getPhone(subId);
7146 if (phone != null) {
7147 return phone.getVtDataUsage(perUidStats);
7148 }
7149 return null;
7150 } finally {
7151 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07007152 }
Jack Yueb89b242016-06-22 13:27:47 -07007153 }
Jack Yu75ab2952016-07-08 14:29:33 -07007154
7155 /**
7156 * Policy control of data connection. Usually used when data limit is passed.
7157 * @param enabled True if enabling the data, otherwise disabling.
7158 * @param subId Subscription index
7159 * {@hide}
7160 */
7161 @Override
7162 public void setPolicyDataEnabled(boolean enabled, int subId) {
7163 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007164
7165 final long identity = Binder.clearCallingIdentity();
7166 try {
7167 Phone phone = getPhone(subId);
7168 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007169 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007170 }
7171 } finally {
7172 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007173 }
7174 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007175
7176 /**
7177 * Get Client request stats
7178 * @return List of Client Request Stats
7179 * @hide
7180 */
7181 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007182 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7183 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007184 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007185 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007186 return null;
7187 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007188 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007189
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007190 final long identity = Binder.clearCallingIdentity();
7191 try {
7192 if (phone != null) {
7193 return phone.getClientRequestStats();
7194 }
7195
7196 return null;
7197 } finally {
7198 Binder.restoreCallingIdentity(identity);
7199 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007200 }
7201
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007202 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007203 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007204 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007205 }
Jack Yueb4124c2017-02-16 15:32:43 -08007206
7207 /**
Grace Chen70990072017-03-24 17:21:30 -07007208 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007209 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007210 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007211 * @param state State of SIM (power down, power up, pass through)
7212 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7213 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7214 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007215 *
7216 **/
7217 @Override
Grace Chen70990072017-03-24 17:21:30 -07007218 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007219 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007220 Phone phone = PhoneFactory.getPhone(slotIndex);
7221
vagdeviaf9a5b92018-08-15 16:01:53 -07007222 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7223
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007224 final long identity = Binder.clearCallingIdentity();
7225 try {
7226 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007227 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007228 }
7229 } finally {
7230 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007231 }
7232 }
Shuo Qiandd210312017-04-12 22:11:33 +00007233
Tyler Gunn65d45c22017-06-05 11:22:26 -07007234 private boolean isUssdApiAllowed(int subId) {
7235 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007236 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007237 if (configManager == null) {
7238 return false;
7239 }
7240 PersistableBundle pb = configManager.getConfigForSubId(subId);
7241 if (pb == null) {
7242 return false;
7243 }
7244 return pb.getBoolean(
7245 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7246 }
7247
Shuo Qiandd210312017-04-12 22:11:33 +00007248 /**
7249 * Check if phone is in emergency callback mode
7250 * @return true if phone is in emergency callback mode
7251 * @param subId sub id
7252 */
goneil9c5f4872017-12-05 14:07:56 -08007253 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007254 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007255 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007256 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007257
7258 final long identity = Binder.clearCallingIdentity();
7259 try {
7260 if (phone != null) {
7261 return phone.isInEcm();
7262 } else {
7263 return false;
7264 }
7265 } finally {
7266 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007267 }
7268 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007269
7270 /**
7271 * Get the current signal strength information for the given subscription.
7272 * Because this information is not updated when the device is in a low power state
7273 * it should not be relied-upon to be current.
7274 * @param subId Subscription index
7275 * @return the most recent cached signal strength info from the modem
7276 */
7277 @Override
7278 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007279 final long identity = Binder.clearCallingIdentity();
7280 try {
7281 Phone p = getPhone(subId);
7282 if (p == null) {
7283 return null;
7284 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007285
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007286 return p.getSignalStrength();
7287 } finally {
7288 Binder.restoreCallingIdentity(identity);
7289 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007290 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007291
Pengquan Meng77b7f132018-08-22 14:49:57 -07007292 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007293 * Get the current modem radio state for the given slot.
7294 * @param slotIndex slot index.
7295 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007296 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007297 * @return the current radio power state from the modem
7298 */
7299 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007300 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007301 Phone phone = PhoneFactory.getPhone(slotIndex);
7302 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007303 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7304 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007305 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7306 }
7307
7308 final long identity = Binder.clearCallingIdentity();
7309 try {
7310 return phone.getRadioPowerState();
7311 } finally {
7312 Binder.restoreCallingIdentity(identity);
7313 }
7314 }
7315 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7316 }
7317
7318 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007319 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7320 *
7321 * <p>Requires one of the following permissions:
7322 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7323 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7324 * privileges.
7325 *
7326 * @param subId subscription id
7327 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7328 * {@code false}.
7329 */
7330 @Override
7331 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007332 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7333 null /* message */);
7334
Pengquan Menga1bb6272018-09-06 09:59:22 -07007335 boolean isEnabled = false;
7336 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007337 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007338 Phone phone = getPhone(subId);
7339 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007340 } catch (Exception e) {
7341 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7342 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007343 } finally {
7344 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007345 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007346 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007347 }
7348
7349
7350 /**
7351 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7352 *
7353 * <p> Requires permission:
7354 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7355 * privileges.
7356 *
7357 * @param subId subscription id
7358 * @param isEnabled {@code true} means enable, {@code false} means disable.
7359 */
7360 @Override
7361 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007362 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7363 mApp, subId, "setDataRoamingEnabled");
7364
Pengquan Menga1bb6272018-09-06 09:59:22 -07007365 final long identity = Binder.clearCallingIdentity();
7366 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007367 Phone phone = getPhone(subId);
7368 if (phone != null) {
7369 phone.setDataRoamingEnabled(isEnabled);
7370 }
7371 } finally {
7372 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007373 }
7374 }
7375
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007376 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007377 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007378 TelephonyPermissions
7379 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007380 mApp, subId, "isManualNetworkSelectionAllowed");
7381
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007382 boolean isAllowed = true;
7383 final long identity = Binder.clearCallingIdentity();
7384 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007385 Phone phone = getPhone(subId);
7386 if (phone != null) {
7387 isAllowed = phone.isCspPlmnEnabled();
7388 }
7389 } finally {
7390 Binder.restoreCallingIdentity(identity);
7391 }
7392 return isAllowed;
7393 }
7394
7395 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007396 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007397 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007398 try {
7399 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007400 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007401 } catch (SecurityException e) {
7402 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7403 // has carrier privileges on an active UICC
7404 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7405 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007406 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007407 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007408 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007409
7410 final long identity = Binder.clearCallingIdentity();
7411 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007412 UiccController uiccController = UiccController.getInstance();
7413 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007414 if (hasReadPermission) {
7415 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007416 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007417
7418 // Remove private info if the caller doesn't have access
7419 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7420 for (UiccCardInfo cardInfo : cardInfos) {
7421 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7422 // is available
7423 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7424 if (card == null || card.getUiccProfile() == null) {
7425 // assume no access if the card or profile is unavailable
7426 filteredInfos.add(cardInfo.getUnprivileged());
7427 continue;
7428 }
7429 UiccProfile profile = card.getUiccProfile();
7430 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7431 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7432 filteredInfos.add(cardInfo);
7433 } else {
7434 filteredInfos.add(cardInfo.getUnprivileged());
7435 }
7436 }
7437 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007438 } finally {
7439 Binder.restoreCallingIdentity(identity);
7440 }
7441 }
7442
7443 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007444 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007445 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007446
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007447 final long identity = Binder.clearCallingIdentity();
7448 try {
7449 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7450 if (slots == null) {
7451 Rlog.i(LOG_TAG, "slots is null.");
7452 return null;
7453 }
7454
7455 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7456 for (int i = 0; i < slots.length; i++) {
7457 UiccSlot slot = slots[i];
7458 if (slot == null) {
7459 continue;
7460 }
7461
Jordan Liu7be7e652019-05-06 18:55:02 +00007462 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007463 UiccCard card = slot.getUiccCard();
7464 if (card != null) {
7465 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007466 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007467 cardId = slot.getEid();
7468 if (TextUtils.isEmpty(cardId)) {
7469 cardId = slot.getIccId();
7470 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007471 }
7472
Jordan Liu857451f2019-05-09 16:35:35 -07007473 if (cardId != null) {
7474 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7475 // if cardId is an EID, it's all digits so this is fine
7476 cardId = IccUtils.stripTrailingFs(cardId);
7477 }
7478
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007479 int cardState = 0;
7480 switch (slot.getCardState()) {
7481 case CARDSTATE_ABSENT:
7482 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7483 break;
7484 case CARDSTATE_PRESENT:
7485 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7486 break;
7487 case CARDSTATE_ERROR:
7488 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7489 break;
7490 case CARDSTATE_RESTRICTED:
7491 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7492 break;
7493 default:
7494 break;
7495
7496 }
7497
7498 infos[i] = new UiccSlotInfo(
7499 slot.isActive(),
7500 slot.isEuicc(),
7501 cardId,
7502 cardState,
7503 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007504 slot.isExtendedApduSupported(),
7505 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007506 }
7507 return infos;
7508 } finally {
7509 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007510 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007511 }
7512
7513 @Override
7514 public boolean switchSlots(int[] physicalSlots) {
7515 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007516
7517 final long identity = Binder.clearCallingIdentity();
7518 try {
7519 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7520 } finally {
7521 Binder.restoreCallingIdentity(identity);
7522 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007523 }
Jack Yu4c988042018-02-27 15:30:01 -08007524
7525 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007526 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007527 final long identity = Binder.clearCallingIdentity();
7528 try {
7529 return UiccController.getInstance().getCardIdForDefaultEuicc();
7530 } finally {
7531 Binder.restoreCallingIdentity(identity);
7532 }
7533 }
7534
7535 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007536 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7537 enforceModifyPermission();
7538 final Phone phone = getPhone(subId);
7539 if (phone == null) {
7540 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7541 return;
7542 }
7543
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007544 final long identity = Binder.clearCallingIdentity();
7545 try {
7546 phone.setRadioIndicationUpdateMode(filters, mode);
7547 } finally {
7548 Binder.restoreCallingIdentity(identity);
7549 }
Jack Yu4c988042018-02-27 15:30:01 -08007550 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007551
7552 /**
goneil47ffb6e2018-04-06 15:40:58 -07007553 * A test API to reload the UICC profile.
7554 *
7555 * <p>Requires that the calling app has permission
7556 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7557 * @hide
7558 */
7559 @Override
7560 public void refreshUiccProfile(int subId) {
7561 enforceModifyPermission();
7562
7563 final long identity = Binder.clearCallingIdentity();
7564 try {
7565 Phone phone = getPhone(subId);
7566 if (phone == null) {
7567 return;
7568 }
7569 UiccCard uiccCard = phone.getUiccCard();
7570 if (uiccCard == null) {
7571 return;
7572 }
7573 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7574 if (uiccProfile == null) {
7575 return;
7576 }
7577 uiccProfile.refresh();
7578 } finally {
7579 Binder.restoreCallingIdentity(identity);
7580 }
7581 }
7582
7583 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007584 * Returns false if the mobile data is disabled by default, otherwise return true.
7585 */
7586 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007587 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007588 }
7589
7590 /**
7591 * Returns true if the data roaming is enabled by default, i.e the system property
7592 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7593 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7594 */
7595 private boolean getDefaultDataRoamingEnabled(int subId) {
7596 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007597 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007598 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007599 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7600 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7601 return isDataRoamingEnabled;
7602 }
7603
7604 /**
7605 * Returns the default network type for the given {@code subId}, if the default network type is
7606 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7607 */
7608 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007609 List<Integer> list = TelephonyProperties.default_network();
7610 int phoneId = mSubscriptionController.getPhoneId(subId);
7611 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7612 return list.get(phoneId);
7613 }
7614 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007615 }
fionaxua13278b2018-03-21 00:08:13 -07007616
7617 @Override
7618 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007619 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007620 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007621
7622 final long identity = Binder.clearCallingIdentity();
7623 try {
7624 final Phone phone = getPhone(subId);
7625 if (phone == null) {
7626 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7627 return;
7628 }
chen xueaba88a2019-03-15 13:15:10 -07007629 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7630 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007631 } finally {
7632 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007633 }
fionaxua13278b2018-03-21 00:08:13 -07007634 }
7635
7636 @Override
7637 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007638 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007639
7640 final long identity = Binder.clearCallingIdentity();
7641 try {
7642 final Phone phone = getPhone(subId);
7643 if (phone == null) {
7644 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7645 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7646 }
7647 return phone.getCarrierIdListVersion();
7648 } finally {
7649 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007650 }
fionaxua13278b2018-03-21 00:08:13 -07007651 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007652
7653 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007654 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7655 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007656 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007657 mApp, subId, callingPackage, callingFeatureId,
7658 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007659 return -1;
7660 }
7661
7662 final long identity = Binder.clearCallingIdentity();
7663 try {
7664 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7665 } finally {
7666 Binder.restoreCallingIdentity(identity);
7667 }
7668 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007669
7670 @Override
7671 public int getCdmaRoamingMode(int subId) {
7672 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7673 mApp, subId, "getCdmaRoamingMode");
7674
7675 final long identity = Binder.clearCallingIdentity();
7676 try {
7677 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7678 } finally {
7679 Binder.restoreCallingIdentity(identity);
7680 }
7681 }
7682
7683 @Override
7684 public boolean setCdmaRoamingMode(int subId, int mode) {
7685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7686 mApp, subId, "setCdmaRoamingMode");
7687
7688 final long identity = Binder.clearCallingIdentity();
7689 try {
7690 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7691 } finally {
7692 Binder.restoreCallingIdentity(identity);
7693 }
7694 }
7695
7696 @Override
7697 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7699 mApp, subId, "setCdmaSubscriptionMode");
7700
7701 final long identity = Binder.clearCallingIdentity();
7702 try {
7703 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7704 } finally {
7705 Binder.restoreCallingIdentity(identity);
7706 }
7707 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007708
sqianc5eccab2018-10-19 18:46:41 -07007709 @Override
sqian8c685422019-02-22 15:55:18 -08007710 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007711 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007712 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007713 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7714 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007715 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7716 }
7717 final long identity = Binder.clearCallingIdentity();
7718 try {
sqian854d44b2018-12-12 16:48:18 -08007719 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7720 for (Phone phone: PhoneFactory.getPhones()) {
7721 if (phone.getEmergencyNumberTracker() != null
7722 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7723 emergencyNumberListInternal.put(
7724 phone.getSubId(),
7725 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7726 }
sqian11b7a0e2018-12-05 18:48:28 -08007727 }
sqian854d44b2018-12-12 16:48:18 -08007728 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007729 } finally {
7730 Binder.restoreCallingIdentity(identity);
7731 }
sqianc5eccab2018-10-19 18:46:41 -07007732 }
7733
7734 @Override
sqian8c685422019-02-22 15:55:18 -08007735 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007736 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007737 if (!exactMatch) {
7738 TelephonyPermissions
7739 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007740 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007741 }
7742 final long identity = Binder.clearCallingIdentity();
7743 try {
sqian854d44b2018-12-12 16:48:18 -08007744 for (Phone phone: PhoneFactory.getPhones()) {
7745 if (phone.getEmergencyNumberTracker() != null
7746 && phone.getEmergencyNumberTracker() != null) {
7747 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7748 number, exactMatch)) {
7749 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007750 }
7751 }
sqian11b7a0e2018-12-05 18:48:28 -08007752 }
7753 return false;
7754 } finally {
7755 Binder.restoreCallingIdentity(identity);
7756 }
7757 }
7758
sqianf4ca7ed2019-01-15 18:32:07 -08007759 /**
7760 * Update emergency number list for test mode.
7761 */
7762 @Override
7763 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7764 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7765 "updateEmergencyNumberListTestMode");
7766
7767 final long identity = Binder.clearCallingIdentity();
7768 try {
7769 for (Phone phone: PhoneFactory.getPhones()) {
7770 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7771 if (tracker != null) {
7772 tracker.executeEmergencyNumberTestModeCommand(action, num);
7773 }
7774 }
7775 } finally {
7776 Binder.restoreCallingIdentity(identity);
7777 }
7778 }
7779
7780 /**
7781 * Get the full emergency number list for test mode.
7782 */
7783 @Override
7784 public List<String> getEmergencyNumberListTestMode() {
7785 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7786 "getEmergencyNumberListTestMode");
7787
7788 final long identity = Binder.clearCallingIdentity();
7789 try {
7790 Set<String> emergencyNumbers = new HashSet<>();
7791 for (Phone phone: PhoneFactory.getPhones()) {
7792 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7793 if (tracker != null) {
7794 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7795 emergencyNumbers.add(num.getNumber());
7796 }
7797 }
7798 }
7799 return new ArrayList<>(emergencyNumbers);
7800 } finally {
7801 Binder.restoreCallingIdentity(identity);
7802 }
7803 }
7804
chen xud6b45bd2018-10-30 22:27:10 -07007805 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007806 public int getEmergencyNumberDbVersion(int subId) {
7807 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7808
7809 final long identity = Binder.clearCallingIdentity();
7810 try {
7811 final Phone phone = getPhone(subId);
7812 if (phone == null) {
7813 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7814 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7815 }
7816 return phone.getEmergencyNumberDbVersion();
7817 } finally {
7818 Binder.restoreCallingIdentity(identity);
7819 }
7820 }
7821
7822 @Override
7823 public void notifyOtaEmergencyNumberDbInstalled() {
7824 enforceModifyPermission();
7825
7826 final long identity = Binder.clearCallingIdentity();
7827 try {
7828 for (Phone phone: PhoneFactory.getPhones()) {
7829 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7830 if (tracker != null) {
7831 tracker.updateOtaEmergencyNumberDatabase();
7832 }
7833 }
7834 } finally {
7835 Binder.restoreCallingIdentity(identity);
7836 }
7837 }
7838
7839 @Override
7840 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7841 enforceActiveEmergencySessionPermission();
7842
7843 final long identity = Binder.clearCallingIdentity();
7844 try {
7845 for (Phone phone: PhoneFactory.getPhones()) {
7846 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7847 if (tracker != null) {
7848 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7849 }
7850 }
7851 } finally {
7852 Binder.restoreCallingIdentity(identity);
7853 }
7854 }
7855
7856 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007857 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7858 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7859 Phone phone = getPhone(subId);
7860 if (phone == null) {
7861 return null;
7862 }
7863 final long identity = Binder.clearCallingIdentity();
7864 try {
7865 UiccProfile profile = UiccController.getInstance()
7866 .getUiccProfileForPhone(phone.getPhoneId());
7867 if (profile != null) {
7868 return profile.getCertsFromCarrierPrivilegeAccessRules();
7869 }
7870 } finally {
7871 Binder.restoreCallingIdentity(identity);
7872 }
7873 return null;
7874 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007875
7876 /**
7877 * Enable or disable a modem stack.
7878 */
7879 @Override
7880 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7881 enforceModifyPermission();
7882
7883 final long identity = Binder.clearCallingIdentity();
7884 try {
7885 Phone phone = PhoneFactory.getPhone(slotIndex);
7886 if (phone == null) {
7887 return false;
7888 } else {
7889 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7890 }
7891 } finally {
7892 Binder.restoreCallingIdentity(identity);
7893 }
7894 }
Michelecea4cf22018-12-21 15:00:11 -08007895
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007896 /**
7897 * Whether a modem stack is enabled or not.
7898 */
7899 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007900 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7901 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007902 Phone phone = PhoneFactory.getPhone(slotIndex);
7903 if (phone == null) return false;
7904
7905 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007906 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7907 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007908 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7909 }
7910
7911 final long identity = Binder.clearCallingIdentity();
7912 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007913 try {
7914 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7915 } catch (NoSuchElementException ex) {
7916 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7917 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007918 } finally {
7919 Binder.restoreCallingIdentity(identity);
7920 }
7921 }
7922
Michelecea4cf22018-12-21 15:00:11 -08007923 @Override
Michele0ea7d782019-03-19 14:58:42 -07007924 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007925 enforceModifyPermission();
7926
7927 final long identity = Binder.clearCallingIdentity();
7928 try {
7929 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007930 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007931 .commit();
7932 } finally {
7933 Binder.restoreCallingIdentity(identity);
7934 }
7935 }
7936
7937 @Override
Michele0ea7d782019-03-19 14:58:42 -07007938 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007939 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007940 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007941 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7942 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007943 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007944 }
Michelecea4cf22018-12-21 15:00:11 -08007945
7946 final long identity = Binder.clearCallingIdentity();
7947 try {
Michele0ea7d782019-03-19 14:58:42 -07007948 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007949 } finally {
7950 Binder.restoreCallingIdentity(identity);
7951 }
7952 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007953
Michele0ea7d782019-03-19 14:58:42 -07007954 @TelephonyManager.IsMultiSimSupportedResult
7955 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007956 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7957 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7958 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007959 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7960 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007961 }
7962 // Check if the hardware supports multisim functionality. If usage of multisim is not
7963 // supported by the modem, indicate that it is restricted.
7964 PhoneCapability staticCapability =
7965 mPhoneConfigurationManager.getStaticPhoneCapability();
7966 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007967 loge("isMultiSimSupportedInternal: no static configuration available");
7968 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007969 }
Sarah Chin5f0ecd72019-12-06 10:24:18 -08007970 if (staticCapability.getLogicalModemUuids().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007971 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7972 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007973 }
7974 // Check if support of multiple SIMs is restricted by carrier
7975 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007976 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007977 }
7978
Michele0ea7d782019-03-19 14:58:42 -07007979 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007980 }
7981
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007982 /**
7983 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007984 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7985 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7986 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007987 * @param numOfSims number of active sims we want to switch to
7988 */
7989 @Override
7990 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007991 if (numOfSims == 1) {
7992 enforceModifyPermission();
7993 } else {
7994 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7995 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7996 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007997 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007998
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007999 try {
Michele30b57b22019-03-01 12:01:14 -08008000 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008001 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008002 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8003 return;
8004 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008005 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8006 } finally {
8007 Binder.restoreCallingIdentity(identity);
8008 }
8009 }
8010
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008011 @Override
8012 public boolean isApplicationOnUicc(int subId, int appType) {
8013 enforceReadPrivilegedPermission("isApplicationOnUicc");
8014 Phone phone = getPhone(subId);
8015 if (phone == null) {
8016 return false;
8017 }
8018 final long identity = Binder.clearCallingIdentity();
8019 try {
8020 UiccCard uiccCard = phone.getUiccCard();
8021 if (uiccCard == null) {
8022 return false;
8023 }
8024 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8025 if (uiccProfile == null) {
8026 return false;
8027 }
8028 if (TelephonyManager.APPTYPE_SIM <= appType
8029 && appType <= TelephonyManager.APPTYPE_ISIM) {
8030 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8031 }
8032 return false;
8033 } finally {
8034 Binder.restoreCallingIdentity(identity);
8035 }
8036 }
8037
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008038 /**
chen xub4baa772019-04-03 10:23:41 -07008039 * Get whether making changes to modem configurations will trigger reboot.
8040 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008041 */
8042 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008043 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8044 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008045 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008046 mApp, subId, callingPackage, callingFeatureId,
8047 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008048 return false;
8049 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008050 final long identity = Binder.clearCallingIdentity();
8051 try {
8052 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8053 } finally {
8054 Binder.restoreCallingIdentity(identity);
8055 }
8056 }
8057
Nathan Harold29f5f052019-02-15 13:41:57 -08008058 private void updateModemStateMetrics() {
8059 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8060 // TODO: check the state for each modem if the api is ready.
8061 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8062 }
8063
Pengquan Meng3889a572019-01-23 11:16:29 -08008064 @Override
8065 public int[] getSlotsMapping() {
8066 enforceReadPrivilegedPermission("getSlotsMapping");
8067
8068 final long identity = Binder.clearCallingIdentity();
8069 try {
8070 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8071 // All logical slots should have a mapping to a physical slot.
8072 int[] logicalSlotsMapping = new int[phoneCount];
8073 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8074 for (int i = 0; i < slotInfos.length; i++) {
8075 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8076 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8077 }
8078 }
8079 return logicalSlotsMapping;
8080 } finally {
8081 Binder.restoreCallingIdentity(identity);
8082 }
8083 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008084
8085 /**
8086 * Get the IRadio HAL Version
8087 */
8088 @Override
8089 public int getRadioHalVersion() {
8090 Phone phone = getDefaultPhone();
8091 if (phone == null) return -1;
8092 HalVersion hv = phone.getHalVersion();
8093 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8094 return hv.major * 100 + hv.minor;
8095 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008096
8097 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008098 * Get the current calling package name.
8099 * @return the current calling package name
8100 */
8101 @Override
8102 public String getCurrentPackageName() {
8103 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8104 }
8105
8106 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008107 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8108 * corresponding network requests on a subId.
8109 *
8110 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008111 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008112 * 2) APN is un-metered for this subscription, or
8113 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
8114 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
8115 *
8116 * @return whether data is allowed for a apn type.
8117 *
8118 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008119 */
8120 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008121 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008122 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8123 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008124
8125 // Now that all security checks passes, perform the operation as ourselves.
8126 final long identity = Binder.clearCallingIdentity();
8127 try {
8128 Phone phone = getPhone(subId);
8129 if (phone == null) return false;
8130
Jack Yu41407ee2019-05-13 16:54:09 -07008131 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008132 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8133 } finally {
8134 Binder.restoreCallingIdentity(identity);
8135 }
8136 }
8137
8138 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008139 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008140 enforceReadPrivilegedPermission("isApnMetered");
8141
8142 // Now that all security checks passes, perform the operation as ourselves.
8143 final long identity = Binder.clearCallingIdentity();
8144 try {
8145 Phone phone = getPhone(subId);
8146 if (phone == null) return true; // By default return true.
8147
Jack Yu41407ee2019-05-13 16:54:09 -07008148 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008149 } finally {
8150 Binder.restoreCallingIdentity(identity);
8151 }
8152 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008153
8154 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008155 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8156 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8157 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8158 if (iccRecords == null) {
8159 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8160 return false;
8161 }
8162 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8163 }
8164
8165 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07008166 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008167 if (callingPackage == null) {
8168 callingPackage = getCurrentPackageName();
8169 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008170 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8171 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
8172 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
8173 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8174 }
8175 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8176 Intent intent = new Intent();
8177 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8178 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8179 // Bring up choose default SMS subscription dialog right now
8180 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8181 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8182 mApp.startActivity(intent);
8183 }
chen xud5ca2d52019-05-28 15:20:57 -07008184
8185 @Override
8186 public String getMmsUAProfUrl(int subId) {
8187 //TODO investigate if this API should require proper permission check in R b/133791609
8188 final long identity = Binder.clearCallingIdentity();
8189 try {
8190 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8191 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8192 } finally {
8193 Binder.restoreCallingIdentity(identity);
8194 }
8195 }
8196
8197 @Override
8198 public String getMmsUserAgent(int subId) {
8199 //TODO investigate if this API should require proper permission check in R b/133791609
8200 final long identity = Binder.clearCallingIdentity();
8201 try {
8202 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8203 .getString(com.android.internal.R.string.config_mms_user_agent);
8204 } finally {
8205 Binder.restoreCallingIdentity(identity);
8206 }
8207 }
Jack Yub07d4972019-05-28 16:12:25 -07008208
8209 @Override
8210 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8211 enforceModifyPermission();
8212
8213 // Now that all security checks passes, perform the operation as ourselves.
8214 final long identity = Binder.clearCallingIdentity();
8215 try {
8216 Phone phone = getPhone(subId);
8217 if (phone == null) return false;
8218
8219 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8220 } finally {
8221 Binder.restoreCallingIdentity(identity);
8222 }
8223 }
8224
8225 @Override
8226 public boolean isDataAllowedInVoiceCall(int subId) {
8227 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8228
8229 // Now that all security checks passes, perform the operation as ourselves.
8230 final long identity = Binder.clearCallingIdentity();
8231 try {
8232 Phone phone = getPhone(subId);
8233 if (phone == null) return false;
8234
8235 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8236 } finally {
8237 Binder.restoreCallingIdentity(identity);
8238 }
8239 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008240
8241 /**
8242 * Updates whether conference event pacakge handling is enabled.
8243 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8244 * otherwise.
8245 */
8246 @Override
8247 public void setCepEnabled(boolean isCepEnabled) {
8248 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8249
8250 final long identity = Binder.clearCallingIdentity();
8251 try {
8252 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8253 for (Phone phone : PhoneFactory.getPhones()) {
8254 Phone defaultPhone = phone.getImsPhone();
8255 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8256 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8257 ImsPhoneCallTracker imsPhoneCallTracker =
8258 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8259 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8260 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8261 + imsPhone.getMsisdn());
8262 }
8263 }
8264 } finally {
8265 Binder.restoreCallingIdentity(identity);
8266 }
8267 }
allenwtsu46dcc572020-01-08 18:24:03 +08008268
8269 /**
8270 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8271 *
8272 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8273 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8274 * before being read.
8275 */
8276 @Override
8277 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8278 isCompressed) {
8279 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8280 mApp, subId, "notifyRcsAutoConfigurationReceived");
8281 try {
8282 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8283 if (configBinder == null) {
8284 Rlog.e(LOG_TAG, "null result for getImsConfig");
8285 } else {
8286 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8287 }
8288 } catch (RemoteException e) {
8289 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8290 }
8291 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008292}