blob: 5c78cc34f2a03d38d532d72f7f98f43df9502218 [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;
Brad Ebinger5f64b052017-12-14 14:26:15 -080051import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070052import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070055import android.os.ShellCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070060import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080061import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070062import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090063import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080064import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080065import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070066import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070067import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080071import android.telephony.CellIdentityCdma;
72import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070074import android.telephony.CellInfoGsm;
75import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070076import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070077import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070078import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080079import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070080import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070082import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080083import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080084import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.RadioAccessSpecifier;
Meng Wang17815702020-01-08 18:00:39 -080087import com.android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080089import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080090import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080091import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070092import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080095import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000096import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070097import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebinger774ba362019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsMmTelFeature;
108import android.telephony.ims.aidl.IImsRcsFeature;
109import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700110import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800113import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800114import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800115import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800119import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800120import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800121
Andrew Lee312e8172014-10-23 17:01:36 -0700122import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800123import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700124import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700125import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700126import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800127import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700128import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700129import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800131import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700132import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800133import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800135import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700136import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700137import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700138import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700140import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800141import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700142import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700143import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700144import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700145import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700146import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700147import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700148import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700149import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800150import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800151import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700152import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800153import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700154import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800155import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700156import com.android.internal.telephony.imsphone.ImsPhone;
157import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800158import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900159import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700160import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800161import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700162import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800163import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700164import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800165import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700166import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800167import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000168import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800169import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700170import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800171import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700172import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700173import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800174import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700175import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700176import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800177
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700178import java.io.FileDescriptor;
179import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700180import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800181import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800182import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800183import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800184import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100185import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800186import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700187import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700189
190/**
191 * Implementation of the ITelephony interface.
192 */
Santos Cordon117fee72014-05-16 17:56:12 -0700193public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194 private static final String LOG_TAG = "PhoneInterfaceManager";
195 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
196 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800197 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198
199 // Message codes used with mMainThreadHandler
200 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700201 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
202 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700203 private static final int CMD_OPEN_CHANNEL = 9;
204 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
205 private static final int CMD_CLOSE_CHANNEL = 11;
206 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800207 private static final int CMD_NV_READ_ITEM = 13;
208 private static final int EVENT_NV_READ_ITEM_DONE = 14;
209 private static final int CMD_NV_WRITE_ITEM = 15;
210 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
211 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
212 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700213 private static final int CMD_RESET_MODEM_CONFIG = 19;
214 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800215 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
216 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
217 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
218 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800219 private static final int CMD_SEND_ENVELOPE = 25;
220 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000221 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
222 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700223 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
224 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
225 private static final int CMD_EXCHANGE_SIM_IO = 31;
226 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800227 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
228 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700229 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
230 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700231 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
232 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700233 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
234 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
235 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
236 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700237 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
238 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
239 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
240 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700241 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800242 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
243 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000244 private static final int CMD_SWITCH_SLOTS = 50;
245 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700246 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
247 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
248 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
249 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
250 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
251 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
252 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
253 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700254 private static final int CMD_GET_ALL_CELL_INFO = 60;
255 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
256 private static final int CMD_GET_CELL_LOCATION = 62;
257 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700258 private static final int CMD_MODEM_REBOOT = 64;
259 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700260 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
261 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800262 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
263 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700264 private static final int CMD_GET_MODEM_STATUS = 70;
265 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700266 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
267 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700268 private static final int CMD_ERASE_MODEM_CONFIG = 74;
269 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700270
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800271 // Parameters of select command.
272 private static final int SELECT_COMMAND = 0xA4;
273 private static final int SELECT_P1 = 0x04;
274 private static final int SELECT_P2 = 0;
275 private static final int SELECT_P3 = 0x10;
276
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700277 /** The singleton instance. */
278 private static PhoneInterfaceManager sInstance;
279
Wink Saville3ab207e2014-11-20 13:07:20 -0800280 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800281 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800282 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700283 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800284 private AppOpsManager mAppOps;
285 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800286 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800287 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700288 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700289
Derek Tan97ebb422014-09-05 16:55:38 -0700290 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
291 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800292 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800293 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700294
Michelecea4cf22018-12-21 15:00:11 -0800295 // String to store multi SIM allowed
296 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
297
Derek Tan740e1672017-06-27 14:56:27 -0700298 // The AID of ISD-R.
299 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
300
yinxub1bed742017-04-17 11:45:04 -0700301 private NetworkScanRequestTracker mNetworkScanRequestTracker;
302
David Kelly5e06a7f2018-03-12 14:10:59 +0000303 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
304 private static final int MANUFACTURER_CODE_LENGTH = 8;
305
Derek Tan89e89d42014-07-08 17:00:10 -0700306 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700307 * Experiment flag to enable erase modem config on reset network, default value is false
308 */
309 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
310 "reset_network_erase_modem_config_enabled";
311
312 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700313 * A request object to use for transmitting data to an ICC.
314 */
315 private static final class IccAPDUArgument {
316 public int channel, cla, command, p1, p2, p3;
317 public String data;
318
319 public IccAPDUArgument(int channel, int cla, int command,
320 int p1, int p2, int p3, String data) {
321 this.channel = channel;
322 this.cla = cla;
323 this.command = command;
324 this.p1 = p1;
325 this.p2 = p2;
326 this.p3 = p3;
327 this.data = data;
328 }
329 }
330
331 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700332 * A request object to use for transmitting data to an ICC.
333 */
334 private static final class ManualNetworkSelectionArgument {
335 public OperatorInfo operatorInfo;
336 public boolean persistSelection;
337
338 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
339 this.operatorInfo = operatorInfo;
340 this.persistSelection = persistSelection;
341 }
342 }
343
344 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700345 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
346 * request after sending. The main thread will notify the request when it is complete.
347 */
348 private static final class MainThreadRequest {
349 /** The argument to use for the request */
350 public Object argument;
351 /** The result of the request that is run on the main thread */
352 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800353 // The subscriber id that this request applies to. Defaults to
354 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
355 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356
Nathan Harold92bed182018-10-12 18:16:49 -0700357 // In cases where subId is unavailable, the caller needs to specify the phone.
358 public Phone phone;
359
vagdeviaf9a5b92018-08-15 16:01:53 -0700360 public WorkSource workSource;
361
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362 public MainThreadRequest(Object argument) {
363 this.argument = argument;
364 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800365
Nathan Harold92bed182018-10-12 18:16:49 -0700366 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
367 this.argument = argument;
368 if (phone != null) {
369 this.phone = phone;
370 }
371 this.workSource = workSource;
372 }
373
vagdeviaf9a5b92018-08-15 16:01:53 -0700374 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800375 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800376 if (subId != null) {
377 this.subId = subId;
378 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700379 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800380 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 }
382
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800383 private static final class IncomingThirdPartyCallArgs {
384 public final ComponentName component;
385 public final String callId;
386 public final String callerDisplayName;
387
388 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
389 String callerDisplayName) {
390 this.component = component;
391 this.callId = callId;
392 this.callerDisplayName = callerDisplayName;
393 }
394 }
395
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700396 /**
397 * A handler that processes messages on the main thread in the phone process. Since many
398 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
399 * inbound binder threads to the main thread in the phone process. The Binder thread
400 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
401 * on, which will be notified when the operation completes and will contain the result of the
402 * request.
403 *
404 * <p>If a MainThreadRequest object is provided in the msg.obj field,
405 * note that request.result must be set to something non-null for the calling thread to
406 * unblock.
407 */
408 private final class MainThreadHandler extends Handler {
409 @Override
410 public void handleMessage(Message msg) {
411 MainThreadRequest request;
412 Message onCompleted;
413 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800414 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700415 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800416 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417
418 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700419 case CMD_HANDLE_USSD_REQUEST: {
420 request = (MainThreadRequest) msg.obj;
421 final Phone phone = getPhoneFromRequest(request);
422 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
423 String ussdRequest = ussdObject.first;
424 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700425
Pengquan Menga1bb6272018-09-06 09:59:22 -0700426 if (!isUssdApiAllowed(request.subId)) {
427 // Carrier does not support use of this API, return failure.
428 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
429 UssdResponse response = new UssdResponse(ussdRequest, null);
430 Bundle returnData = new Bundle();
431 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
432 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700433
Pengquan Menga1bb6272018-09-06 09:59:22 -0700434 request.result = true;
435 notifyRequester(request);
436 return;
437 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700438
Pengquan Menga1bb6272018-09-06 09:59:22 -0700439 try {
440 request.result = phone != null
441 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
442 } catch (CallStateException cse) {
443 request.result = false;
444 }
445 // Wake up the requesting thread
446 notifyRequester(request);
447 break;
pkanwar32d516d2016-10-14 19:37:38 -0700448 }
449
Yorke Lee716f67e2015-06-17 15:39:16 -0700450 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700451 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700452 final Phone phone = getPhoneFromRequest(request);
453 request.result = phone != null ?
454 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
455 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700456 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700457 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700458 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700459 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700460
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700461 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700462 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700463 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800464 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700465 if (uiccCard == null) {
466 loge("iccTransmitApduLogicalChannel: No UICC");
467 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700468 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700469 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700470 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
471 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700472 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700473 iccArgument.channel, iccArgument.cla, iccArgument.command,
474 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700475 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700476 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700477 break;
478
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700479 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700480 ar = (AsyncResult) msg.obj;
481 request = (MainThreadRequest) ar.userObj;
482 if (ar.exception == null && ar.result != null) {
483 request.result = ar.result;
484 } else {
485 request.result = new IccIoResult(0x6F, 0, (byte[])null);
486 if (ar.result == null) {
487 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800488 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700489 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800490 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700491 } else {
492 loge("iccTransmitApduLogicalChannel: Unknown exception");
493 }
494 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700495 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700496 break;
497
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
499 request = (MainThreadRequest) msg.obj;
500 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800501 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700502 if (uiccCard == null) {
503 loge("iccTransmitApduBasicChannel: No UICC");
504 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700505 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700506 } else {
507 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
508 request);
509 uiccCard.iccTransmitApduBasicChannel(
510 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
511 iccArgument.p3, iccArgument.data, onCompleted);
512 }
513 break;
514
515 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
516 ar = (AsyncResult) msg.obj;
517 request = (MainThreadRequest) ar.userObj;
518 if (ar.exception == null && ar.result != null) {
519 request.result = ar.result;
520 } else {
521 request.result = new IccIoResult(0x6F, 0, (byte[])null);
522 if (ar.result == null) {
523 loge("iccTransmitApduBasicChannel: Empty response");
524 } else if (ar.exception instanceof CommandException) {
525 loge("iccTransmitApduBasicChannel: CommandException: " +
526 ar.exception);
527 } else {
528 loge("iccTransmitApduBasicChannel: Unknown exception");
529 }
530 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700531 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700532 break;
533
534 case CMD_EXCHANGE_SIM_IO:
535 request = (MainThreadRequest) msg.obj;
536 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800537 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700538 if (uiccCard == null) {
539 loge("iccExchangeSimIO: No UICC");
540 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700541 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700542 } else {
543 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
544 request);
545 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
546 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
547 iccArgument.data, onCompleted);
548 }
549 break;
550
551 case EVENT_EXCHANGE_SIM_IO_DONE:
552 ar = (AsyncResult) msg.obj;
553 request = (MainThreadRequest) ar.userObj;
554 if (ar.exception == null && ar.result != null) {
555 request.result = ar.result;
556 } else {
557 request.result = new IccIoResult(0x6f, 0, (byte[])null);
558 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700559 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700560 break;
561
Derek Tan4d5e5c12014-02-04 11:54:58 -0800562 case CMD_SEND_ENVELOPE:
563 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800564 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700565 if (uiccCard == null) {
566 loge("sendEnvelopeWithStatus: No UICC");
567 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700568 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700569 } else {
570 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
571 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
572 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800573 break;
574
575 case EVENT_SEND_ENVELOPE_DONE:
576 ar = (AsyncResult) msg.obj;
577 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700578 if (ar.exception == null && ar.result != null) {
579 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800580 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700581 request.result = new IccIoResult(0x6F, 0, (byte[])null);
582 if (ar.result == null) {
583 loge("sendEnvelopeWithStatus: Empty response");
584 } else if (ar.exception instanceof CommandException) {
585 loge("sendEnvelopeWithStatus: CommandException: " +
586 ar.exception);
587 } else {
588 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
589 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800590 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700591 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800592 break;
593
Shishir Agrawal566b7612013-10-28 14:41:00 -0700594 case CMD_OPEN_CHANNEL:
595 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800596 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800597 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700598 if (uiccCard == null) {
599 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800600 request.result = new IccOpenLogicalChannelResponse(-1,
601 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700602 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700603 } else {
604 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800605 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
606 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700607 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 break;
609
610 case EVENT_OPEN_CHANNEL_DONE:
611 ar = (AsyncResult) msg.obj;
612 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700613 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700615 int[] result = (int[]) ar.result;
616 int channelId = result[0];
617 byte[] selectResponse = null;
618 if (result.length > 1) {
619 selectResponse = new byte[result.length - 1];
620 for (int i = 1; i < result.length; ++i) {
621 selectResponse[i - 1] = (byte) result[i];
622 }
623 }
624 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700625 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 if (ar.result == null) {
628 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700629 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 if (ar.exception != null) {
631 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
632 }
633
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700634 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700635 if (ar.exception instanceof CommandException) {
636 CommandException.Error error =
637 ((CommandException) (ar.exception)).getCommandError();
638 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700639 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700640 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700641 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700642 }
643 }
644 openChannelResp = new IccOpenLogicalChannelResponse(
645 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700647 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700648 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 break;
650
651 case CMD_CLOSE_CHANNEL:
652 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800653 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700654 if (uiccCard == null) {
655 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900656 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700657 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700658 } else {
659 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
660 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
661 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 break;
663
664 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800665 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
666 break;
667
668 case CMD_NV_READ_ITEM:
669 request = (MainThreadRequest) msg.obj;
670 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800671 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
672 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800673 break;
674
675 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 ar = (AsyncResult) msg.obj;
677 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800678 if (ar.exception == null && ar.result != null) {
679 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800681 request.result = "";
682 if (ar.result == null) {
683 loge("nvReadItem: Empty response");
684 } else if (ar.exception instanceof CommandException) {
685 loge("nvReadItem: CommandException: " +
686 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800688 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 }
690 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700691 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 break;
693
Jake Hambye994d462014-02-03 13:10:13 -0800694 case CMD_NV_WRITE_ITEM:
695 request = (MainThreadRequest) msg.obj;
696 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
697 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800698 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700699 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800700 break;
701
702 case EVENT_NV_WRITE_ITEM_DONE:
703 handleNullReturnEvent(msg, "nvWriteItem");
704 break;
705
706 case CMD_NV_WRITE_CDMA_PRL:
707 request = (MainThreadRequest) msg.obj;
708 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800709 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800710 break;
711
712 case EVENT_NV_WRITE_CDMA_PRL_DONE:
713 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
714 break;
715
chen xu6dac5ab2018-10-26 17:39:23 -0700716 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800717 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700718 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800719 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800720 break;
721
chen xu6dac5ab2018-10-26 17:39:23 -0700722 case EVENT_RESET_MODEM_CONFIG_DONE:
723 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800724 break;
725
Jake Hamby7c27be32014-03-03 13:25:59 -0800726 case CMD_GET_PREFERRED_NETWORK_TYPE:
727 request = (MainThreadRequest) msg.obj;
728 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700729 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800730 break;
731
732 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
733 ar = (AsyncResult) msg.obj;
734 request = (MainThreadRequest) ar.userObj;
735 if (ar.exception == null && ar.result != null) {
736 request.result = ar.result; // Integer
737 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800738 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800739 if (ar.result == null) {
740 loge("getPreferredNetworkType: Empty response");
741 } else if (ar.exception instanceof CommandException) {
742 loge("getPreferredNetworkType: CommandException: " +
743 ar.exception);
744 } else {
745 loge("getPreferredNetworkType: Unknown exception");
746 }
747 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700748 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800749 break;
750
751 case CMD_SET_PREFERRED_NETWORK_TYPE:
752 request = (MainThreadRequest) msg.obj;
753 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
754 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700755 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800756 break;
757
758 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
759 handleNullReturnEvent(msg, "setPreferredNetworkType");
760 break;
761
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000762 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
763 request = (MainThreadRequest)msg.obj;
764 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800765 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000766 break;
767
768 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
769 ar = (AsyncResult)msg.obj;
770 request = (MainThreadRequest)ar.userObj;
771 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700772 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000773 break;
774
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800775 case CMD_SET_VOICEMAIL_NUMBER:
776 request = (MainThreadRequest) msg.obj;
777 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
778 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800779 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
780 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800781 break;
782
783 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
784 handleNullReturnEvent(msg, "setVoicemailNumber");
785 break;
786
Stuart Scott54788802015-03-30 13:18:01 -0700787 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
788 request = (MainThreadRequest) msg.obj;
789 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
790 request);
791 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
792 break;
793
794 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
795 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
796 break;
797
Shishir Agrawal302c8692015-06-19 13:49:39 -0700798 case CMD_PERFORM_NETWORK_SCAN:
799 request = (MainThreadRequest) msg.obj;
800 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
801 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
802 break;
803
804 case EVENT_PERFORM_NETWORK_SCAN_DONE:
805 ar = (AsyncResult) msg.obj;
806 request = (MainThreadRequest) ar.userObj;
807 CellNetworkScanResult cellScanResult;
808 if (ar.exception == null && ar.result != null) {
809 cellScanResult = new CellNetworkScanResult(
810 CellNetworkScanResult.STATUS_SUCCESS,
811 (List<OperatorInfo>) ar.result);
812 } else {
813 if (ar.result == null) {
814 loge("getCellNetworkScanResults: Empty response");
815 }
816 if (ar.exception != null) {
817 loge("getCellNetworkScanResults: Exception: " + ar.exception);
818 }
819 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
820 if (ar.exception instanceof CommandException) {
821 CommandException.Error error =
822 ((CommandException) (ar.exception)).getCommandError();
823 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
824 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
825 } else if (error == CommandException.Error.GENERIC_FAILURE) {
826 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
827 }
828 }
829 cellScanResult = new CellNetworkScanResult(errorCode, null);
830 }
831 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700832 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700833 break;
834
835 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
836 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700837 ManualNetworkSelectionArgument selArg =
838 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700839 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
840 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700841 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
842 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700843 break;
844
845 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700846 ar = (AsyncResult) msg.obj;
847 request = (MainThreadRequest) ar.userObj;
848 if (ar.exception == null) {
849 request.result = true;
850 } else {
851 request.result = false;
852 loge("setNetworkSelectionModeManual " + ar.exception);
853 }
854 notifyRequester(request);
855 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700856 break;
857
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700858 case CMD_GET_MODEM_ACTIVITY_INFO:
859 request = (MainThreadRequest) msg.obj;
860 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700861 if (defaultPhone != null) {
862 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
863 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700864 break;
865
866 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
867 ar = (AsyncResult) msg.obj;
868 request = (MainThreadRequest) ar.userObj;
869 if (ar.exception == null && ar.result != null) {
870 request.result = ar.result;
871 } else {
872 if (ar.result == null) {
873 loge("queryModemActivityInfo: Empty response");
874 } else if (ar.exception instanceof CommandException) {
875 loge("queryModemActivityInfo: CommandException: " +
876 ar.exception);
877 } else {
878 loge("queryModemActivityInfo: Unknown exception");
879 }
880 }
Amit Mahajand4766222016-01-28 15:28:28 -0800881 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
882 if (request.result == null) {
Chen Xu13851032019-09-10 18:49:52 -0700883 request.result = new ModemActivityInfo(0, 0, 0, null, 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800884 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700885 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700886 break;
887
Meng Wang1a7c35a2016-05-05 20:56:15 -0700888 case CMD_SET_ALLOWED_CARRIERS:
889 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800890 CarrierRestrictionRules argument =
891 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700892 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800893 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700894 break;
895
896 case EVENT_SET_ALLOWED_CARRIERS_DONE:
897 ar = (AsyncResult) msg.obj;
898 request = (MainThreadRequest) ar.userObj;
899 if (ar.exception == null && ar.result != null) {
900 request.result = ar.result;
901 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800902 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
903 if (ar.exception instanceof CommandException) {
904 loge("setAllowedCarriers: CommandException: " + ar.exception);
905 CommandException.Error error =
906 ((CommandException) (ar.exception)).getCommandError();
907 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
908 request.result =
909 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
910 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700911 } else {
912 loge("setAllowedCarriers: Unknown exception");
913 }
914 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700915 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700916 break;
917
918 case CMD_GET_ALLOWED_CARRIERS:
919 request = (MainThreadRequest) msg.obj;
920 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800921 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700922 break;
923
924 case EVENT_GET_ALLOWED_CARRIERS_DONE:
925 ar = (AsyncResult) msg.obj;
926 request = (MainThreadRequest) ar.userObj;
927 if (ar.exception == null && ar.result != null) {
928 request.result = ar.result;
929 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800930 request.result = new IllegalStateException(
931 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700932 if (ar.result == null) {
933 loge("getAllowedCarriers: Empty response");
934 } else if (ar.exception instanceof CommandException) {
935 loge("getAllowedCarriers: CommandException: " +
936 ar.exception);
937 } else {
938 loge("getAllowedCarriers: Unknown exception");
939 }
940 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700941 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700942 break;
943
Nathan Haroldb3014052017-01-25 15:57:32 -0800944 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
945 ar = (AsyncResult) msg.obj;
946 request = (MainThreadRequest) ar.userObj;
947 if (ar.exception == null && ar.result != null) {
948 request.result = ar.result;
949 } else {
950 request.result = new IllegalArgumentException(
951 "Failed to retrieve Forbidden Plmns");
952 if (ar.result == null) {
953 loge("getForbiddenPlmns: Empty response");
954 } else {
955 loge("getForbiddenPlmns: Unknown exception");
956 }
957 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700958 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800959 break;
960
961 case CMD_GET_FORBIDDEN_PLMNS:
962 request = (MainThreadRequest) msg.obj;
963 uiccCard = getUiccCardFromRequest(request);
964 if (uiccCard == null) {
965 loge("getForbiddenPlmns() UiccCard is null");
966 request.result = new IllegalArgumentException(
967 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700968 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800969 break;
970 }
971 Integer appType = (Integer) request.argument;
972 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
973 if (uiccApp == null) {
974 loge("getForbiddenPlmns() no app with specified type -- "
975 + appType);
976 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700977 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800978 break;
979 } else {
980 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
981 + " specified type -- " + appType);
982 }
983 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
984 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
985 onCompleted);
986 break;
987
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000988 case CMD_SWITCH_SLOTS:
989 request = (MainThreadRequest) msg.obj;
990 int[] physicalSlots = (int[]) request.argument;
991 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
992 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
993 break;
994
995 case EVENT_SWITCH_SLOTS_DONE:
996 ar = (AsyncResult) msg.obj;
997 request = (MainThreadRequest) ar.userObj;
998 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700999 notifyRequester(request);
1000 break;
1001 case CMD_GET_NETWORK_SELECTION_MODE:
1002 request = (MainThreadRequest) msg.obj;
1003 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1004 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1005 break;
1006
1007 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1008 ar = (AsyncResult) msg.obj;
1009 request = (MainThreadRequest) ar.userObj;
1010 if (ar.exception != null) {
1011 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1012 } else {
1013 int mode = ((int[]) ar.result)[0];
1014 if (mode == 0) {
1015 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1016 } else {
1017 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1018 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001019 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001020 notifyRequester(request);
1021 break;
1022 case CMD_GET_CDMA_ROAMING_MODE:
1023 request = (MainThreadRequest) msg.obj;
1024 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1025 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1026 break;
1027 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1028 ar = (AsyncResult) msg.obj;
1029 request = (MainThreadRequest) ar.userObj;
1030 if (ar.exception != null) {
1031 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1032 } else {
1033 request.result = ((int[]) ar.result)[0];
1034 }
1035 notifyRequester(request);
1036 break;
1037 case CMD_SET_CDMA_ROAMING_MODE:
1038 request = (MainThreadRequest) msg.obj;
1039 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1040 int mode = (int) request.argument;
1041 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1042 break;
1043 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1044 ar = (AsyncResult) msg.obj;
1045 request = (MainThreadRequest) ar.userObj;
1046 request.result = ar.exception == null;
1047 notifyRequester(request);
1048 break;
1049 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1050 request = (MainThreadRequest) msg.obj;
1051 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1052 int subscriptionMode = (int) request.argument;
1053 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1054 break;
1055 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1056 ar = (AsyncResult) msg.obj;
1057 request = (MainThreadRequest) ar.userObj;
1058 request.result = ar.exception == null;
1059 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001060 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001061 case CMD_GET_ALL_CELL_INFO:
1062 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001063 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001064 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001065 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001066 case EVENT_GET_ALL_CELL_INFO_DONE:
1067 ar = (AsyncResult) msg.obj;
1068 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001069 // If a timeout occurs, the response will be null
1070 request.result = (ar.exception == null && ar.result != null)
1071 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001072 synchronized (request) {
1073 request.notifyAll();
1074 }
1075 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001076 case CMD_REQUEST_CELL_INFO_UPDATE:
1077 request = (MainThreadRequest) msg.obj;
1078 request.phone.requestCellInfoUpdate(request.workSource,
1079 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1080 break;
1081 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1082 ar = (AsyncResult) msg.obj;
1083 request = (MainThreadRequest) ar.userObj;
1084 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1085 try {
1086 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001087 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001088 cb.onError(
1089 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1090 ar.exception.getClass().getName(),
1091 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001092 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001093 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001094 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001095 } else {
1096 // use the result as returned
1097 cb.onCellInfo((List<CellInfo>) ar.result);
1098 }
1099 } catch (RemoteException re) {
1100 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1101 }
1102 break;
1103 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001104 request = (MainThreadRequest) msg.obj;
1105 WorkSource ws = (WorkSource) request.argument;
1106 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001107 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001108 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001109 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001110 ar = (AsyncResult) msg.obj;
1111 request = (MainThreadRequest) ar.userObj;
1112 if (ar.exception == null) {
1113 request.result = ar.result;
1114 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001115 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001116 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001117 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001118 }
1119
1120 synchronized (request) {
1121 request.notifyAll();
1122 }
1123 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001124 case CMD_MODEM_REBOOT:
1125 request = (MainThreadRequest) msg.obj;
1126 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001127 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001128 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001129 case EVENT_CMD_MODEM_REBOOT_DONE:
1130 handleNullReturnEvent(msg, "rebootModem");
1131 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001132 case CMD_REQUEST_ENABLE_MODEM:
1133 request = (MainThreadRequest) msg.obj;
1134 boolean enable = (boolean) request.argument;
1135 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001136 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001137 PhoneConfigurationManager.getInstance()
1138 .enablePhone(request.phone, enable, onCompleted);
1139 break;
1140 case EVENT_ENABLE_MODEM_DONE:
1141 ar = (AsyncResult) msg.obj;
1142 request = (MainThreadRequest) ar.userObj;
1143 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001144 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001145 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001146 if ((boolean) request.result) {
1147 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1148 updateModemStateMetrics();
1149 } else {
1150 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1151 + ar.exception);
1152 }
1153 notifyRequester(request);
1154 break;
1155 case CMD_GET_MODEM_STATUS:
1156 request = (MainThreadRequest) msg.obj;
1157 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1158 PhoneConfigurationManager.getInstance()
1159 .getPhoneStatusFromModem(request.phone, onCompleted);
1160 break;
1161 case EVENT_GET_MODEM_STATUS_DONE:
1162 ar = (AsyncResult) msg.obj;
1163 request = (MainThreadRequest) ar.userObj;
1164 int id = request.phone.getPhoneId();
1165 if (ar.exception == null && ar.result != null) {
1166 request.result = ar.result;
1167 //update the cache as modem status has changed
1168 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1169 (boolean) request.result);
1170 } else {
1171 // Return true if modem status cannot be retrieved. For most cases,
1172 // modem status is on. And for older version modems, GET_MODEM_STATUS
1173 // and disable modem are not supported. Modem is always on.
1174 // TODO: this should be fixed in R to support a third
1175 // status UNKNOWN b/131631629
1176 request.result = true;
1177 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1178 + ar.exception);
1179 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001180 notifyRequester(request);
1181 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001182 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1183 ar = (AsyncResult) msg.obj;
1184 request = (MainThreadRequest) ar.userObj;
1185 if (ar.exception == null && ar.result != null) {
1186 request.result = ar.result;
1187 } else {
1188 request.result = -1;
1189 loge("Failed to set Forbidden Plmns");
1190 if (ar.result == null) {
1191 loge("setForbidenPlmns: Empty response");
1192 } else if (ar.exception != null) {
1193 loge("setForbiddenPlmns: Exception: " + ar.exception);
1194 request.result = -1;
1195 } else {
1196 loge("setForbiddenPlmns: Unknown exception");
1197 }
1198 }
1199 notifyRequester(request);
1200 break;
1201 case CMD_SET_FORBIDDEN_PLMNS:
1202 request = (MainThreadRequest) msg.obj;
1203 uiccCard = getUiccCardFromRequest(request);
1204 if (uiccCard == null) {
1205 loge("setForbiddenPlmns: UiccCard is null");
1206 request.result = -1;
1207 notifyRequester(request);
1208 break;
1209 }
1210 Pair<Integer, List<String>> setFplmnsArgs =
1211 (Pair<Integer, List<String>>) request.argument;
1212 appType = setFplmnsArgs.first;
1213 List<String> fplmns = setFplmnsArgs.second;
1214 uiccApp = uiccCard.getApplicationByType(appType);
1215 if (uiccApp == null) {
1216 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1217 request.result = -1;
1218 loge("Failed to get UICC App");
1219 notifyRequester(request);
1220 } else {
1221 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1222 ((SIMRecords) uiccApp.getIccRecords())
1223 .setForbiddenPlmns(onCompleted, fplmns);
1224 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001225 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001226 case CMD_ERASE_MODEM_CONFIG:
1227 request = (MainThreadRequest) msg.obj;
1228 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1229 defaultPhone.eraseModemConfig(onCompleted);
1230 break;
1231 case EVENT_ERASE_MODEM_CONFIG_DONE:
1232 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001233 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001234 default:
1235 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1236 break;
1237 }
1238 }
Jake Hambye994d462014-02-03 13:10:13 -08001239
Pengquan Menga1bb6272018-09-06 09:59:22 -07001240 private void notifyRequester(MainThreadRequest request) {
1241 synchronized (request) {
1242 request.notifyAll();
1243 }
1244 }
1245
Jake Hambye994d462014-02-03 13:10:13 -08001246 private void handleNullReturnEvent(Message msg, String command) {
1247 AsyncResult ar = (AsyncResult) msg.obj;
1248 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1249 if (ar.exception == null) {
1250 request.result = true;
1251 } else {
1252 request.result = false;
1253 if (ar.exception instanceof CommandException) {
1254 loge(command + ": CommandException: " + ar.exception);
1255 } else {
1256 loge(command + ": Unknown exception");
1257 }
1258 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001259 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001260 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001261 }
1262
1263 /**
1264 * Posts the specified command to be executed on the main thread,
1265 * waits for the request to complete, and returns the result.
1266 * @see #sendRequestAsync
1267 */
1268 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001269 return sendRequest(
1270 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001271 }
1272
1273 /**
1274 * Posts the specified command to be executed on the main thread,
1275 * waits for the request to complete, and returns the result.
1276 * @see #sendRequestAsync
1277 */
1278 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1279 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001280 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001281 }
1282
1283 /**
1284 * Posts the specified command to be executed on the main thread,
1285 * waits for the request to complete, and returns the result.
1286 * @see #sendRequestAsync
1287 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001288 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001289 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001290 }
1291
1292 /**
1293 * Posts the specified command to be executed on the main thread,
1294 * waits for the request to complete, and returns the result.
1295 * @see #sendRequestAsync
1296 */
Nathan Harold92bed182018-10-12 18:16:49 -07001297 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1298 return sendRequest(command, argument, subId, null, workSource);
1299 }
1300
1301 /**
1302 * Posts the specified command to be executed on the main thread,
1303 * waits for the request to complete, and returns the result.
1304 * @see #sendRequestAsync
1305 */
1306 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1307 return sendRequest(
1308 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1309 }
1310
1311 /**
1312 * Posts the specified command to be executed on the main thread,
1313 * waits for the request to complete, and returns the result.
1314 * @see #sendRequestAsync
1315 */
1316 private Object sendRequest(
1317 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001318 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1319 throw new RuntimeException("This method will deadlock if called from the main thread.");
1320 }
1321
Nathan Harold92bed182018-10-12 18:16:49 -07001322 MainThreadRequest request = null;
1323 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1324 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1325 } else if (phone != null) {
1326 request = new MainThreadRequest(argument, phone, workSource);
1327 } else {
1328 request = new MainThreadRequest(argument, subId, workSource);
1329 }
1330
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331 Message msg = mMainThreadHandler.obtainMessage(command, request);
1332 msg.sendToTarget();
1333
1334 // Wait for the request to complete
1335 synchronized (request) {
1336 while (request.result == null) {
1337 try {
1338 request.wait();
1339 } catch (InterruptedException e) {
1340 // Do nothing, go back and wait until the request is complete
1341 }
1342 }
1343 }
1344 return request.result;
1345 }
1346
1347 /**
1348 * Asynchronous ("fire and forget") version of sendRequest():
1349 * Posts the specified command to be executed on the main thread, and
1350 * returns immediately.
1351 * @see #sendRequest
1352 */
1353 private void sendRequestAsync(int command) {
1354 mMainThreadHandler.sendEmptyMessage(command);
1355 }
1356
1357 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001358 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001359 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001360 */
1361 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001362 sendRequestAsync(command, argument, null, null);
1363 }
1364
1365 /**
1366 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1367 * @see {@link #sendRequest(int,Object)}
1368 */
1369 private void sendRequestAsync(
1370 int command, Object argument, Phone phone, WorkSource workSource) {
1371 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001372 Message msg = mMainThreadHandler.obtainMessage(command, request);
1373 msg.sendToTarget();
1374 }
1375
1376 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377 * Initialize the singleton PhoneInterfaceManager instance.
1378 * This is only done once, at startup, from PhoneApp.onCreate().
1379 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001380 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001381 synchronized (PhoneInterfaceManager.class) {
1382 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001383 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001384 } else {
1385 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1386 }
1387 return sInstance;
1388 }
1389 }
1390
1391 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001392 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001393 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001394 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001395 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001396 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001397 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1398 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001399 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001400 mTelephonySharedPreferences =
1401 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001402 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001403 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001404
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001405 publish();
1406 }
1407
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001408 private Phone getDefaultPhone() {
1409 Phone thePhone = getPhone(getDefaultSubscription());
1410 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1411 }
1412
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001413 private void publish() {
1414 if (DBG) log("publish: " + this);
1415
1416 ServiceManager.addService("phone", this);
1417 }
1418
Stuart Scott584921c2015-01-15 17:10:34 -08001419 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001420 if (request.phone != null) {
1421 return request.phone;
1422 } else {
1423 return getPhoneFromSubId(request.subId);
1424 }
1425 }
1426
1427 private Phone getPhoneFromSubId(int subId) {
1428 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1429 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001430 }
1431
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001432 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1433 Phone phone = getPhoneFromRequest(request);
1434 return phone == null ? null :
1435 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1436 }
1437
Wink Saville36469e72014-06-11 15:17:00 -07001438 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001439 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001440 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001441 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001442
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001443 private void sendEraseModemConfig(Phone phone) {
1444 if (phone != null) {
1445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1446 mApp, phone.getSubId(), "eraseModemConfig");
1447 final long identity = Binder.clearCallingIdentity();
1448 try {
1449 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1450 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1451 } finally {
1452 Binder.restoreCallingIdentity(identity);
1453 }
1454 }
1455 }
1456
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001457 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001458 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001459 }
1460
Wink Savilleb564aae2014-10-23 10:18:09 -07001461 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001462 if (DBG) log("dial: " + number);
1463 // No permission check needed here: This is just a wrapper around the
1464 // ACTION_DIAL intent, which is available to any app since it puts up
1465 // the UI before it does anything.
1466
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001467 final long identity = Binder.clearCallingIdentity();
1468 try {
1469 String url = createTelUrl(number);
1470 if (url == null) {
1471 return;
1472 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001473
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001474 // PENDING: should we just silently fail if phone is offhook or ringing?
1475 PhoneConstants.State state = mCM.getState(subId);
1476 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1477 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1478 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1479 mApp.startActivity(intent);
1480 }
1481 } finally {
1482 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001483 }
1484 }
1485
1486 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001487 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001488 }
1489
Wink Savilleb564aae2014-10-23 10:18:09 -07001490 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001491 if (DBG) log("call: " + number);
1492
1493 // This is just a wrapper around the ACTION_CALL intent, but we still
1494 // need to do a permission check since we're calling startActivity()
1495 // from the context of the phone app.
1496 enforceCallPermission();
1497
Jordan Liu1617b712019-07-10 15:06:26 -07001498 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001499 != AppOpsManager.MODE_ALLOWED) {
1500 return;
1501 }
1502
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001503 final long identity = Binder.clearCallingIdentity();
1504 try {
1505 String url = createTelUrl(number);
1506 if (url == null) {
1507 return;
1508 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001509
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001510 boolean isValid = false;
1511 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1512 if (slist != null) {
1513 for (SubscriptionInfo subInfoRecord : slist) {
1514 if (subInfoRecord.getSubscriptionId() == subId) {
1515 isValid = true;
1516 break;
1517 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001518 }
Wink Saville08874612014-08-31 19:19:58 -07001519 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001520 if (!isValid) {
1521 return;
1522 }
Wink Saville08874612014-08-31 19:19:58 -07001523
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001524 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1525 intent.putExtra(SUBSCRIPTION_KEY, subId);
1526 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1527 mApp.startActivity(intent);
1528 } finally {
1529 Binder.restoreCallingIdentity(identity);
1530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001531 }
1532
Wink Savilleb564aae2014-10-23 10:18:09 -07001533 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001534 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001535 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1536 }
1537
Wink Savilleb564aae2014-10-23 10:18:09 -07001538 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001539 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001540 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1541 }
1542
Wink Savilleb564aae2014-10-23 10:18:09 -07001543 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001544 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001545
1546 final long identity = Binder.clearCallingIdentity();
1547 try {
1548 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1549 checkSimPin.start();
1550 return checkSimPin.unlockSim(null, pin);
1551 } finally {
1552 Binder.restoreCallingIdentity(identity);
1553 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 }
1555
Wink Savilleb564aae2014-10-23 10:18:09 -07001556 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001557 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001558
1559 final long identity = Binder.clearCallingIdentity();
1560 try {
1561 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1562 checkSimPuk.start();
1563 return checkSimPuk.unlockSim(puk, pin);
1564 } finally {
1565 Binder.restoreCallingIdentity(identity);
1566 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567 }
1568
1569 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001570 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001571 * a synchronous one.
1572 */
1573 private static class UnlockSim extends Thread {
1574
1575 private final IccCard mSimCard;
1576
1577 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001578 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1579 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001580
1581 // For replies from SimCard interface
1582 private Handler mHandler;
1583
1584 // For async handler to identify request type
1585 private static final int SUPPLY_PIN_COMPLETE = 100;
1586
1587 public UnlockSim(IccCard simCard) {
1588 mSimCard = simCard;
1589 }
1590
1591 @Override
1592 public void run() {
1593 Looper.prepare();
1594 synchronized (UnlockSim.this) {
1595 mHandler = new Handler() {
1596 @Override
1597 public void handleMessage(Message msg) {
1598 AsyncResult ar = (AsyncResult) msg.obj;
1599 switch (msg.what) {
1600 case SUPPLY_PIN_COMPLETE:
1601 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1602 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001603 mRetryCount = msg.arg1;
1604 if (ar.exception != null) {
1605 if (ar.exception instanceof CommandException &&
1606 ((CommandException)(ar.exception)).getCommandError()
1607 == CommandException.Error.PASSWORD_INCORRECT) {
1608 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1609 } else {
1610 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1611 }
1612 } else {
1613 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1614 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001615 mDone = true;
1616 UnlockSim.this.notifyAll();
1617 }
1618 break;
1619 }
1620 }
1621 };
1622 UnlockSim.this.notifyAll();
1623 }
1624 Looper.loop();
1625 }
1626
1627 /*
1628 * Use PIN or PUK to unlock SIM card
1629 *
1630 * If PUK is null, unlock SIM card with PIN
1631 *
1632 * If PUK is not null, unlock SIM card with PUK and set PIN code
1633 */
Wink Saville9de0f752013-10-22 19:04:03 -07001634 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001635
1636 while (mHandler == null) {
1637 try {
1638 wait();
1639 } catch (InterruptedException e) {
1640 Thread.currentThread().interrupt();
1641 }
1642 }
1643 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1644
1645 if (puk == null) {
1646 mSimCard.supplyPin(pin, callback);
1647 } else {
1648 mSimCard.supplyPuk(puk, pin, callback);
1649 }
1650
1651 while (!mDone) {
1652 try {
1653 Log.d(LOG_TAG, "wait for done");
1654 wait();
1655 } catch (InterruptedException e) {
1656 // Restore the interrupted status
1657 Thread.currentThread().interrupt();
1658 }
1659 }
1660 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001661 int[] resultArray = new int[2];
1662 resultArray[0] = mResult;
1663 resultArray[1] = mRetryCount;
1664 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001665 }
1666 }
1667
1668 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001669 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001670
1671 }
1672
Wink Savilleb564aae2014-10-23 10:18:09 -07001673 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001674 // No permission check needed here: this call is harmless, and it's
1675 // needed for the ServiceState.requestStateUpdate() call (which is
1676 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001677 final long identity = Binder.clearCallingIdentity();
1678 try {
1679 final Phone phone = getPhone(subId);
1680 if (phone != null) {
1681 phone.updateServiceLocation();
1682 }
1683 } finally {
1684 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001685 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001686 }
1687
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001688 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001689 @Override
1690 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001691 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001692 }
1693
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001694 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001695 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1696 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1697 callingFeatureId);
1698 }
1699
1700 @Deprecated
1701 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001702 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001703 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
1704 }
1705
1706 @Override
1707 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1708 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001709 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001710 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001711 return false;
1712 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001713
1714 final long identity = Binder.clearCallingIdentity();
1715 try {
1716 return isRadioOnForSubscriber(subId);
1717 } finally {
1718 Binder.restoreCallingIdentity(identity);
1719 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001720 }
1721
1722 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001723 final long identity = Binder.clearCallingIdentity();
1724 try {
1725 final Phone phone = getPhone(subId);
1726 if (phone != null) {
1727 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1728 } else {
1729 return false;
1730 }
1731 } finally {
1732 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001733 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 }
1735
1736 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001737 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001738 }
Wink Saville36469e72014-06-11 15:17:00 -07001739
Wink Savilleb564aae2014-10-23 10:18:09 -07001740 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001742
1743 final long identity = Binder.clearCallingIdentity();
1744 try {
1745 final Phone phone = getPhone(subId);
1746 if (phone != null) {
1747 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1748 }
1749 } finally {
1750 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001751 }
Wink Saville36469e72014-06-11 15:17:00 -07001752 }
1753
1754 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001755 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001756 }
1757
Wink Savilleb564aae2014-10-23 10:18:09 -07001758 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001759 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001760
1761 final long identity = Binder.clearCallingIdentity();
1762 try {
1763 final Phone phone = getPhone(subId);
1764 if (phone == null) {
1765 return false;
1766 }
1767 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1768 toggleRadioOnOffForSubscriber(subId);
1769 }
1770 return true;
1771 } finally {
1772 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001773 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 }
Wink Saville36469e72014-06-11 15:17:00 -07001775
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001776 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08001777 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001778 /*
1779 * If any of the Radios are available, it will need to be
1780 * shutdown. So return true if any Radio is available.
1781 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001782 final long identity = Binder.clearCallingIdentity();
1783 try {
1784 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1785 Phone phone = PhoneFactory.getPhone(i);
1786 if (phone != null && phone.isRadioAvailable()) return true;
1787 }
1788 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1789 return false;
1790 } finally {
1791 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001792 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001793 }
1794
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001795 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001796 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001797 enforceModifyPermission();
1798
1799 final long identity = Binder.clearCallingIdentity();
1800 try {
1801 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1802 logv("Shutting down Phone " + i);
1803 shutdownRadioUsingPhoneId(i);
1804 }
1805 } finally {
1806 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001807 }
1808 }
1809
1810 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001811 Phone phone = PhoneFactory.getPhone(phoneId);
1812 if (phone != null && phone.isRadioAvailable()) {
1813 phone.shutdownRadio();
1814 }
1815 }
1816
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001817 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001818 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001819
1820 final long identity = Binder.clearCallingIdentity();
1821 try {
1822 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1823 if (defaultPhone != null) {
1824 defaultPhone.setRadioPower(turnOn);
1825 return true;
1826 } else {
1827 loge("There's no default phone.");
1828 return false;
1829 }
1830 } finally {
1831 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001832 }
Wink Saville36469e72014-06-11 15:17:00 -07001833 }
1834
Wink Savilleb564aae2014-10-23 10:18:09 -07001835 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001836 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001837
1838 final long identity = Binder.clearCallingIdentity();
1839 try {
1840 final Phone phone = getPhone(subId);
1841 if (phone != null) {
1842 phone.setRadioPower(turnOn);
1843 return true;
1844 } else {
1845 return false;
1846 }
1847 } finally {
1848 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001849 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001850 }
1851
Wink Saville36469e72014-06-11 15:17:00 -07001852 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001853 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001854 public boolean enableDataConnectivity() {
1855 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001856
1857 final long identity = Binder.clearCallingIdentity();
1858 try {
1859 int subId = mSubscriptionController.getDefaultDataSubId();
1860 final Phone phone = getPhone(subId);
1861 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001862 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001863 return true;
1864 } else {
1865 return false;
1866 }
1867 } finally {
1868 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001869 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001870 }
1871
Wink Saville36469e72014-06-11 15:17:00 -07001872 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001873 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001874 public boolean disableDataConnectivity() {
1875 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001876
1877 final long identity = Binder.clearCallingIdentity();
1878 try {
1879 int subId = mSubscriptionController.getDefaultDataSubId();
1880 final Phone phone = getPhone(subId);
1881 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001882 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001883 return true;
1884 } else {
1885 return false;
1886 }
1887 } finally {
1888 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001889 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 }
1891
Sanket Padawe356d7632015-06-22 14:03:32 -07001892 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001893 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001894 final long identity = Binder.clearCallingIdentity();
1895 try {
1896 final Phone phone = getPhone(subId);
1897 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001898 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001899 } else {
1900 return false;
1901 }
1902 } finally {
1903 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001904 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001905 }
1906
1907 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001908 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001909 }
1910
pkanwarae03a6b2016-11-06 20:37:09 -08001911 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001912 enforceCallPermission();
1913
1914 final long identity = Binder.clearCallingIdentity();
1915 try {
1916 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1917 return;
1918 }
1919 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1920 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1921 } finally {
1922 Binder.restoreCallingIdentity(identity);
1923 }
pkanwar32d516d2016-10-14 19:37:38 -07001924 };
1925
Wink Savilleb564aae2014-10-23 10:18:09 -07001926 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001927 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001928
1929 final long identity = Binder.clearCallingIdentity();
1930 try {
1931 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1932 return false;
1933 }
1934 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1935 } finally {
1936 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001937 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 }
1939
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001940 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001941 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001942 }
1943
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001944 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001945 final long identity = Binder.clearCallingIdentity();
1946 try {
1947 Phone phone = PhoneFactory.getPhone(slotIndex);
1948 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1949 PhoneConstantConversions.convertCallState(phone.getState());
1950 } finally {
1951 Binder.restoreCallingIdentity(identity);
1952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953 }
1954
Sanket Padawe356d7632015-06-22 14:03:32 -07001955 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001956 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001957 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1958 }
1959
1960 @Override
1961 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001962 final long identity = Binder.clearCallingIdentity();
1963 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001964 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001965 if (phone != null) {
1966 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1967 } else {
1968 return PhoneConstantConversions.convertDataState(
1969 PhoneConstants.DataState.DISCONNECTED);
1970 }
1971 } finally {
1972 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001973 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001974 }
1975
Sanket Padawe356d7632015-06-22 14:03:32 -07001976 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001977 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001978 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1979 }
1980
1981 @Override
1982 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001983 final long identity = Binder.clearCallingIdentity();
1984 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001985 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001986 if (phone != null) {
1987 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1988 } else {
1989 return TelephonyManager.DATA_ACTIVITY_NONE;
1990 }
1991 } finally {
1992 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001993 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001994 }
1995
1996 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08001997 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001998 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001999 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002000
2001 LocationAccessPolicy.LocationPermissionResult locationResult =
2002 LocationAccessPolicy.checkLocationPermission(mApp,
2003 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2004 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002005 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002006 .setCallingPid(Binder.getCallingPid())
2007 .setCallingUid(Binder.getCallingUid())
2008 .setMethod("getCellLocation")
2009 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2010 .build());
2011 switch (locationResult) {
2012 case DENIED_HARD:
2013 throw new SecurityException("Not allowed to access cell location");
2014 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002015 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2016 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 }
2018
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002019 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002020 final long identity = Binder.clearCallingIdentity();
2021 try {
2022 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002023 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002024 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002025 } finally {
2026 Binder.restoreCallingIdentity(identity);
2027 }
Svetoslav64fad262015-04-14 14:35:21 -07002028 }
2029
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002030 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002031 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2032 String callingFeatureId) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002033 if (!TextUtils.isEmpty(callingPackage)) {
2034 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002035 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2036 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002037 return "";
2038 }
2039 }
2040
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002041 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2042 // registered cell info, so return a NULL country instead.
2043 final long identity = Binder.clearCallingIdentity();
2044 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002045 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2046 // Get default phone in this case.
2047 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2048 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002049 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002050 // Todo: fix this when we can get the actual cellular network info when the device
2051 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002052 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002053 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2054 null)) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002055 return "";
2056 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002057 Phone phone = PhoneFactory.getPhone(phoneId);
2058 if (phone != null) {
2059 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002060 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002061 if (sst != null) {
2062 LocaleTracker lt = sst.getLocaleTracker();
2063 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002064 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2065 return lt.getCurrentCountry();
2066 } else if (emergencyNumberTracker != null) {
2067 return emergencyNumberTracker.getEmergencyCountryIso();
2068 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002069 }
2070 }
2071 }
2072 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002073 } finally {
2074 Binder.restoreCallingIdentity(identity);
2075 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002076 }
2077
2078 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002079 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002080 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002081 }
2082
Sanket Padawe356d7632015-06-22 14:03:32 -07002083 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002084 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085 mApp.enforceCallingOrSelfPermission(
2086 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002087
2088 final long identity = Binder.clearCallingIdentity();
2089 try {
2090 final Phone phone = getPhone(subId);
2091 if (phone != null) {
2092 phone.enableLocationUpdates();
2093 }
2094 } finally {
2095 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002096 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002097 }
2098
2099 @Override
2100 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002101 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002102 }
2103
Sanket Padawe356d7632015-06-22 14:03:32 -07002104 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002105 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002106 mApp.enforceCallingOrSelfPermission(
2107 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002108
2109 final long identity = Binder.clearCallingIdentity();
2110 try {
2111 final Phone phone = getPhone(subId);
2112 if (phone != null) {
2113 phone.disableLocationUpdates();
2114 }
2115 } finally {
2116 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002117 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002118 }
2119
Nathan Harold31d7ff32018-10-15 20:20:30 -07002120 /**
2121 * Returns the target SDK version number for a given package name.
2122 *
Nathan Haroldec184742019-07-10 17:04:16 -07002123 * This call MUST be invoked before clearing the calling UID.
2124 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002125 * @return target SDK if the package is found or INT_MAX.
2126 */
2127 private int getTargetSdk(String packageName) {
2128 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002129 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002130 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002131 if (ai != null) return ai.targetSdkVersion;
2132 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002133 loge("Failed to get package info for pkg="
2134 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002135 }
2136 return Integer.MAX_VALUE;
2137 }
2138
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002139 @Override
2140 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002141 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2142 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002143 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002144 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2145 throw new SecurityException(
2146 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2147 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002148
Jordan Liu1617b712019-07-10 15:06:26 -07002149 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2151 return null;
2152 }
Svetoslav64fad262015-04-14 14:35:21 -07002153
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002154 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002156 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002157 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002158
Nathan Haroldf180aac2018-06-01 18:43:55 -07002159 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2160 for (CellInfo ci : info) {
2161 if (ci instanceof CellInfoGsm) {
2162 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2163 } else if (ci instanceof CellInfoWcdma) {
2164 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2165 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002167 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 }
2169
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002170 private List<CellInfo> getCachedCellInfo() {
2171 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2172 for (Phone phone : PhoneFactory.getPhones()) {
2173 List<CellInfo> info = phone.getAllCellInfo();
2174 if (info != null) cellInfos.addAll(info);
2175 }
2176 return cellInfos;
2177 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002178
2179 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002180 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002181 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002182 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002183
2184 LocationAccessPolicy.LocationPermissionResult locationResult =
2185 LocationAccessPolicy.checkLocationPermission(mApp,
2186 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2187 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002188 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002189 .setCallingPid(Binder.getCallingPid())
2190 .setCallingUid(Binder.getCallingUid())
2191 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002192 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002193 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2194 .build());
2195 switch (locationResult) {
2196 case DENIED_HARD:
2197 throw new SecurityException("Not allowed to access cell info");
2198 case DENIED_SOFT:
2199 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002200 }
2201
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002202 final int targetSdk = getTargetSdk(callingPackage);
2203 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2204 return getCachedCellInfo();
2205 }
2206
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002207 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002208 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002209 final long identity = Binder.clearCallingIdentity();
2210 try {
2211 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2212 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002213 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002214 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002215 if (info != null) cellInfos.addAll(info);
2216 }
2217 return cellInfos;
2218 } finally {
2219 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220 }
2221 }
2222
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002223 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002224 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2225 String callingFeatureId) {
2226 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2227 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002228 }
2229
2230 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002231 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2232 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002233 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002234 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002235 }
2236
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002237 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2238 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002239 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002240 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002241
2242 LocationAccessPolicy.LocationPermissionResult locationResult =
2243 LocationAccessPolicy.checkLocationPermission(mApp,
2244 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2245 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002246 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002247 .setCallingPid(Binder.getCallingPid())
2248 .setCallingUid(Binder.getCallingUid())
2249 .setMethod("requestCellInfoUpdate")
2250 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2251 .build());
2252 switch (locationResult) {
2253 case DENIED_HARD:
2254 throw new SecurityException("Not allowed to access cell info");
2255 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002256 try {
2257 cb.onCellInfo(new ArrayList<CellInfo>());
2258 } catch (RemoteException re) {
2259 // Drop without consequences
2260 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002261 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002262 }
2263
Nathan Harolda939a962019-05-09 10:13:47 -07002264
2265 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002266 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2267
2268 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2269 }
2270
2271 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002272 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002273 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002274 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002275
2276 final long identity = Binder.clearCallingIdentity();
2277 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002278 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002279 } finally {
2280 Binder.restoreCallingIdentity(identity);
2281 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 }
2283
Shishir Agrawala9f32182016-04-12 12:00:16 -07002284 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002285 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002286 Phone phone = PhoneFactory.getPhone(slotIndex);
2287 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002288 return null;
2289 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002290 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002291 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002292 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002293 return null;
2294 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002295
2296 final long identity = Binder.clearCallingIdentity();
2297 try {
2298 return phone.getImei();
2299 } finally {
2300 Binder.restoreCallingIdentity(identity);
2301 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002302 }
2303
2304 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002305 public String getTypeAllocationCodeForSlot(int slotIndex) {
2306 Phone phone = PhoneFactory.getPhone(slotIndex);
2307 String tac = null;
2308 if (phone != null) {
2309 String imei = phone.getImei();
2310 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2311 }
2312 return tac;
2313 }
2314
2315 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002316 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002317 Phone phone = PhoneFactory.getPhone(slotIndex);
2318 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002319 return null;
2320 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002321
Jeff Davidson913390f2018-02-23 17:11:49 -08002322 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002323 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002324 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002325 return null;
2326 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002327
2328 final long identity = Binder.clearCallingIdentity();
2329 try {
2330 return phone.getMeid();
2331 } finally {
2332 Binder.restoreCallingIdentity(identity);
2333 }
Jack Yu2af8d712017-03-15 17:14:14 -07002334 }
2335
2336 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002337 public String getManufacturerCodeForSlot(int slotIndex) {
2338 Phone phone = PhoneFactory.getPhone(slotIndex);
2339 String manufacturerCode = null;
2340 if (phone != null) {
2341 String meid = phone.getMeid();
2342 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2343 }
2344 return manufacturerCode;
2345 }
2346
2347 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002348 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2349 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002350 Phone phone = PhoneFactory.getPhone(slotIndex);
2351 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002352 return null;
2353 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002354 int subId = phone.getSubId();
2355 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002356 mApp, subId, callingPackage, callingFeatureId,
2357 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002358 return null;
2359 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002360
2361 final long identity = Binder.clearCallingIdentity();
2362 try {
2363 return phone.getDeviceSvn();
2364 } finally {
2365 Binder.restoreCallingIdentity(identity);
2366 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002367 }
2368
fionaxu43304da2017-11-27 22:51:16 -08002369 @Override
2370 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002371 final long identity = Binder.clearCallingIdentity();
2372 try {
2373 final Phone phone = getPhone(subId);
2374 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2375 } finally {
2376 Binder.restoreCallingIdentity(identity);
2377 }
fionaxu43304da2017-11-27 22:51:16 -08002378 }
2379
2380 @Override
2381 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002382 final long identity = Binder.clearCallingIdentity();
2383 try {
2384 final Phone phone = getPhone(subId);
2385 return phone == null ? null : phone.getCarrierName();
2386 } finally {
2387 Binder.restoreCallingIdentity(identity);
2388 }
fionaxu43304da2017-11-27 22:51:16 -08002389 }
2390
calvinpanffe225e2018-11-01 19:43:06 +08002391 @Override
chen xu0026ca62019-03-06 15:28:50 -08002392 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002393 final long identity = Binder.clearCallingIdentity();
2394 try {
2395 final Phone phone = getPhone(subId);
2396 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002397 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002398 } finally {
2399 Binder.restoreCallingIdentity(identity);
2400 }
2401 }
2402
2403 @Override
chen xu0026ca62019-03-06 15:28:50 -08002404 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002405 final long identity = Binder.clearCallingIdentity();
2406 try {
2407 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002408 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002409 } finally {
2410 Binder.restoreCallingIdentity(identity);
2411 }
2412 }
2413
chen xu651eec72018-11-11 19:03:44 -08002414 @Override
chen xu864e11c2018-12-06 22:10:03 -08002415 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2416 if (!isSubscriptionMccMnc) {
2417 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2418 }
chen xu651eec72018-11-11 19:03:44 -08002419 final Phone phone = PhoneFactory.getPhone(slotIndex);
2420 if (phone == null) {
2421 return TelephonyManager.UNKNOWN_CARRIER_ID;
2422 }
2423 final long identity = Binder.clearCallingIdentity();
2424 try {
2425 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2426 } finally {
2427 Binder.restoreCallingIdentity(identity);
2428 }
2429 }
2430
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 //
2432 // Internal helper methods.
2433 //
2434
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002435 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2437 *
2438 * @throws SecurityException if the caller does not have the required permission
2439 */
2440 private void enforceModifyPermission() {
2441 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2442 }
2443
Shuo Qianf2b2df42019-11-13 17:43:31 -08002444 private void enforceActiveEmergencySessionPermission() {
2445 mApp.enforceCallingOrSelfPermission(
2446 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2447 }
2448
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 /**
2450 * Make sure the caller has the CALL_PHONE permission.
2451 *
2452 * @throws SecurityException if the caller does not have the required permission
2453 */
2454 private void enforceCallPermission() {
2455 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2456 }
2457
paulhu423b5f22019-08-23 19:17:33 +08002458 private void enforceSettingsPermission() {
2459 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002460 }
2461
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 private String createTelUrl(String number) {
2463 if (TextUtils.isEmpty(number)) {
2464 return null;
2465 }
2466
Jake Hambye994d462014-02-03 13:10:13 -08002467 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 }
2469
Ihab Awadf9e92732013-12-05 18:02:52 -08002470 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2472 }
2473
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002474 private static void logv(String msg) {
2475 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2476 }
2477
Ihab Awadf9e92732013-12-05 18:02:52 -08002478 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2480 }
2481
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002482 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002483 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002484 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002485 }
2486
Sanket Padawe356d7632015-06-22 14:03:32 -07002487 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002488 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002489 final long identity = Binder.clearCallingIdentity();
2490 try {
2491 final Phone phone = PhoneFactory.getPhone(slotIndex);
2492 if (phone == null) {
2493 return PhoneConstants.PHONE_TYPE_NONE;
2494 } else {
2495 return phone.getPhoneType();
2496 }
2497 } finally {
2498 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 }
2501
2502 /**
2503 * Returns the CDMA ERI icon index to display
2504 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002505 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002506 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2507 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2508 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002509 }
2510
Sanket Padawe356d7632015-06-22 14:03:32 -07002511 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002512 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2513 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002514 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002515 mApp, subId, callingPackage, callingFeatureId,
2516 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002517 return -1;
2518 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002519
2520 final long identity = Binder.clearCallingIdentity();
2521 try {
2522 final Phone phone = getPhone(subId);
2523 if (phone != null) {
2524 return phone.getCdmaEriIconIndex();
2525 } else {
2526 return -1;
2527 }
2528 } finally {
2529 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002531 }
2532
2533 /**
2534 * Returns the CDMA ERI icon mode,
2535 * 0 - ON
2536 * 1 - FLASHING
2537 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002538 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002539 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2540 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2541 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002542 }
2543
Sanket Padawe356d7632015-06-22 14:03:32 -07002544 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002545 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2546 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002547 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002548 mApp, subId, callingPackage, callingFeatureId,
2549 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002550 return -1;
2551 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002552
2553 final long identity = Binder.clearCallingIdentity();
2554 try {
2555 final Phone phone = getPhone(subId);
2556 if (phone != null) {
2557 return phone.getCdmaEriIconMode();
2558 } else {
2559 return -1;
2560 }
2561 } finally {
2562 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002564 }
2565
2566 /**
2567 * Returns the CDMA ERI text,
2568 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002569 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002570 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2571 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2572 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002573 }
2574
Sanket Padawe356d7632015-06-22 14:03:32 -07002575 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002576 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2577 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002578 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002579 mApp, subId, callingPackage, callingFeatureId,
2580 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002581 return null;
2582 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002583
2584 final long identity = Binder.clearCallingIdentity();
2585 try {
2586 final Phone phone = getPhone(subId);
2587 if (phone != null) {
2588 return phone.getCdmaEriText();
2589 } else {
2590 return null;
2591 }
2592 } finally {
2593 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002594 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002595 }
2596
2597 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002598 * Returns the CDMA MDN.
2599 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002600 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002601 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2603 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002604
2605 final long identity = Binder.clearCallingIdentity();
2606 try {
2607 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002608 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002609 return phone.getLine1Number();
2610 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002611 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612 return null;
2613 }
2614 } finally {
2615 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002616 }
2617 }
2618
2619 /**
2620 * Returns the CDMA MIN.
2621 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002622 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002623 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2625 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626
2627 final long identity = Binder.clearCallingIdentity();
2628 try {
2629 final Phone phone = getPhone(subId);
2630 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2631 return phone.getCdmaMin();
2632 } else {
2633 return null;
2634 }
2635 } finally {
2636 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002637 }
2638 }
2639
Hall Liud892bec2018-11-30 14:51:45 -08002640 @Override
2641 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2642 INumberVerificationCallback callback, String callingPackage) {
2643 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2644 != PERMISSION_GRANTED) {
2645 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2646 }
2647 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2648
2649 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2650 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2651 throw new SecurityException("Calling package must be configured in the device config");
2652 }
2653
2654 if (range == null) {
2655 throw new NullPointerException("Range must be non-null");
2656 }
2657
2658 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002659 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002660
2661 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2662 }
2663
Junda Liuca05d5d2014-08-14 22:36:34 -07002664 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002665 * Returns true if CDMA provisioning needs to run.
2666 */
2667 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668 final long identity = Binder.clearCallingIdentity();
2669 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002670 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002671 } finally {
2672 Binder.restoreCallingIdentity(identity);
2673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002674 }
2675
2676 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002677 * Sets the voice mail number of a given subId.
2678 */
2679 @Override
2680 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002681 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002682
2683 final long identity = Binder.clearCallingIdentity();
2684 try {
2685 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2686 new Pair<String, String>(alphaTag, number), new Integer(subId));
2687 return success;
2688 } finally {
2689 Binder.restoreCallingIdentity(identity);
2690 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002691 }
2692
Ta-wei Yen87c49842016-05-13 21:19:52 -07002693 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002694 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2695 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002696 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2697 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002698 if (!TextUtils.equals(callingPackage, systemDialer)) {
2699 throw new SecurityException("caller must be system dialer");
2700 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002701
2702 final long identity = Binder.clearCallingIdentity();
2703 try {
2704 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2705 if (phoneAccountHandle == null) {
2706 return null;
2707 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002708 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002709 } finally {
2710 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002711 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002712 }
2713
2714 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002715 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2716 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002717 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002718 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002719 mApp, subId, callingPackage, callingFeatureId,
2720 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002721 return null;
2722 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002723
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002724 final long identity = Binder.clearCallingIdentity();
2725 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002726 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002727 } finally {
2728 Binder.restoreCallingIdentity(identity);
2729 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002730 }
2731
2732 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002733 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2734 VisualVoicemailSmsFilterSettings settings) {
2735 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002736
2737 final long identity = Binder.clearCallingIdentity();
2738 try {
2739 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002740 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002741 } finally {
2742 Binder.restoreCallingIdentity(identity);
2743 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002744 }
2745
2746 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002747 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2748 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002749
2750 final long identity = Binder.clearCallingIdentity();
2751 try {
2752 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002753 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002754 } finally {
2755 Binder.restoreCallingIdentity(identity);
2756 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002757 }
2758
2759 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002760 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2761 String callingPackage, int subId) {
2762 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002763
2764 final long identity = Binder.clearCallingIdentity();
2765 try {
2766 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002767 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002768 } finally {
2769 Binder.restoreCallingIdentity(identity);
2770 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002771 }
2772
2773 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002774 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002775 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002776
2777 final long identity = Binder.clearCallingIdentity();
2778 try {
2779 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002780 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002781 } finally {
2782 Binder.restoreCallingIdentity(identity);
2783 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002784 }
2785
2786 @Override
2787 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2788 String number, int port, String text, PendingIntent sentIntent) {
2789 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002790 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002791 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002792 SmsController smsController = PhoneFactory.getSmsController();
2793 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2794 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002795 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002796
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002797 /**
fionaxu0152e512016-11-14 13:36:14 -08002798 * Sets the voice activation state of a given subId.
2799 */
2800 @Override
2801 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002802 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2803 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002804
2805 final long identity = Binder.clearCallingIdentity();
2806 try {
2807 final Phone phone = getPhone(subId);
2808 if (phone != null) {
2809 phone.setVoiceActivationState(activationState);
2810 } else {
2811 loge("setVoiceActivationState fails with invalid subId: " + subId);
2812 }
2813 } finally {
2814 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002815 }
2816 }
2817
2818 /**
2819 * Sets the data activation state of a given subId.
2820 */
2821 @Override
2822 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2824 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002825
2826 final long identity = Binder.clearCallingIdentity();
2827 try {
2828 final Phone phone = getPhone(subId);
2829 if (phone != null) {
2830 phone.setDataActivationState(activationState);
2831 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002832 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002833 }
2834 } finally {
2835 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002836 }
2837 }
2838
2839 /**
2840 * Returns the voice activation state of a given subId.
2841 */
2842 @Override
2843 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002844 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002845
fionaxu0152e512016-11-14 13:36:14 -08002846 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002847 final long identity = Binder.clearCallingIdentity();
2848 try {
2849 if (phone != null) {
2850 return phone.getVoiceActivationState();
2851 } else {
2852 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2853 }
2854 } finally {
2855 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002856 }
2857 }
2858
2859 /**
2860 * Returns the data activation state of a given subId.
2861 */
2862 @Override
2863 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002864 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002865
fionaxu0152e512016-11-14 13:36:14 -08002866 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002867 final long identity = Binder.clearCallingIdentity();
2868 try {
2869 if (phone != null) {
2870 return phone.getDataActivationState();
2871 } else {
2872 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2873 }
2874 } finally {
2875 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002876 }
2877 }
2878
2879 /**
Wink Saville36469e72014-06-11 15:17:00 -07002880 * Returns the unread count of voicemails for a subId
2881 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002882 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002883 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2884 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002885 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002886 mApp, subId, callingPackage, callingFeatureId,
2887 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002888 return 0;
2889 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002890 final long identity = Binder.clearCallingIdentity();
2891 try {
2892 final Phone phone = getPhone(subId);
2893 if (phone != null) {
2894 return phone.getVoiceMessageCount();
2895 } else {
2896 return 0;
2897 }
2898 } finally {
2899 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002900 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002901 }
2902
2903 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002904 * returns true, if the device is in a state where both voice and data
2905 * are supported simultaneously. This can change based on location or network condition.
2906 */
2907 @Override
2908 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002909 final long identity = Binder.clearCallingIdentity();
2910 try {
2911 final Phone phone = getPhone(subId);
2912 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2913 } finally {
2914 Binder.restoreCallingIdentity(identity);
2915 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002916 }
2917
2918 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002919 * Send the dialer code if called from the current default dialer or the caller has
2920 * carrier privilege.
2921 * @param inputCode The dialer code to send
2922 */
2923 @Override
2924 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002925 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002926 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002927 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2928 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002929 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002930 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2931 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002932 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002933
2934 final long identity = Binder.clearCallingIdentity();
2935 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002936 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002937 } finally {
2938 Binder.restoreCallingIdentity(identity);
2939 }
fionaxu235cc5e2017-03-06 22:25:57 -08002940 }
2941
Pengquan Menga1bb6272018-09-06 09:59:22 -07002942 @Override
2943 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002944 if (!isActiveSubscription(subId)) {
2945 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2946 }
2947
Pengquan Menga1bb6272018-09-06 09:59:22 -07002948 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2949 }
2950
Brad Ebinger35c841c2018-10-01 10:40:55 -07002951 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002952 public boolean isInEmergencySmsMode() {
2953 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2954 final long identity = Binder.clearCallingIdentity();
2955 try {
2956 for (Phone phone : PhoneFactory.getPhones()) {
2957 if (phone.isInEmergencySmsMode()) {
2958 return true;
2959 }
2960 }
2961 } finally {
2962 Binder.restoreCallingIdentity(identity);
2963 }
2964 return false;
2965 }
2966
2967 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002968 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2969 throws RemoteException {
2970 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07002971 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2972 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2973 "IMS not available on device.");
2974 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002975 final long token = Binder.clearCallingIdentity();
2976 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002977 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002978 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002979 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002980 } catch (ImsException e) {
2981 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002982 } finally {
2983 Binder.restoreCallingIdentity(token);
2984 }
2985 }
2986
2987 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002988 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2989 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002990 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2991 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2992 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07002993 final long token = Binder.clearCallingIdentity();
2994 try {
2995 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2996 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2997 .removeRegistrationCallbackForSubscription(c, subId);
2998 } catch (ImsException e) {
2999 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3000 + "is inactive, ignoring unregister.");
3001 // If the subscription is no longer active, just return, since the callback
3002 // will already have been removed internally.
3003 } finally {
3004 Binder.restoreCallingIdentity(token);
3005 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003006 }
3007
Brad Ebinger774ba362019-10-22 17:36:18 -07003008 /**
3009 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3010 */
3011 @Override
3012 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3013 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3014 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3015 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3016 "IMS not available on device.");
3017 }
3018 final long token = Binder.clearCallingIdentity();
3019 try {
3020 Phone phone = getPhone(subId);
3021 if (phone == null) {
3022 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3023 + subId + "'");
3024 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3025 }
3026 phone.getImsRegistrationState(regState -> {
3027 try {
3028 consumer.accept((regState == null)
3029 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3030 } catch (RemoteException e) {
3031 // Ignore if the remote process is no longer available to call back.
3032 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3033 }
3034 });
3035 } finally {
3036 Binder.restoreCallingIdentity(token);
3037 }
3038 }
3039
3040 /**
3041 * Get the transport type for the IMS service registration state.
3042 */
3043 @Override
3044 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3045 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3046 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3047 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3048 "IMS not available on device.");
3049 }
3050 final long token = Binder.clearCallingIdentity();
3051 try {
3052 Phone phone = getPhone(subId);
3053 if (phone == null) {
3054 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3055 + subId + "'");
3056 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3057 }
3058 phone.getImsRegistrationTech(regTech -> {
3059 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3060 int regTechConverted = (regTech == null)
3061 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3062 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3063 regTechConverted);
3064 try {
3065 consumer.accept(regTechConverted);
3066 } catch (RemoteException e) {
3067 // Ignore if the remote process is no longer available to call back.
3068 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3069 }
3070 });
3071 } finally {
3072 Binder.restoreCallingIdentity(token);
3073 }
3074 }
3075
Brad Ebinger35c841c2018-10-01 10:40:55 -07003076 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003077 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3078 throws RemoteException {
3079 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003080 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3081 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3082 "IMS not available on device.");
3083 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003084 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3085 final long token = Binder.clearCallingIdentity();
3086 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003087 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003088 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003089 } catch (ImsException e) {
3090 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003091 } finally {
3092 Binder.restoreCallingIdentity(token);
3093 }
3094 }
3095
3096 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003097 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3098 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003099 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3100 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3101 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003102
3103 final long token = Binder.clearCallingIdentity();
3104 try {
3105 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3106 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003107 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003108 } catch (ImsException e) {
3109 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3110 + "is inactive, ignoring unregister.");
3111 // If the subscription is no longer active, just return, since the callback
3112 // will already have been removed internally.
3113 } finally {
3114 Binder.restoreCallingIdentity(token);
3115 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003116 }
3117
3118 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003119 public boolean isCapable(int subId, int capability, int regTech) {
3120 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003121 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3122 final long token = Binder.clearCallingIdentity();
3123 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003124 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003125 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003126 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003127 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3128 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003129 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003130 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3131 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003132 } finally {
3133 Binder.restoreCallingIdentity(token);
3134 }
3135 }
3136
3137 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003138 public boolean isAvailable(int subId, int capability, int regTech) {
3139 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003140 final long token = Binder.clearCallingIdentity();
3141 try {
3142 Phone phone = getPhone(subId);
3143 if (phone == null) return false;
3144 return phone.isImsCapabilityAvailable(capability, regTech);
3145 } finally {
3146 Binder.restoreCallingIdentity(token);
3147 }
3148 }
3149
Brad Ebinger77b832e2019-10-17 17:03:22 -07003150 /**
3151 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3152 * subscription.
3153 * @param subId The subscription to use to check the configuration.
3154 * @param callback The callback that will be used to send the result.
3155 * @param capability The MmTelFeature capability that will be used to send the result.
3156 * @param transportType The transport type of the MmTelFeature capability.
3157 */
3158 @Override
3159 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3160 int transportType) {
3161 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3162 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3163 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3164 "IMS not available on device.");
3165 }
3166 final long token = Binder.clearCallingIdentity();
3167 try {
3168 int slotId = getSlotIndex(subId);
3169 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3170 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3171 + subId + "'");
3172 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3173 }
3174 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3175 transportType, aBoolean -> {
3176 try {
3177 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3178 } catch (RemoteException e) {
3179 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3180 + "running. Ignore");
3181 }
3182 });
3183 } finally {
3184 Binder.restoreCallingIdentity(token);
3185 }
3186 }
3187
Brad Ebinger35c841c2018-10-01 10:40:55 -07003188 @Override
3189 public boolean isAdvancedCallingSettingEnabled(int subId) {
3190 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3191 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3192 final long token = Binder.clearCallingIdentity();
3193 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003194 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003195 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003196 } catch (ImsException e) {
3197 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003198 } finally {
3199 Binder.restoreCallingIdentity(token);
3200 }
3201 }
3202
3203 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003204 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003205 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003206 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003207 final long identity = Binder.clearCallingIdentity();
3208 try {
3209 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003210 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003211 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003212 } catch (ImsException e) {
3213 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003214 } finally {
3215 Binder.restoreCallingIdentity(identity);
3216 }
3217 }
3218
3219 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003220 public boolean isVtSettingEnabled(int subId) {
3221 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003222 final long identity = Binder.clearCallingIdentity();
3223 try {
3224 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003225 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3226 } catch (ImsException e) {
3227 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003228 } finally {
3229 Binder.restoreCallingIdentity(identity);
3230 }
3231 }
3232
3233 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003234 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003235 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003236 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003237 final long identity = Binder.clearCallingIdentity();
3238 try {
3239 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003240 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003241 } catch (ImsException e) {
3242 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003243 } finally {
3244 Binder.restoreCallingIdentity(identity);
3245 }
3246 }
3247
3248 @Override
3249 public boolean isVoWiFiSettingEnabled(int subId) {
3250 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3251 final long identity = Binder.clearCallingIdentity();
3252 try {
3253 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003254 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003255 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003256 } catch (ImsException e) {
3257 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003258 } finally {
3259 Binder.restoreCallingIdentity(identity);
3260 }
3261 }
3262
3263 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003264 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003265 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003266 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003267 final long identity = Binder.clearCallingIdentity();
3268 try {
3269 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003270 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003271 } catch (ImsException e) {
3272 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003273 } finally {
3274 Binder.restoreCallingIdentity(identity);
3275 }
3276 }
3277
3278 @Override
3279 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3280 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3281 final long identity = Binder.clearCallingIdentity();
3282 try {
3283 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003284 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003285 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003286 } catch (ImsException e) {
3287 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003288 } finally {
3289 Binder.restoreCallingIdentity(identity);
3290 }
3291 }
3292
3293 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003294 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003296 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003297 final long identity = Binder.clearCallingIdentity();
3298 try {
3299 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003300 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003301 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003302 } catch (ImsException e) {
3303 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003304 } finally {
3305 Binder.restoreCallingIdentity(identity);
3306 }
3307 }
3308
3309 @Override
3310 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3311 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3312 "setVoWiFiNonPersistent");
3313 final long identity = Binder.clearCallingIdentity();
3314 try {
3315 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003316 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003317 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003318 } catch (ImsException e) {
3319 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003320 } finally {
3321 Binder.restoreCallingIdentity(identity);
3322 }
3323 }
3324
3325 @Override
3326 public int getVoWiFiModeSetting(int subId) {
3327 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3328 final long identity = Binder.clearCallingIdentity();
3329 try {
3330 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003331 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003332 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003333 } catch (ImsException e) {
3334 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003335 } finally {
3336 Binder.restoreCallingIdentity(identity);
3337 }
3338 }
3339
3340 @Override
3341 public void setVoWiFiModeSetting(int subId, int mode) {
3342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3343 "setVoWiFiModeSetting");
3344 final long identity = Binder.clearCallingIdentity();
3345 try {
3346 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003347 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003348 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003349 } catch (ImsException e) {
3350 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003351 } finally {
3352 Binder.restoreCallingIdentity(identity);
3353 }
3354 }
3355
3356 @Override
3357 public int getVoWiFiRoamingModeSetting(int subId) {
3358 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3359 final long identity = Binder.clearCallingIdentity();
3360 try {
3361 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003362 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003363 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003364 } catch (ImsException e) {
3365 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003366 } finally {
3367 Binder.restoreCallingIdentity(identity);
3368 }
3369 }
3370
3371 @Override
3372 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3374 "setVoWiFiRoamingModeSetting");
3375 final long identity = Binder.clearCallingIdentity();
3376 try {
3377 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003378 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003379 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003380 } catch (ImsException e) {
3381 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003382 } finally {
3383 Binder.restoreCallingIdentity(identity);
3384 }
3385 }
3386
3387 @Override
3388 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3389 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3390 "setRttCapabilityEnabled");
3391 final long identity = Binder.clearCallingIdentity();
3392 try {
3393 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003394 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3395 } catch (ImsException e) {
3396 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003397 } finally {
3398 Binder.restoreCallingIdentity(identity);
3399 }
3400 }
3401
3402 @Override
3403 public boolean isTtyOverVolteEnabled(int subId) {
3404 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3405 final long identity = Binder.clearCallingIdentity();
3406 try {
3407 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003408 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003409 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003410 } catch (ImsException e) {
3411 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003412 } finally {
3413 Binder.restoreCallingIdentity(identity);
3414 }
3415 }
3416
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003417 @Override
3418 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3419 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3420 final long identity = Binder.clearCallingIdentity();
3421 try {
3422 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003423 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003424 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003425 } catch (ImsException e) {
3426 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003427 } finally {
3428 Binder.restoreCallingIdentity(identity);
3429 }
3430 }
3431
3432 @Override
3433 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3434 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3435 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003436 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3437 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3438 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003439 try {
3440 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003441 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003442 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003443 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003444 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3445 + "is inactive, ignoring unregister.");
3446 // If the subscription is no longer active, just return, since the callback will already
3447 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003448 } finally {
3449 Binder.restoreCallingIdentity(identity);
3450 }
3451 }
3452
allenwtsu99c623b2020-01-03 18:24:23 +08003453
3454 private void checkModifyPhoneStatePermission(int subId, String message) {
3455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3456 message);
3457 }
3458
3459 private boolean isImsProvisioningRequired(int subId, int capability,
3460 boolean isMmtelCapability) {
3461 Phone phone = getPhone(subId);
3462 if (phone == null) {
3463 loge("phone instance null for subid " + subId);
3464 return false;
3465 }
3466 if (isMmtelCapability) {
3467 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3468 return false;
3469 }
3470 } else {
3471 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3472 return false;
3473 }
3474 }
3475 return true;
3476 }
3477
3478 @Override
3479 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3480 boolean isProvisioned) {
3481 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3482
3483 final long identity = Binder.clearCallingIdentity();
3484 try {
3485 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3486 if (!isImsProvisioningRequired(subId, capability, false)) {
3487 return;
3488 }
3489
3490 // this capability requires provisioning, route to the correct API.
3491 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3492 switch (capability) {
3493 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3494 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3495 ims.setEabProvisioned(isProvisioned);
3496 break;
3497 default: {
3498 throw new IllegalArgumentException("Tried to set provisioning for "
3499 + "rcs capability '" + capability + "', which does not require "
3500 + "provisioning.");
3501 }
3502 }
3503 } finally {
3504 Binder.restoreCallingIdentity(identity);
3505 }
3506
3507 }
3508
3509
3510 @Override
3511 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3512 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3513 final long identity = Binder.clearCallingIdentity();
3514 try {
3515 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3516 if (!isImsProvisioningRequired(subId, capability, false)) {
3517 return true;
3518 }
3519
3520 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3521 switch (capability) {
3522 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3523 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3524 return ims.isEabProvisionedOnDevice();
3525
3526 default: {
3527 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3528 + "capability '" + capability + "', which does not require "
3529 + "provisioning.");
3530 }
3531 }
3532
3533 } finally {
3534 Binder.restoreCallingIdentity(identity);
3535 }
3536 }
3537
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003538 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003539 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3540 boolean isProvisioned) {
3541 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3542 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3543 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3544 }
allenwtsu99c623b2020-01-03 18:24:23 +08003545 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003546 final long identity = Binder.clearCallingIdentity();
3547 try {
3548 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003549 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003550 return;
3551 }
3552
3553 // this capability requires provisioning, route to the correct API.
3554 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3555 switch (capability) {
3556 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3557 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3558 ims.setVolteProvisioned(isProvisioned);
3559 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3560 ims.setWfcProvisioned(isProvisioned);
3561 }
3562 break;
3563 }
3564 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3565 // There is currently no difference in VT provisioning type.
3566 ims.setVtProvisioned(isProvisioned);
3567 break;
3568 }
3569 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3570 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3571 // change the capability of the feature instead if needed.
3572 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3573 == isProvisioned) {
3574 // No change in provisioning.
3575 return;
3576 }
3577 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3578 try {
3579 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003580 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003581 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3582 + ", Exception" + e.getMessage());
3583 }
3584 break;
3585 }
3586 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003587 throw new IllegalArgumentException("Tried to set provisioning for "
3588 + "MmTel capability '" + capability + "', which does not require "
3589 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003590 }
3591 }
3592
3593 } finally {
3594 Binder.restoreCallingIdentity(identity);
3595 }
3596 }
3597
3598 @Override
3599 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3600 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3601 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3602 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3603 }
3604 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3605 final long identity = Binder.clearCallingIdentity();
3606 try {
3607 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003608 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003609 return true;
3610 }
3611
3612 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3613 switch (capability) {
3614 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3615 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3616 return ims.isVolteProvisionedOnDevice();
3617 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3618 return ims.isWfcProvisionedOnDevice();
3619 }
3620 // This should never happen, since we are checking tech above to make sure it
3621 // is either LTE or IWLAN.
3622 throw new IllegalArgumentException("Invalid radio technology for voice "
3623 + "capability.");
3624 }
3625 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3626 // There is currently no difference in VT provisioning type.
3627 return ims.isVtProvisionedOnDevice();
3628 }
3629 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3630 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3631 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3632 }
3633 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003634 throw new IllegalArgumentException(
3635 "Tried to get provisioning for MmTel capability '" + capability
3636 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003637 }
3638 }
3639
3640 } finally {
3641 Binder.restoreCallingIdentity(identity);
3642 }
3643 }
3644
3645 @Override
3646 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3647 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3648 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3649 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3650 }
3651 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3652 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3653 return (provisionedBits & capability) > 0;
3654 }
3655
3656 @Override
3657 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3658 boolean isProvisioned) {
3659 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3660 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3661 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3662 }
3663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3664 "setProvisioningStatusForCapability");
3665 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3666 // If the current provisioning status for capability already matches isProvisioned,
3667 // do nothing.
3668 if (((provisionedBits & capability) > 0) == isProvisioned) {
3669 return;
3670 }
3671 if (isProvisioned) {
3672 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3673 } else {
3674 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3675 }
3676 }
3677
3678 /**
3679 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3680 * technology. The bitfield should mirror the bitfield defined by
3681 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3682 */
3683 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3684 String key = getMmTelProvisioningKey(subId, tech);
3685 // Default is no capabilities are provisioned.
3686 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3687 }
3688
3689 /**
3690 * Sets the MmTel capability provisioning bitfield (defined by
3691 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3692 * technology specified.
3693 *
3694 * Note: This is a synchronous command and should not be called on UI thread.
3695 */
3696 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3697 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3698 String key = getMmTelProvisioningKey(subId, tech);
3699 editor.putInt(key, newField);
3700 editor.commit();
3701 }
3702
3703 private static String getMmTelProvisioningKey(int subId, int tech) {
3704 // resulting key is provision_ims_mmtel_{subId}_{tech}
3705 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3706 }
3707
3708 /**
3709 * Query CarrierConfig to see if the specified capability requires provisioning for the
3710 * carrier associated with the subscription id.
3711 */
3712 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3713 int capability) {
3714 CarrierConfigManager configManager = new CarrierConfigManager(context);
3715 PersistableBundle c = configManager.getConfigForSubId(subId);
3716 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003717 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003718 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3719 false);
3720 boolean requireVoiceVtProvisioning = c.getBoolean(
3721 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3722
3723 // First check to make sure that the capability requires provisioning.
3724 switch (capability) {
3725 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3726 // intentional fallthrough
3727 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3728 if (requireVoiceVtProvisioning) {
3729 // Voice and Video requires provisioning
3730 return true;
3731 }
3732 break;
3733 }
3734 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3735 if (requireUtProvisioning) {
3736 // UT requires provisioning
3737 return true;
3738 }
3739 break;
3740 }
3741 }
3742 return false;
3743 }
3744
allenwtsu99c623b2020-01-03 18:24:23 +08003745 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
3746 int capability) {
3747 CarrierConfigManager configManager = new CarrierConfigManager(context);
3748 PersistableBundle c = configManager.getConfigForSubId(subId);
3749
3750 boolean requireRcsProvisioning = c.getBoolean(
3751 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
3752
3753 // First check to make sure that the capability requires provisioning.
3754 switch (capability) {
3755 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3756 // intentional fallthrough
3757 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
3758 if (requireRcsProvisioning) {
3759 // OPTION or PRESENCE requires provisioning
3760 return true;
3761 }
3762 break;
3763 }
3764 }
3765 return false;
3766 }
3767
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003768 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003769 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003770 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3771 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3772 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003773 enforceReadPrivilegedPermission("getImsProvisioningInt");
3774 final long identity = Binder.clearCallingIdentity();
3775 try {
3776 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003777 int slotId = getSlotIndex(subId);
3778 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3779 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3780 + subId + "' for key:" + key);
3781 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3782 }
3783 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003784 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003785 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3786 + subId + "' for key:" + key);
3787 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003788 } finally {
3789 Binder.restoreCallingIdentity(identity);
3790 }
3791 }
3792
3793 @Override
3794 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003795 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3796 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3797 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003798 enforceReadPrivilegedPermission("getImsProvisioningString");
3799 final long identity = Binder.clearCallingIdentity();
3800 try {
3801 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003802 int slotId = getSlotIndex(subId);
3803 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3804 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3805 + subId + "' for key:" + key);
3806 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3807 }
3808 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003809 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003810 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3811 + subId + "' for key:" + key);
3812 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003813 } finally {
3814 Binder.restoreCallingIdentity(identity);
3815 }
3816 }
3817
3818 @Override
3819 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003820 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3821 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3822 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3824 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003825 final long identity = Binder.clearCallingIdentity();
3826 try {
3827 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003828 int slotId = getSlotIndex(subId);
3829 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3830 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3831 + subId + "' for key:" + key);
3832 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3833 }
3834 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003835 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003836 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3837 + "' for key:" + key);
3838 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003839 } finally {
3840 Binder.restoreCallingIdentity(identity);
3841 }
3842 }
3843
3844 @Override
3845 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003846 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3847 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3848 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003849 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3850 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003851 final long identity = Binder.clearCallingIdentity();
3852 try {
3853 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003854 int slotId = getSlotIndex(subId);
3855 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3856 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3857 + subId + "' for key:" + key);
3858 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3859 }
3860 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003861 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003862 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3863 + "' for key:" + key);
3864 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003865 } finally {
3866 Binder.restoreCallingIdentity(identity);
3867 }
3868 }
3869
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003870 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003871 int slotId = SubscriptionManager.getSlotIndex(subId);
3872 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003873 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3874 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003875 }
3876 return slotId;
3877 }
3878
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003879 private int getSlotIndex(int subId) {
3880 int slotId = SubscriptionManager.getSlotIndex(subId);
3881 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3882 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3883 }
3884 return slotId;
3885 }
3886
Wink Saville36469e72014-06-11 15:17:00 -07003887 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003888 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003889 */
3890 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003891 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3892 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003893 final int targetSdk = getTargetSdk(callingPackage);
3894 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003895 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003896 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003897 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003898 mApp, subId, callingPackage, callingFeatureId,
3899 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003900 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3901 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003902
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003903 final long identity = Binder.clearCallingIdentity();
3904 try {
3905 final Phone phone = getPhone(subId);
3906 if (phone != null) {
3907 return phone.getServiceState().getDataNetworkType();
3908 } else {
3909 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3910 }
3911 } finally {
3912 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003913 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003914 }
3915
3916 /**
3917 * Returns the data network type
3918 */
3919 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003920 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
3921 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
3922 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003923 }
3924
3925 /**
3926 * Returns the data network type for a subId
3927 */
3928 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003929 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
3930 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003931 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003932 mApp, subId, callingPackage, callingFeatureId,
3933 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003934 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3935 }
3936
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003937 final long identity = Binder.clearCallingIdentity();
3938 try {
3939 final Phone phone = getPhone(subId);
3940 if (phone != null) {
3941 return phone.getServiceState().getDataNetworkType();
3942 } else {
3943 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3944 }
3945 } finally {
3946 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003947 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003948 }
3949
3950 /**
Wink Saville36469e72014-06-11 15:17:00 -07003951 * Returns the Voice network type for a subId
3952 */
3953 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003954 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
3955 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003956 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003957 mApp, subId, callingPackage, callingFeatureId,
3958 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003959 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3960 }
3961
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003962 final long identity = Binder.clearCallingIdentity();
3963 try {
3964 final Phone phone = getPhone(subId);
3965 if (phone != null) {
3966 return phone.getServiceState().getVoiceNetworkType();
3967 } else {
3968 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3969 }
3970 } finally {
3971 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003972 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003973 }
3974
3975 /**
3976 * @return true if a ICC card is present
3977 */
3978 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003979 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003980 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3981 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003982 }
3983
3984 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003985 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003986 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003987 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003988 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003989 final long identity = Binder.clearCallingIdentity();
3990 try {
3991 final Phone phone = PhoneFactory.getPhone(slotIndex);
3992 if (phone != null) {
3993 return phone.getIccCard().hasIccCard();
3994 } else {
3995 return false;
3996 }
3997 } finally {
3998 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003999 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004000 }
4001
4002 /**
4003 * Return if the current radio is LTE on CDMA. This
4004 * is a tri-state return value as for a period of time
4005 * the mode may be unknown.
4006 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004007 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004008 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004009 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004010 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004011 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004012 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4013 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4014 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004015 }
4016
Sanket Padawe356d7632015-06-22 14:03:32 -07004017 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004018 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4019 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004020 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004021 mApp, subId, callingPackage, callingFeatureId,
4022 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004023 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4024 }
4025
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004026 final long identity = Binder.clearCallingIdentity();
4027 try {
4028 final Phone phone = getPhone(subId);
4029 if (phone == null) {
4030 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4031 } else {
4032 return phone.getLteOnCdmaMode();
4033 }
4034 } finally {
4035 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004036 }
Wink Saville36469e72014-06-11 15:17:00 -07004037 }
4038
Wink Saville36469e72014-06-11 15:17:00 -07004039 /**
4040 * {@hide}
4041 * Returns Default subId, 0 in the case of single standby.
4042 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004043 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004044 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004045 }
4046
Shishir Agrawala9f32182016-04-12 12:00:16 -07004047 private int getSlotForDefaultSubscription() {
4048 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4049 }
4050
Wink Savilleb564aae2014-10-23 10:18:09 -07004051 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004052 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004053 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004054
Pengquan Menge92a50d2018-09-21 15:54:48 -07004055 private boolean isActiveSubscription(int subId) {
4056 return mSubscriptionController.isActiveSubId(subId);
4057 }
4058
Ihab Awadf2177b72013-11-25 13:33:23 -08004059 /**
4060 * @see android.telephony.TelephonyManager.WifiCallingChoices
4061 */
4062 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004063 final long identity = Binder.clearCallingIdentity();
4064 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004065 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004066 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4067 getWhenToMakeWifiCallsDefaultPreference());
4068 } finally {
4069 Binder.restoreCallingIdentity(identity);
4070 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004071 }
4072
4073 /**
4074 * @see android.telephony.TelephonyManager.WifiCallingChoices
4075 */
4076 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004077 final long identity = Binder.clearCallingIdentity();
4078 try {
4079 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004080 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004081 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4082 } finally {
4083 Binder.restoreCallingIdentity(identity);
4084 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004085 }
4086
Sailesh Nepald1e68152013-12-12 19:08:02 -08004087 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004088 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004089 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004090 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004091
Jordan Liu4c733742019-02-28 12:03:40 -08004092 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4093 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4094 if (phoneId == -1) {
4095 throw new IllegalArgumentException("Given slot index: " + slotIndex
4096 + " does not correspond to an active phone");
4097 }
4098 return PhoneFactory.getPhone(phoneId);
4099 }
4100
Shishir Agrawal566b7612013-10-28 14:41:00 -07004101 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004102 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4103 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004104 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4105 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004106 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004107 if (DBG) {
4108 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4109 }
4110 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4111 p2);
4112 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004113
Jordan Liu4c733742019-02-28 12:03:40 -08004114
4115 @Override
4116 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4117 int slotIndex, String callingPackage, String aid, int p2) {
4118 enforceModifyPermission();
4119 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4120 if (DBG) {
4121 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4122 }
4123 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4124 callingPackage, aid, p2);
4125 }
4126
4127 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4128 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004129 final long identity = Binder.clearCallingIdentity();
4130 try {
4131 if (TextUtils.equals(ISDR_AID, aid)) {
4132 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004133 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4134 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004135 if (bestComponent == null
4136 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4137 loge("The calling package is not allowed to access ISD-R.");
4138 throw new SecurityException(
4139 "The calling package is not allowed to access ISD-R.");
4140 }
Derek Tan740e1672017-06-27 14:56:27 -07004141 }
Derek Tan740e1672017-06-27 14:56:27 -07004142
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004143 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004144 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4145 null /* workSource */);
4146 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004147 return response;
4148 } finally {
4149 Binder.restoreCallingIdentity(identity);
4150 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004151 }
4152
4153 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004154 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004155 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4156 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004157 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4158 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4159 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004160
Jordan Liu4c733742019-02-28 12:03:40 -08004161 @Override
4162 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4163 enforceModifyPermission();
4164 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4165 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4166 channel);
4167 }
4168
4169 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004170 final long identity = Binder.clearCallingIdentity();
4171 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004172 if (channel < 0) {
4173 return false;
4174 }
Jordan Liu4c733742019-02-28 12:03:40 -08004175 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4176 null /* workSource */);
4177 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004178 return success;
4179 } finally {
4180 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004181 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004182 }
4183
4184 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004185 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004186 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004187 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4188 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004189 if (DBG) {
4190 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4191 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4192 + p3 + " data=" + data);
4193 }
4194 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4195 command, p1, p2, p3, data);
4196 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004197
Jordan Liu4c733742019-02-28 12:03:40 -08004198 @Override
4199 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4200 int command, int p1, int p2, int p3, String data) {
4201 enforceModifyPermission();
4202 if (DBG) {
4203 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4204 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4205 + p3 + " data=" + data);
4206 }
4207 return iccTransmitApduLogicalChannelWithPermission(
4208 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4209 data);
4210 }
4211
4212 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4213 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004214 final long identity = Binder.clearCallingIdentity();
4215 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004216 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004217 return "";
4218 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004219
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004220 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004221 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4222 null /* workSource */);
4223 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004224
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004225 // Append the returned status code to the end of the response payload.
4226 String s = Integer.toHexString(
4227 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4228 if (response.payload != null) {
4229 s = IccUtils.bytesToHexString(response.payload) + s;
4230 }
4231 return s;
4232 } finally {
4233 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004234 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004235 }
Jake Hambye994d462014-02-03 13:10:13 -08004236
Evan Charltonc66da362014-05-16 14:06:40 -07004237 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004238 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4239 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004240 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4241 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004242 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004243 if (DBG) {
4244 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4245 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4246 }
4247 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4248 cla, command, p1, p2, p3, data);
4249 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004250
Jordan Liu4c733742019-02-28 12:03:40 -08004251 @Override
4252 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4253 int command, int p1, int p2, int p3, String data) {
4254 enforceModifyPermission();
4255 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4256 if (DBG) {
4257 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4258 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4259 + " data=" + data);
4260 }
4261
4262 return iccTransmitApduBasicChannelWithPermission(
4263 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4264 p2, p3, data);
4265 }
4266
4267 // open APDU basic channel assuming the caller has sufficient permissions
4268 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4269 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004270 final long identity = Binder.clearCallingIdentity();
4271 try {
4272 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4273 && TextUtils.equals(ISDR_AID, data)) {
4274 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004275 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4276 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004277 if (bestComponent == null
4278 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4279 loge("The calling package is not allowed to select ISD-R.");
4280 throw new SecurityException(
4281 "The calling package is not allowed to select ISD-R.");
4282 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004283 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004284
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004285 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004286 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4287 null /* workSource */);
4288 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004289
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004290 // Append the returned status code to the end of the response payload.
4291 String s = Integer.toHexString(
4292 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4293 if (response.payload != null) {
4294 s = IccUtils.bytesToHexString(response.payload) + s;
4295 }
4296 return s;
4297 } finally {
4298 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004299 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004300 }
4301
4302 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004303 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004304 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004305 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4306 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004307
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004308 final long identity = Binder.clearCallingIdentity();
4309 try {
4310 if (DBG) {
4311 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4312 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4313 }
4314
4315 IccIoResult response =
4316 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4317 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4318 subId);
4319
4320 if (DBG) {
4321 log("Exchange SIM_IO [R]" + response);
4322 }
4323
4324 byte[] result = null;
4325 int length = 2;
4326 if (response.payload != null) {
4327 length = 2 + response.payload.length;
4328 result = new byte[length];
4329 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4330 } else {
4331 result = new byte[length];
4332 }
4333
4334 result[length - 1] = (byte) response.sw2;
4335 result[length - 2] = (byte) response.sw1;
4336 return result;
4337 } finally {
4338 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004339 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004340 }
4341
Nathan Haroldb3014052017-01-25 15:57:32 -08004342 /**
4343 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4344 * on a particular subscription
4345 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004346 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4347 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004348 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004349 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004350 return null;
4351 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004352
4353 final long identity = Binder.clearCallingIdentity();
4354 try {
4355 if (appType != TelephonyManager.APPTYPE_USIM
4356 && appType != TelephonyManager.APPTYPE_SIM) {
4357 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4358 return null;
4359 }
4360 Object response = sendRequest(
4361 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4362 if (response instanceof String[]) {
4363 return (String[]) response;
4364 }
yincheng zhaod698b842019-09-06 17:06:54 -07004365 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004366 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004367 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004368 } finally {
4369 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004370 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004371 }
4372
yincheng zhaod698b842019-09-06 17:06:54 -07004373 /**
4374 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4375 * subscription.
4376 *
4377 * @param subId the id of the subscription.
4378 * @param appType the uicc app type, must be USIM or SIM.
4379 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4380 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004381 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004382 * @return number of fplmns that is successfully written to the SIM.
4383 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004384 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4385 String callingFeatureId) {
4386 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4387 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004388 if (DBG) logv("no permissions for setForbiddenplmns");
4389 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4390 }
4391 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4392 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4393 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4394 }
4395 if (fplmns == null) {
4396 throw new IllegalArgumentException("Fplmn List provided is null");
4397 }
4398 for (String fplmn : fplmns) {
4399 if (!CellIdentity.isValidPlmn(fplmn)) {
4400 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4401 }
4402 }
4403 final long identity = Binder.clearCallingIdentity();
4404 try {
4405 Object response = sendRequest(
4406 CMD_SET_FORBIDDEN_PLMNS,
4407 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4408 subId);
4409 return (int) response;
4410 } finally {
4411 Binder.restoreCallingIdentity(identity);
4412 }
4413 }
4414
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004415 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004416 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4418 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004419
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004420 final long identity = Binder.clearCallingIdentity();
4421 try {
4422 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4423 if (response.payload == null) {
4424 return "";
4425 }
Evan Charltonc66da362014-05-16 14:06:40 -07004426
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004427 // Append the returned status code to the end of the response payload.
4428 String s = Integer.toHexString(
4429 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4430 s = IccUtils.bytesToHexString(response.payload) + s;
4431 return s;
4432 } finally {
4433 Binder.restoreCallingIdentity(identity);
4434 }
Evan Charltonc66da362014-05-16 14:06:40 -07004435 }
4436
Jake Hambye994d462014-02-03 13:10:13 -08004437 /**
4438 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4439 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4440 *
4441 * @param itemID the ID of the item to read
4442 * @return the NV item as a String, or null on error.
4443 */
4444 @Override
4445 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004446 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004447 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4448 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004449
4450 final long identity = Binder.clearCallingIdentity();
4451 try {
4452 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004453 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004454 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4455 return value;
4456 } finally {
4457 Binder.restoreCallingIdentity(identity);
4458 }
Jake Hambye994d462014-02-03 13:10:13 -08004459 }
4460
4461 /**
4462 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4463 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4464 *
4465 * @param itemID the ID of the item to read
4466 * @param itemValue the value to write, as a String
4467 * @return true on success; false on any failure
4468 */
4469 @Override
4470 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004471 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004472 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4473 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004474
4475 final long identity = Binder.clearCallingIdentity();
4476 try {
4477 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4478 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004479 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004480 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4481 return success;
4482 } finally {
4483 Binder.restoreCallingIdentity(identity);
4484 }
Jake Hambye994d462014-02-03 13:10:13 -08004485 }
4486
4487 /**
4488 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4489 * Used for device configuration by some CDMA operators.
4490 *
4491 * @param preferredRoamingList byte array containing the new PRL
4492 * @return true on success; false on any failure
4493 */
4494 @Override
4495 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004496 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4497 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004498
4499 final long identity = Binder.clearCallingIdentity();
4500 try {
4501 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4502 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4503 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4504 return success;
4505 } finally {
4506 Binder.restoreCallingIdentity(identity);
4507 }
Jake Hambye994d462014-02-03 13:10:13 -08004508 }
4509
4510 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004511 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004512 * Used for device configuration by some CDMA operators.
4513 *
chen xu6dac5ab2018-10-26 17:39:23 -07004514 * @param slotIndex - device slot.
4515 *
Jake Hambye994d462014-02-03 13:10:13 -08004516 * @return true on success; false on any failure
4517 */
4518 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004519 public boolean resetModemConfig(int slotIndex) {
4520 Phone phone = PhoneFactory.getPhone(slotIndex);
4521 if (phone != null) {
4522 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4523 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004524
chen xu6dac5ab2018-10-26 17:39:23 -07004525 final long identity = Binder.clearCallingIdentity();
4526 try {
4527 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4528 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4529 return success;
4530 } finally {
4531 Binder.restoreCallingIdentity(identity);
4532 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004533 }
chen xu6dac5ab2018-10-26 17:39:23 -07004534 return false;
4535 }
4536
4537 /**
4538 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4539 *
4540 * @param slotIndex - device slot.
4541 *
4542 * @return true on success; false on any failure
4543 */
4544 @Override
4545 public boolean rebootModem(int slotIndex) {
4546 Phone phone = PhoneFactory.getPhone(slotIndex);
4547 if (phone != null) {
4548 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4549 mApp, phone.getSubId(), "rebootModem");
4550
4551 final long identity = Binder.clearCallingIdentity();
4552 try {
4553 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4554 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4555 return success;
4556 } finally {
4557 Binder.restoreCallingIdentity(identity);
4558 }
4559 }
4560 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004561 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004562
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004563 public String[] getPcscfAddress(String apnType, String callingPackage,
4564 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004565 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004566 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4567 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004568 return new String[0];
4569 }
4570
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004571 final long identity = Binder.clearCallingIdentity();
4572 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004573 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004574 } finally {
4575 Binder.restoreCallingIdentity(identity);
4576 }
Wink Saville36469e72014-06-11 15:17:00 -07004577 }
4578
Brad Ebinger51f743a2017-01-23 13:50:20 -08004579 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004580 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4581 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004582 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004583 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004584 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004585
4586 final long identity = Binder.clearCallingIdentity();
4587 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004588 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004589 // may happen if the device does not support IMS.
4590 return;
4591 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004592 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004593 } finally {
4594 Binder.restoreCallingIdentity(identity);
4595 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004596 }
4597
4598 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004599 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4600 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004601 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004602 public void disableIms(int slotId) {
4603 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004604
4605 final long identity = Binder.clearCallingIdentity();
4606 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004607 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004608 // may happen if the device does not support IMS.
4609 return;
4610 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004611 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004612 } finally {
4613 Binder.restoreCallingIdentity(identity);
4614 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004615 }
4616
4617 /**
4618 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4619 * feature or {@link null} if the service is not available. If the feature is available, the
4620 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4621 */
4622 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004623 IImsServiceFeatureCallback callback) {
4624 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004625
4626 final long identity = Binder.clearCallingIdentity();
4627 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004628 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004629 // may happen if the device does not support IMS.
4630 return null;
4631 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004632 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004633 } finally {
4634 Binder.restoreCallingIdentity(identity);
4635 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004636 }
4637
4638 /**
4639 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4640 * feature during emergency calling or {@link null} if the service is not available. If the
4641 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4642 * listener for feature updates.
4643 */
4644 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4645 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004646
4647 final long identity = Binder.clearCallingIdentity();
4648 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004649 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004650 // may happen if the device does not support IMS.
4651 return null;
4652 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004653 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004654 } finally {
4655 Binder.restoreCallingIdentity(identity);
4656 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004657 }
4658
Brad Ebinger5f64b052017-12-14 14:26:15 -08004659 /**
4660 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004661 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004662 */
4663 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4664 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004665
4666 final long identity = Binder.clearCallingIdentity();
4667 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004668 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004669 // may happen if the device does not support IMS.
4670 return null;
4671 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004672 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004673 } finally {
4674 Binder.restoreCallingIdentity(identity);
4675 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004676 }
4677
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004678 /**
4679 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004680 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004681 */
4682 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4683 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004684
4685 final long identity = Binder.clearCallingIdentity();
4686 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004687 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004688 // may happen if the device does not support IMS.
4689 return null;
4690 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004691 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004692 } finally {
4693 Binder.restoreCallingIdentity(identity);
4694 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004695 }
4696
Brad Ebinger884c07b2018-02-15 16:17:40 -08004697 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004698 * Sets the ImsService Package Name that Telephony will bind to.
4699 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08004700 * @param slotIndex the slot ID that the ImsService should bind for.
4701 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004702 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004703 * @param featureTypes An integer array of feature types associated with a packageName.
4704 * @param packageName The name of the package that the current configuration will be replaced
4705 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004706 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004707 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004708 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4709 int[] featureTypes, String packageName) {
4710 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4711 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4713 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08004714 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004715
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004716 final long identity = Binder.clearCallingIdentity();
4717 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004718 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004719 // may happen if the device does not support IMS.
4720 return false;
4721 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004722 Map<Integer, String> featureConfig = new HashMap<>();
4723 for (int featureType : featureTypes) {
4724 featureConfig.put(featureType, packageName);
4725 }
4726 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4727 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004728 } finally {
4729 Binder.restoreCallingIdentity(identity);
4730 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004731 }
4732
4733 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08004734 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004735 *
4736 * @param slotId The slot that the ImsService is associated with.
4737 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4738 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004739 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004740 * @return the package name of the ImsService configuration.
4741 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004742 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4743 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004744 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08004745 TelephonyPermissions
4746 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4747 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4748 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004749
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004750 final long identity = Binder.clearCallingIdentity();
4751 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004752 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004753 // may happen if the device does not support IMS.
4754 return "";
4755 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004756 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004757 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4758 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004759 } finally {
4760 Binder.restoreCallingIdentity(identity);
4761 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004762 }
4763
Brad Ebinger77b832e2019-10-17 17:03:22 -07004764 /**
4765 * Get the MmTelFeature state associated with the requested subscription id.
4766 * @param subId The subscription that the MmTelFeature is associated with.
4767 * @param callback A callback with an integer containing the
4768 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4769 */
4770 @Override
4771 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4772 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4773 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4774 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4775 "IMS not available on device.");
4776 }
4777 final long token = Binder.clearCallingIdentity();
4778 try {
4779 int slotId = getSlotIndex(subId);
4780 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4781 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4782 + subId + "'");
4783 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4784 }
4785 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4786 try {
4787 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4788 } catch (RemoteException e) {
4789 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4790 + "Ignore");
4791 }
4792 });
4793 } finally {
4794 Binder.restoreCallingIdentity(token);
4795 }
4796 }
4797
Wink Saville36469e72014-06-11 15:17:00 -07004798 public void setImsRegistrationState(boolean registered) {
4799 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004800
4801 final long identity = Binder.clearCallingIdentity();
4802 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004803 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004804 } finally {
4805 Binder.restoreCallingIdentity(identity);
4806 }
Wink Saville36469e72014-06-11 15:17:00 -07004807 }
4808
4809 /**
Stuart Scott54788802015-03-30 13:18:01 -07004810 * Set the network selection mode to automatic.
4811 *
4812 */
4813 @Override
4814 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004815 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4816 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004817
Pengquan Menge92a50d2018-09-21 15:54:48 -07004818 if (!isActiveSubscription(subId)) {
4819 return;
4820 }
4821
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004822 final long identity = Binder.clearCallingIdentity();
4823 try {
4824 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4825 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4826 } finally {
4827 Binder.restoreCallingIdentity(identity);
4828 }
Stuart Scott54788802015-03-30 13:18:01 -07004829 }
4830
Pengquan Mengea84e042018-09-20 14:57:26 -07004831 /**
4832 * Ask the radio to connect to the input network and change selection mode to manual.
4833 *
4834 * @param subId the id of the subscription.
4835 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4836 * the operator to attach to.
4837 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4838 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4839 * normal network selection next time.
4840 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004841 */
4842 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004843 public boolean setNetworkSelectionModeManual(
4844 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4846 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004847
4848 if (!isActiveSubscription(subId)) {
4849 return false;
4850 }
4851
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004852 final long identity = Binder.clearCallingIdentity();
4853 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004854 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004855 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004856 if (DBG) {
4857 log("setNetworkSelectionModeManual: subId: " + subId
4858 + " operator: " + operatorInfo);
4859 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004860 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4861 } finally {
4862 Binder.restoreCallingIdentity(identity);
4863 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004864 }
4865
4866 /**
4867 * Scans for available networks.
4868 */
4869 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004870 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4871 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4873 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004874 LocationAccessPolicy.LocationPermissionResult locationResult =
4875 LocationAccessPolicy.checkLocationPermission(mApp,
4876 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4877 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004878 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004879 .setCallingPid(Binder.getCallingPid())
4880 .setCallingUid(Binder.getCallingUid())
4881 .setMethod("getCellNetworkScanResults")
4882 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4883 .build());
4884 switch (locationResult) {
4885 case DENIED_HARD:
4886 throw new SecurityException("Not allowed to access scan results -- location");
4887 case DENIED_SOFT:
4888 return null;
4889 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004890
Pengquan Menga1bb6272018-09-06 09:59:22 -07004891 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004892 try {
4893 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004894 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004895 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004896 } finally {
4897 Binder.restoreCallingIdentity(identity);
4898 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004899 }
4900
4901 /**
yinxub1bed742017-04-17 11:45:04 -07004902 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004903 *
yinxub1bed742017-04-17 11:45:04 -07004904 * @param subId id of the subscription
4905 * @param request contains the radio access networks with bands/channels to scan
4906 * @param messenger callback messenger for scan results or errors
4907 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004908 * @return the id of the requested scan which can be used to stop the scan.
4909 */
4910 @Override
4911 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004912 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4914 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004915 LocationAccessPolicy.LocationPermissionResult locationResult =
4916 LocationAccessPolicy.checkLocationPermission(mApp,
4917 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4918 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004919 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004920 .setCallingPid(Binder.getCallingPid())
4921 .setCallingUid(Binder.getCallingUid())
4922 .setMethod("requestNetworkScan")
4923 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4924 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004925 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004926 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004927 if (e != null) {
4928 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4929 throw e;
4930 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004931 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004932 return TelephonyScanManager.INVALID_SCAN_ID;
4933 }
4934 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004935 }
Hall Liu912dfd32019-04-25 14:02:26 -07004936 int callingUid = Binder.getCallingUid();
4937 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004938 final long identity = Binder.clearCallingIdentity();
4939 try {
4940 return mNetworkScanRequestTracker.startNetworkScan(
4941 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004942 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004943 } finally {
4944 Binder.restoreCallingIdentity(identity);
4945 }
yinxu504e1392017-04-12 16:03:22 -07004946 }
4947
Hall Liub2ac8ef2019-02-28 15:56:23 -08004948 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004949 NetworkScanRequest request, int subId) {
4950 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4951 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4952 boolean hasNetworkScanPermission =
4953 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4954 == PERMISSION_GRANTED;
4955
4956 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4957 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4958 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004959 }
4960
4961 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4962 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004963 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4964 return new SecurityException("Specific channels must not be"
4965 + " scanned without location access.");
4966 }
4967 }
4968 }
4969
Hall Liub2ac8ef2019-02-28 15:56:23 -08004970 return null;
4971 }
4972
yinxu504e1392017-04-12 16:03:22 -07004973 /**
4974 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004975 *
4976 * @param subId id of the subscription
4977 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004978 */
4979 @Override
4980 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004981 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4982 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004983
Hall Liu912dfd32019-04-25 14:02:26 -07004984 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004985 final long identity = Binder.clearCallingIdentity();
4986 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004987 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004988 } finally {
4989 Binder.restoreCallingIdentity(identity);
4990 }
yinxu504e1392017-04-12 16:03:22 -07004991 }
4992
4993 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004994 * Get the calculated preferred network type.
4995 * Used for debugging incorrect network type.
4996 *
4997 * @return the preferred network type, defined in RILConstants.java.
4998 */
4999 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005000 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005001 final Phone defaultPhone = getDefaultPhone();
5002 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005003 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005004 return RILConstants.PREFERRED_NETWORK_MODE;
5005 }
5006
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005007 final long identity = Binder.clearCallingIdentity();
5008 try {
5009 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005010 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005011 } finally {
5012 Binder.restoreCallingIdentity(identity);
5013 }
Junda Liu84d15a22014-07-02 11:21:04 -07005014 }
5015
5016 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005017 * Get the preferred network type.
5018 * Used for device configuration by some CDMA operators.
5019 *
5020 * @return the preferred network type, defined in RILConstants.java.
5021 */
5022 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005023 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005024 TelephonyPermissions
5025 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5026 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005027
5028 final long identity = Binder.clearCallingIdentity();
5029 try {
5030 if (DBG) log("getPreferredNetworkType");
5031 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5032 int networkType = (result != null ? result[0] : -1);
5033 if (DBG) log("getPreferredNetworkType: " + networkType);
5034 return networkType;
5035 } finally {
5036 Binder.restoreCallingIdentity(identity);
5037 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005038 }
5039
5040 /**
5041 * Set the preferred network type.
5042 * Used for device configuration by some CDMA operators.
5043 *
5044 * @param networkType the preferred network type, defined in RILConstants.java.
5045 * @return true on success; false on any failure.
5046 */
5047 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005048 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5050 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005051
5052 final long identity = Binder.clearCallingIdentity();
5053 try {
5054 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
5055 Boolean success = (Boolean) sendRequest(
5056 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5057 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5058 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005059 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005060 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5061 }
5062 return success;
5063 } finally {
5064 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005065 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005066 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005067
5068 /**
Miaoa84611c2019-03-15 09:21:10 +08005069 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005070 *
Miaoa84611c2019-03-15 09:21:10 +08005071 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005072 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005073 * @hide
5074 */
5075 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005076 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005077 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005078 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005079 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005080 try {
Miaoa84611c2019-03-15 09:21:10 +08005081 if (phone != null) {
5082 return phone.hasMatchedTetherApnSetting();
5083 } else {
5084 return false;
5085 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005086 } finally {
5087 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005088 }
Junda Liu475951f2014-11-07 16:45:03 -08005089 }
5090
5091 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005092 * Set mobile data enabled
5093 * Used by the user through settings etc to turn on/off mobile data
5094 *
5095 * @param enable {@code true} turn turn data on, else {@code false}
5096 */
5097 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005098 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005099 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5100 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005101
5102 final long identity = Binder.clearCallingIdentity();
5103 try {
5104 int phoneId = mSubscriptionController.getPhoneId(subId);
5105 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5106 Phone phone = PhoneFactory.getPhone(phoneId);
5107 if (phone != null) {
5108 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005109 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005110 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005111 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005112 }
5113 } finally {
5114 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005115 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005116 }
5117
5118 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005119 * Get the user enabled state of Mobile Data.
5120 *
5121 * TODO: remove and use isUserDataEnabled.
5122 * This can't be removed now because some vendor codes
5123 * calls through ITelephony directly while they should
5124 * use TelephonyManager.
5125 *
5126 * @return true on enabled
5127 */
5128 @Override
5129 public boolean getDataEnabled(int subId) {
5130 return isUserDataEnabled(subId);
5131 }
5132
5133 /**
5134 * Get whether mobile data is enabled per user setting.
5135 *
5136 * There are other factors deciding whether mobile data is actually enabled, but they are
5137 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005138 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005139 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005140 *
5141 * @return {@code true} if data is enabled else {@code false}
5142 */
5143 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005144 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005145 try {
5146 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5147 null);
5148 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005149 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5150 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005151 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005152
5153 final long identity = Binder.clearCallingIdentity();
5154 try {
5155 int phoneId = mSubscriptionController.getPhoneId(subId);
5156 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5157 Phone phone = PhoneFactory.getPhone(phoneId);
5158 if (phone != null) {
5159 boolean retVal = phone.isUserDataEnabled();
5160 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5161 return retVal;
5162 } else {
5163 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5164 return false;
5165 }
5166 } finally {
5167 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005168 }
5169 }
5170
5171 /**
5172 * Get whether mobile data is enabled.
5173 *
5174 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5175 * whether mobile data is actually enabled.
5176 *
5177 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5178 *
5179 * @return {@code true} if data is enabled else {@code false}
5180 */
5181 @Override
5182 public boolean isDataEnabled(int subId) {
5183 try {
5184 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5185 null);
5186 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005187 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5188 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005189 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005190
5191 final long identity = Binder.clearCallingIdentity();
5192 try {
5193 int phoneId = mSubscriptionController.getPhoneId(subId);
5194 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5195 Phone phone = PhoneFactory.getPhone(phoneId);
5196 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005197 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005198 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5199 return retVal;
5200 } else {
5201 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5202 return false;
5203 }
5204 } finally {
5205 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005206 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005207 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005208
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005209 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5210 Phone phone) {
5211 //load access rules from carrier configs, and check those as well: b/139133814
5212 SubscriptionController subController = SubscriptionController.getInstance();
5213 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5214 || subController == null) return privilegeFromSim;
5215
5216 int uid = Binder.getCallingUid();
5217 PackageManager pkgMgr = phone.getContext().getPackageManager();
5218 String[] packages = pkgMgr.getPackagesForUid(uid);
5219
5220 final long identity = Binder.clearCallingIdentity();
5221 try {
5222 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5223 SubscriptionManager subManager = (SubscriptionManager)
5224 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5225 for (String pkg : packages) {
5226 if (subManager.canManageSubscription(subInfo, pkg)) {
5227 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5228 }
5229 }
5230 return privilegeFromSim;
5231 } finally {
5232 Binder.restoreCallingIdentity(identity);
5233 }
5234 }
5235
5236 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5237 String pkgName) {
5238 //load access rules from carrier configs, and check those as well: b/139133814
5239 SubscriptionController subController = SubscriptionController.getInstance();
5240 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5241 || subController == null) return privilegeFromSim;
5242
5243 final long identity = Binder.clearCallingIdentity();
5244 try {
5245 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5246 SubscriptionManager subManager = (SubscriptionManager)
5247 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5248 return subManager.canManageSubscription(subInfo, pkgName)
5249 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5250 } finally {
5251 Binder.restoreCallingIdentity(identity);
5252 }
5253 }
5254
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005255 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005256 public int getCarrierPrivilegeStatus(int subId) {
5257 final Phone phone = getPhone(subId);
5258 if (phone == null) {
5259 loge("getCarrierPrivilegeStatus: Invalid subId");
5260 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5261 }
5262 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005263 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005264 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005265 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5266 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005267
5268 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5269 card.getCarrierPrivilegeStatusForCurrentTransaction(
5270 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005271 }
Junda Liu29340342014-07-10 15:23:27 -07005272
5273 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005274 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5275 final Phone phone = getPhone(subId);
5276 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005277 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005278 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5279 }
5280 UiccProfile profile =
5281 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5282 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005283 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005284 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5285 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005286 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5287 profile.getCarrierPrivilegeStatusForUid(
5288 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005289 }
5290
5291 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005292 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5293 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005294 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005295 }
5296
5297 int phoneId = SubscriptionManager.getPhoneId(subId);
5298 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005299 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005300 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005301 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5302 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005303 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5304 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5305 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005306 }
5307
5308 @Override
5309 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005310 if (TextUtils.isEmpty(pkgName))
5311 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005312 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5313 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5314 UiccCard card = UiccController.getInstance().getUiccCard(i);
5315 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005316 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005317 continue;
5318 }
5319
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005320 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5321 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5322 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005323 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5324 break;
5325 }
5326 }
5327
5328 return result;
Junda Liu29340342014-07-10 15:23:27 -07005329 }
Derek Tan89e89d42014-07-08 17:00:10 -07005330
5331 @Override
Junda Liue64de782015-04-16 17:19:16 -07005332 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5333 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5334 loge("phoneId " + phoneId + " is not valid.");
5335 return null;
5336 }
5337 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005338 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005339 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005340 return null ;
5341 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005342 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005343 }
5344
Amith Yamasani6e118872016-02-19 12:53:51 -08005345 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005346 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005347 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005348 List<String> privilegedPackages = new ArrayList<>();
5349 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005350 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5351 // has UICC in that slot.
5352 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005353 if (card.hasCarrierPrivilegeRules()) {
5354 if (packages == null) {
5355 // Only check packages in user 0 for now
5356 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005357 PackageManager.MATCH_DISABLED_COMPONENTS
5358 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005359 | PackageManager.GET_SIGNING_CERTIFICATES,
5360 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005361 }
5362 for (int p = packages.size() - 1; p >= 0; p--) {
5363 PackageInfo pkgInfo = packages.get(p);
5364 if (pkgInfo != null && pkgInfo.packageName != null
5365 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005366 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005367 privilegedPackages.add(pkgInfo.packageName);
5368 }
5369 }
5370 }
5371 }
5372 return privilegedPackages;
5373 }
5374
chen xuf7e9fe82019-05-09 19:31:02 -07005375 @Override
5376 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005377 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5378
5379 final long identity = Binder.clearCallingIdentity();
5380
chen xuf7e9fe82019-05-09 19:31:02 -07005381 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005382 try {
5383 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5384 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5385 }
5386 } finally {
5387 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005388 }
5389 return privilegedPackages;
5390 }
5391
Wink Savilleb564aae2014-10-23 10:18:09 -07005392 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005393 final Phone phone = getPhone(subId);
5394 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005395 if (card == null) {
5396 loge("getIccId: No UICC");
5397 return null;
5398 }
5399 String iccId = card.getIccId();
5400 if (TextUtils.isEmpty(iccId)) {
5401 loge("getIccId: ICC ID is null or empty.");
5402 return null;
5403 }
5404 return iccId;
5405 }
5406
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005407 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005408 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5409 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005410 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5411 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005412
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005413 final long identity = Binder.clearCallingIdentity();
5414 try {
5415 final String iccId = getIccId(subId);
5416 final Phone phone = getPhone(subId);
5417 if (phone == null) {
5418 return false;
5419 }
5420 final String subscriberId = phone.getSubscriberId();
5421
5422 if (DBG_MERGE) {
5423 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5424 + subscriberId + " to " + number);
5425 }
5426
5427 if (TextUtils.isEmpty(iccId)) {
5428 return false;
5429 }
5430
5431 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5432
5433 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5434 if (alphaTag == null) {
5435 editor.remove(alphaTagPrefKey);
5436 } else {
5437 editor.putString(alphaTagPrefKey, alphaTag);
5438 }
5439
5440 // Record both the line number and IMSI for this ICCID, since we need to
5441 // track all merged IMSIs based on line number
5442 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5443 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5444 if (number == null) {
5445 editor.remove(numberPrefKey);
5446 editor.remove(subscriberPrefKey);
5447 } else {
5448 editor.putString(numberPrefKey, number);
5449 editor.putString(subscriberPrefKey, subscriberId);
5450 }
5451
5452 editor.commit();
5453 return true;
5454 } finally {
5455 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005456 }
Derek Tan7226c842014-07-02 17:42:23 -07005457 }
5458
5459 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005460 public String getLine1NumberForDisplay(int subId, String callingPackage,
5461 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005462 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005463 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005464 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005465 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005466 return null;
5467 }
Derek Tan97ebb422014-09-05 16:55:38 -07005468
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005469 final long identity = Binder.clearCallingIdentity();
5470 try {
5471 String iccId = getIccId(subId);
5472 if (iccId != null) {
5473 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5474 if (DBG_MERGE) {
5475 log("getLine1NumberForDisplay returning "
5476 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5477 }
5478 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005479 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005480 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5481 return null;
5482 } finally {
5483 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005484 }
Derek Tan7226c842014-07-02 17:42:23 -07005485 }
5486
5487 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005488 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5489 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005490 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005491 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005492 return null;
5493 }
Derek Tan97ebb422014-09-05 16:55:38 -07005494
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005495 final long identity = Binder.clearCallingIdentity();
5496 try {
5497 String iccId = getIccId(subId);
5498 if (iccId != null) {
5499 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5500 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5501 }
5502 return null;
5503 } finally {
5504 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005505 }
Derek Tan7226c842014-07-02 17:42:23 -07005506 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005507
5508 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005509 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5510 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005511 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5512 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005513 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005514 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005515 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005516 return null;
5517 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005518
Jordan Liub49b04b2019-05-06 14:45:15 -07005519 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5520 // the process, where TelephonyManager was instantiated.
5521 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005522 final long identity = Binder.clearCallingIdentity();
5523 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005524 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005525 final TelephonyManager tele = TelephonyManager.from(context);
5526 final SubscriptionManager sub = SubscriptionManager.from(context);
5527
5528 // Figure out what subscribers are currently active
5529 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005530
Jordan Liub49b04b2019-05-06 14:45:15 -07005531 // Only consider subs which match the current subId
5532 // This logic can be simplified. See b/131189269 for progress.
5533 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005534 activeSubscriberIds.add(tele.getSubscriberId(subId));
5535 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005536
5537 // First pass, find a number override for an active subscriber
5538 String mergeNumber = null;
5539 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5540 for (String key : prefs.keySet()) {
5541 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5542 final String subscriberId = (String) prefs.get(key);
5543 if (activeSubscriberIds.contains(subscriberId)) {
5544 final String iccId = key.substring(
5545 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5546 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5547 mergeNumber = (String) prefs.get(numberKey);
5548 if (DBG_MERGE) {
5549 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5550 + " for active subscriber " + subscriberId);
5551 }
5552 if (!TextUtils.isEmpty(mergeNumber)) {
5553 break;
5554 }
5555 }
5556 }
5557 }
5558
5559 // Shortcut when no active merged subscribers
5560 if (TextUtils.isEmpty(mergeNumber)) {
5561 return null;
5562 }
5563
5564 // Second pass, find all subscribers under that line override
5565 final ArraySet<String> result = new ArraySet<>();
5566 for (String key : prefs.keySet()) {
5567 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5568 final String number = (String) prefs.get(key);
5569 if (mergeNumber.equals(number)) {
5570 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5571 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5572 final String subscriberId = (String) prefs.get(subscriberKey);
5573 if (!TextUtils.isEmpty(subscriberId)) {
5574 result.add(subscriberId);
5575 }
5576 }
5577 }
5578 }
5579
5580 final String[] resultArray = result.toArray(new String[result.size()]);
5581 Arrays.sort(resultArray);
5582 if (DBG_MERGE) {
5583 Slog.d(LOG_TAG,
5584 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5585 }
5586 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005587 } finally {
5588 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005589 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005590 }
5591
5592 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005593 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5594 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5595
5596 final long identity = Binder.clearCallingIdentity();
5597 try {
5598 final TelephonyManager telephonyManager = mApp.getSystemService(
5599 TelephonyManager.class);
5600 String subscriberId = telephonyManager.getSubscriberId(subId);
5601 if (subscriberId == null) {
5602 if (DBG) {
5603 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5604 + subId);
5605 }
5606 return null;
5607 }
5608
5609 final SubscriptionInfo info = SubscriptionController.getInstance()
5610 .getSubscriptionInfo(subId);
5611 final ParcelUuid groupUuid = info.getGroupUuid();
5612 // If it doesn't belong to any group, return just subscriberId of itself.
5613 if (groupUuid == null) {
5614 return new String[]{subscriberId};
5615 }
5616
5617 // Get all subscriberIds from the group.
5618 final List<String> mergedSubscriberIds = new ArrayList<>();
5619 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005620 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5621 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07005622 for (SubscriptionInfo subInfo : groupInfos) {
5623 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5624 if (subscriberId != null) {
5625 mergedSubscriberIds.add(subscriberId);
5626 }
5627 }
5628
5629 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5630 } finally {
5631 Binder.restoreCallingIdentity(identity);
5632
5633 }
5634 }
5635
5636 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005637 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005638 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5639 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005640
5641 final long identity = Binder.clearCallingIdentity();
5642 try {
5643 final Phone phone = getPhone(subId);
5644 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5645 } finally {
5646 Binder.restoreCallingIdentity(identity);
5647 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005648 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005649
5650 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005651 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005652 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5653 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005654 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005655
5656 final long identity = Binder.clearCallingIdentity();
5657 try {
5658 final Phone phone = getPhone(subId);
5659 if (phone == null) {
5660 return false;
5661 }
5662 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5663 cdmaNonRoamingList);
5664 } finally {
5665 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005666 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005667 }
5668
5669 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005670 @Deprecated
5671 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5672 enforceModifyPermission();
5673
5674 int returnValue = 0;
5675 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005676 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005677 if(result.exception == null) {
5678 if (result.result != null) {
5679 byte[] responseData = (byte[])(result.result);
5680 if(responseData.length > oemResp.length) {
5681 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5682 responseData.length + "bytes. Buffer Size is " +
5683 oemResp.length + "bytes.");
5684 }
5685 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5686 returnValue = responseData.length;
5687 }
5688 } else {
5689 CommandException ex = (CommandException) result.exception;
5690 returnValue = ex.getCommandError().ordinal();
5691 if(returnValue > 0) returnValue *= -1;
5692 }
5693 } catch (RuntimeException e) {
5694 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5695 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5696 if(returnValue > 0) returnValue *= -1;
5697 }
5698
5699 return returnValue;
5700 }
5701
5702 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005703 public void setRadioCapability(RadioAccessFamily[] rafs) {
5704 try {
5705 ProxyController.getInstance().setRadioCapability(rafs);
5706 } catch (RuntimeException e) {
5707 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5708 }
5709 }
5710
5711 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005712 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005713 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005714 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005715 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005716 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005717 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005718 final long identity = Binder.clearCallingIdentity();
5719 try {
chen xub97461a2018-10-26 14:17:57 -07005720 TelephonyPermissions
5721 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5722 mApp, phone.getSubId(), "getRadioAccessFamily");
5723 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005724 } finally {
5725 Binder.restoreCallingIdentity(identity);
5726 }
chen xub97461a2018-10-26 14:17:57 -07005727 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005728 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005729
5730 @Override
5731 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005732 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005733 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005734
5735 final long identity = Binder.clearCallingIdentity();
5736 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005737 ImsManager.getInstance(defaultPhone.getContext(),
5738 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005739 } finally {
5740 Binder.restoreCallingIdentity(identity);
5741 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005742 }
5743
5744 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005745 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005746 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005747 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5748 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005749 return false;
5750 }
Svet Ganovb320e182015-04-16 12:30:10 -07005751
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005752 final long identity = Binder.clearCallingIdentity();
5753 try {
5754 // Check the user preference and the system-level IMS setting. Even if the user has
5755 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5756 // In the long run, we may instead need to check if there exists a connection service
5757 // which can support video calling.
5758 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005759 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005760 return imsManager.isVtEnabledByPlatform()
5761 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5762 && imsManager.isVtEnabledByUser();
5763 } finally {
5764 Binder.restoreCallingIdentity(identity);
5765 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005766 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005767
Andrew Leea1239f22015-03-02 17:44:07 -08005768 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005769 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5770 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005771 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005772 mApp, subId, callingPackage, callingFeatureId,
5773 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005774 return false;
5775 }
5776
5777 final long identity = Binder.clearCallingIdentity();
5778 try {
5779 CarrierConfigManager configManager =
5780 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005781 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005782 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5783 } finally {
5784 Binder.restoreCallingIdentity(identity);
5785 }
Andrew Leea1239f22015-03-02 17:44:07 -08005786 }
5787
5788 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005789 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005790 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005791 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005792 return false;
5793 }
5794
5795 final long identity = Binder.clearCallingIdentity();
5796 try {
5797 CarrierConfigManager configManager =
5798 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005799 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005800 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5801 } finally {
5802 Binder.restoreCallingIdentity(identity);
5803 }
Andrew Leea1239f22015-03-02 17:44:07 -08005804 }
5805
Andrew Lee9431b832015-03-09 18:46:45 -07005806 @Override
5807 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07005808 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005809 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005810 }
5811
5812 @Override
5813 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005814 final long identity = Binder.clearCallingIdentity();
5815 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005816 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005817 } finally {
5818 Binder.restoreCallingIdentity(identity);
5819 }
Andrew Lee9431b832015-03-09 18:46:45 -07005820 }
5821
Hall Liuf6668912018-10-31 17:05:23 -07005822 /**
5823 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5824 * support for the feature and device firmware support.
5825 *
5826 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5827 */
5828 @Override
5829 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005830 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005831 final Phone phone = getPhone(subscriptionId);
5832 if (phone == null) {
5833 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5834 return false;
5835 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005836 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005837 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005838 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5839 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005840 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005841 return isCarrierSupported && isDeviceSupported;
5842 } finally {
5843 Binder.restoreCallingIdentity(identity);
5844 }
Hall Liu98187582018-01-22 19:15:32 -08005845 }
5846
Hall Liuf6668912018-10-31 17:05:23 -07005847 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005848 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5849 * RTT setting, will return true if the device and carrier both support RTT.
5850 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005851 */
5852 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005853 final long identity = Binder.clearCallingIdentity();
5854 try {
Hall Liu81eb08c2019-10-29 16:50:20 -07005855 return isRttSupported(subscriptionId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005856 } finally {
5857 Binder.restoreCallingIdentity(identity);
5858 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005859 }
5860
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005861 @Deprecated
5862 @Override
5863 public String getDeviceId(String callingPackage) {
5864 return getDeviceIdWithFeature(callingPackage, null);
5865 }
5866
Sanket Padawe7310cc72015-01-14 09:53:20 -08005867 /**
5868 * Returns the unique device ID of phone, for example, the IMEI for
5869 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5870 *
5871 * <p>Requires Permission:
5872 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5873 */
5874 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005875 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005876 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005877 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005878 return null;
5879 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005880 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005881 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005882 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005883 return null;
5884 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005885
5886 final long identity = Binder.clearCallingIdentity();
5887 try {
5888 return phone.getDeviceId();
5889 } finally {
5890 Binder.restoreCallingIdentity(identity);
5891 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005892 }
5893
Ping Sunc67b7c22016-03-02 19:16:45 +08005894 /**
5895 * {@hide}
5896 * Returns the IMS Registration Status on a particular subid
5897 *
5898 * @param subId
5899 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005900 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005901 Phone phone = getPhone(subId);
5902 if (phone != null) {
5903 return phone.isImsRegistered();
5904 } else {
5905 return false;
5906 }
5907 }
5908
Santos Cordon7a1885b2015-02-03 11:15:19 -08005909 @Override
5910 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005911 final long identity = Binder.clearCallingIdentity();
5912 try {
5913 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5914 } finally {
5915 Binder.restoreCallingIdentity(identity);
5916 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005917 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005918
Tyler Gunnf70ed162019-04-03 15:28:53 -07005919 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07005920 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005921 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07005922 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005923 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07005924 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5925 }
5926 final long identity = Binder.clearCallingIdentity();
5927 try {
5928 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5929 } finally {
5930 Binder.restoreCallingIdentity(identity);
5931 }
5932 }
5933
5934 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005935 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5936 final long identity = Binder.clearCallingIdentity();
5937 try {
5938 Phone phone = getPhone(subscriptionId);
5939 if (phone == null) {
5940 return null;
5941 }
5942 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5943 } finally {
5944 Binder.restoreCallingIdentity(identity);
5945 }
5946 }
5947
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005948 /**
5949 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005950 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005951 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005952 final long identity = Binder.clearCallingIdentity();
5953 try {
5954 Phone phone = getPhone(subId);
5955 if (phone != null) {
5956 return phone.isWifiCallingEnabled();
5957 } else {
5958 return false;
5959 }
5960 } finally {
5961 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005962 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005963 }
5964
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005965 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005966 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005967 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005968 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005969 final long identity = Binder.clearCallingIdentity();
5970 try {
5971 Phone phone = getPhone(subId);
5972 if (phone != null) {
5973 return phone.isVideoEnabled();
5974 } else {
5975 return false;
5976 }
5977 } finally {
5978 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005979 }
5980 }
5981
5982 /**
5983 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5984 * defined in {@link ImsRegistrationImplBase}.
5985 */
5986 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005987 final long identity = Binder.clearCallingIdentity();
5988 try {
5989 Phone phone = getPhone(subId);
5990 if (phone != null) {
5991 return phone.getImsRegistrationTech();
5992 } else {
5993 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5994 }
5995 } finally {
5996 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005997 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005998 }
5999
Stuart Scott8eef64f2015-04-08 15:13:54 -07006000 @Override
6001 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006002 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006003 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6004 return;
6005 }
6006
Svet Ganovcc087f82015-05-12 20:35:54 -07006007 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006008
Svet Ganovcc087f82015-05-12 20:35:54 -07006009 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006010 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6011 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006012 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006013 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006014 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006015 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6016 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006017 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006018 // There has been issues when Sms raw table somehow stores orphan
6019 // fragments. They lead to garbled message when new fragments come
6020 // in and combined with those stale ones. In case this happens again,
6021 // user can reset all network settings which will clean up this table.
6022 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006023 // Clean up IMS settings as well here.
6024 int slotId = getSlotIndex(subId);
6025 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6026 ImsManager.getInstance(mApp, slotId).factoryReset();
6027 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006028
6029 // Erase modem config if erase modem on network setting is enabled.
6030 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6031 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6032 if (configValue != null && Boolean.parseBoolean(configValue)) {
6033 sendEraseModemConfig(getDefaultPhone());
6034 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006035 } finally {
6036 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006037 }
6038 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006039
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006040 private void cleanUpSmsRawTable(Context context) {
6041 ContentResolver resolver = context.getContentResolver();
6042 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6043 resolver.delete(uri, null, null);
6044 }
6045
Narayan Kamath1c496c22015-04-16 14:40:19 +01006046 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006047 public String getSimLocaleForSubscriber(int subId) {
6048 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6049 final Phone phone = getPhone(subId);
6050 if (phone == null) {
6051 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006052 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006053 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006054 final long identity = Binder.clearCallingIdentity();
6055 try {
chen xu5d3637b2019-01-21 23:31:38 -08006056 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006057 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08006058 if (info == null) {
6059 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6060 return null;
6061 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006062 // Try and fetch the locale from the carrier properties or from the SIM language
6063 // preferences (EF-PL and EF-LI)...
6064 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006065 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006066 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6067 if (localeFromDefaultSim != null) {
6068 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6069 if (DBG) log("Using locale from subId: " + subId + " locale: "
6070 + localeFromDefaultSim);
6071 return localeFromDefaultSim.toLanguageTag();
6072 } else {
6073 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006074 }
6075 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006076
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006077 // The SIM language preferences only store a language (e.g. fr = French), not an
6078 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6079 // the SIM and carrier preferences does not include a country we add the country
6080 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006081 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006082 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006083 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006084 return mccLocale.toLanguageTag();
6085 }
6086
6087 if (DBG) log("No locale found - returning null");
6088 return null;
6089 } finally {
6090 Binder.restoreCallingIdentity(identity);
6091 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006092 }
6093
6094 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006095 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6096 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006097 }
6098
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006099 /**
6100 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6101 */
6102 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006103 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6104 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006105 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006106
Chenjie Yu1ba97252018-01-11 18:16:20 -08006107 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006108 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006109
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006110 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006111 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6112 * representing the state of the modem.
6113 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006114 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6115 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006116 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006117 */
6118 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006119 public void requestModemActivityInfo(ResultReceiver result) {
6120 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006121 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006122
6123 final long identity = Binder.clearCallingIdentity();
6124 try {
6125 ModemActivityInfo ret = null;
6126 synchronized (mLastModemActivityInfo) {
6127 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6128 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006129 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006130 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006131 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xu13851032019-09-10 18:49:52 -07006132 int[] txTimeMs = info.getTransmitTimeMillis();
6133 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006134 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xu13851032019-09-10 18:49:52 -07006135 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006136 }
6137 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006138 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6139 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006140 mLastModemActivityInfo.setIdleTimeMillis(
6141 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xu13851032019-09-10 18:49:52 -07006142 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6143 mLastModemActivityInfo.setReceiveTimeMillis(
6144 info.getReceiveTimeMillis() + mLastModemActivityInfo
6145 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006146 }
Chen Xu13851032019-09-10 18:49:52 -07006147
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006148 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6149 mLastModemActivityInfo.getSleepTimeMillis(),
6150 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xu13851032019-09-10 18:49:52 -07006151 mLastModemActivityInfo.getTransmitTimeMillis(),
6152 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006153 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006154 Bundle bundle = new Bundle();
6155 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6156 result.send(0, bundle);
6157 } finally {
6158 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006159 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006160 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006161
Siddharth Rayb8114062018-06-17 15:02:38 -07006162 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6163 // less than total activity duration.
6164 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6165 if (info == null) {
6166 return false;
6167 }
6168 int activityDurationMs =
6169 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6170 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006171 int[] txTimeMs = info.getTransmitTimeMillis();
6172 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6173 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006174 }
6175 return (info.isValid()
6176 && (info.getSleepTimeMillis() <= activityDurationMs)
6177 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006178 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006179 && (totalTxTimeMs <= activityDurationMs));
6180 }
6181
Jack Yu85bd38a2015-11-09 11:34:32 -08006182 /**
6183 * {@hide}
6184 * Returns the service state information on specified subscription.
6185 */
6186 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006187 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6188 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006189 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006190 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006191 return null;
6192 }
6193
Hall Liuf19c44f2018-11-27 14:38:17 -08006194 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6195 LocationAccessPolicy.checkLocationPermission(mApp,
6196 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6197 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006198 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006199 .setCallingPid(Binder.getCallingPid())
6200 .setCallingUid(Binder.getCallingUid())
6201 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006202 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006203 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6204 .build());
6205
6206 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6207 LocationAccessPolicy.checkLocationPermission(mApp,
6208 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6209 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006210 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006211 .setCallingPid(Binder.getCallingPid())
6212 .setCallingUid(Binder.getCallingUid())
6213 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006214 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006215 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6216 .build());
6217 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6218 boolean hasFinePermission =
6219 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6220 boolean hasCoarsePermission =
6221 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6222
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006223 final long identity = Binder.clearCallingIdentity();
6224 try {
6225 final Phone phone = getPhone(subId);
6226 if (phone == null) {
6227 return null;
6228 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006229
Hall Liuf19c44f2018-11-27 14:38:17 -08006230 ServiceState ss = phone.getServiceState();
6231
6232 // Scrub out the location info in ServiceState depending on what level of access
6233 // the caller has.
6234 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006235 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6236 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006237 } finally {
6238 Binder.restoreCallingIdentity(identity);
6239 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006240 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006241
6242 /**
6243 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6244 *
6245 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6246 * voicemail ringtone.
6247 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6248 * PhoneAccount.
6249 */
6250 @Override
6251 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006252 final long identity = Binder.clearCallingIdentity();
6253 try {
6254 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6255 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006256 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006257 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006258
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006259 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6260 } finally {
6261 Binder.restoreCallingIdentity(identity);
6262 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006263 }
6264
6265 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006266 * Sets the per-account voicemail ringtone.
6267 *
6268 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6269 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6270 *
6271 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6272 * voicemail ringtone.
6273 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6274 * PhoneAccount.
6275 */
6276 @Override
6277 public void setVoicemailRingtoneUri(String callingPackage,
6278 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006279 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006280 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006281 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6282 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006283 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6284 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6285 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006286 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006287
6288 final long identity = Binder.clearCallingIdentity();
6289 try {
6290 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6291 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006292 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006293 }
6294 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6295 } finally {
6296 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006297 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006298 }
6299
6300 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006301 * Returns whether vibration is set for voicemail notification in Phone settings.
6302 *
6303 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6304 * voicemail vibration setting.
6305 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6306 */
6307 @Override
6308 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006309 final long identity = Binder.clearCallingIdentity();
6310 try {
6311 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6312 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006313 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006314 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006315
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006316 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6317 } finally {
6318 Binder.restoreCallingIdentity(identity);
6319 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006320 }
6321
Youhan Wange64578a2016-05-02 15:32:42 -07006322 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006323 * Sets the per-account voicemail vibration.
6324 *
6325 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6326 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6327 *
6328 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6329 * voicemail vibration setting.
6330 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6331 * specific PhoneAccount.
6332 */
6333 @Override
6334 public void setVoicemailVibrationEnabled(String callingPackage,
6335 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006336 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006337 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006338 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6339 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6341 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6342 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006343 }
6344
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006345 final long identity = Binder.clearCallingIdentity();
6346 try {
6347 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6348 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006349 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006350 }
6351 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6352 } finally {
6353 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006354 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006355 }
6356
6357 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006358 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6359 *
6360 * @throws SecurityException if the caller does not have the required permission
6361 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006362 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006363 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006364 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006365 }
6366
6367 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006368 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6369 * permission.
6370 *
6371 * @throws SecurityException if the caller does not have the required permission
6372 */
6373 private void enforceSendSmsPermission() {
6374 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6375 }
6376
6377 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006378 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006379 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006380 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006381 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006382 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006383 final long identity = Binder.clearCallingIdentity();
6384 try {
6385 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006386 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006387 if (componentName == null) {
6388 throw new SecurityException(
6389 "Caller not current active visual voicemail package[null]");
6390 }
6391 String vvmPackage = componentName.getPackageName();
6392 if (!callingPackage.equals(vvmPackage)) {
6393 throw new SecurityException("Caller not current active visual voicemail package["
6394 + vvmPackage + "]");
6395 }
6396 } finally {
6397 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006398 }
6399 }
6400
6401 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006402 * Return the application ID for the app type.
6403 *
6404 * @param subId the subscription ID that this request applies to.
6405 * @param appType the uicc app type.
6406 * @return Application ID for specificied app type, or null if no uicc.
6407 */
6408 @Override
6409 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006410 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006411 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006412
6413 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006414 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006415 if (phone == null) {
6416 return null;
6417 }
6418 String aid = null;
6419 try {
6420 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6421 .getApplicationByType(appType).getAid();
6422 } catch (Exception e) {
6423 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6424 }
6425 return aid;
6426 } finally {
6427 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006428 }
Youhan Wange64578a2016-05-02 15:32:42 -07006429 }
6430
Youhan Wang4001d252016-05-11 10:29:41 -07006431 /**
6432 * Return the Electronic Serial Number.
6433 *
6434 * @param subId the subscription ID that this request applies to.
6435 * @return ESN or null if error.
6436 */
6437 @Override
6438 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006439 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006440 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006441
6442 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006443 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006444 if (phone == null) {
6445 return null;
6446 }
6447 String esn = null;
6448 try {
6449 esn = phone.getEsn();
6450 } catch (Exception e) {
6451 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6452 }
6453 return esn;
6454 } finally {
6455 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006456 }
Youhan Wang4001d252016-05-11 10:29:41 -07006457 }
6458
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006459 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006460 * Return the Preferred Roaming List Version.
6461 *
6462 * @param subId the subscription ID that this request applies to.
6463 * @return PRLVersion or null if error.
6464 */
6465 @Override
6466 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006467 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006468 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006469
6470 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006471 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006472 if (phone == null) {
6473 return null;
6474 }
6475 String cdmaPrlVersion = null;
6476 try {
6477 cdmaPrlVersion = phone.getCdmaPrlVersion();
6478 } catch (Exception e) {
6479 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6480 }
6481 return cdmaPrlVersion;
6482 } finally {
6483 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006484 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006485 }
6486
6487 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006488 * Get snapshot of Telephony histograms
6489 * @return List of Telephony histograms
6490 * @hide
6491 */
6492 @Override
6493 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006494 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6495 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006496
6497 final long identity = Binder.clearCallingIdentity();
6498 try {
6499 return RIL.getTelephonyRILTimingHistograms();
6500 } finally {
6501 Binder.restoreCallingIdentity(identity);
6502 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006503 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006504
6505 /**
6506 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006507 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6508 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006509 * Require system privileges. In the future we may add this to carrier APIs.
6510 *
Michele Berionne482f8202018-11-27 18:57:59 -08006511 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006512 */
6513 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006514 @TelephonyManager.SetCarrierRestrictionResult
6515 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006516 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006517 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006518
Michele Berionne482f8202018-11-27 18:57:59 -08006519 if (carrierRestrictionRules == null) {
6520 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006521 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006522
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006523 final long identity = Binder.clearCallingIdentity();
6524 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006525 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006526 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006527 } finally {
6528 Binder.restoreCallingIdentity(identity);
6529 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006530 }
6531
6532 /**
6533 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006534 * Get the allowed carrier list and the excluded carrier list, including the priority between
6535 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006536 * Require system privileges. In the future we may add this to carrier APIs.
6537 *
Michele Berionne482f8202018-11-27 18:57:59 -08006538 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006539 */
6540 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006541 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006542 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006543 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006544
6545 final long identity = Binder.clearCallingIdentity();
6546 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006547 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6548 if (response instanceof CarrierRestrictionRules) {
6549 return (CarrierRestrictionRules) response;
6550 }
6551 // Response is an Exception of some kind,
6552 // which is signalled to the user as a NULL retval
6553 return null;
6554 } catch (Exception e) {
6555 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6556 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006557 } finally {
6558 Binder.restoreCallingIdentity(identity);
6559 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006560 }
6561
fionaxu59545b42016-05-25 15:53:37 -07006562 /**
6563 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6564 * @param subId the subscription ID that this action applies to.
6565 * @param enabled control enable or disable metered apns.
6566 * {@hide}
6567 */
6568 @Override
6569 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6570 enforceModifyPermission();
6571 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006572
6573 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006574 if (phone == null) {
6575 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6576 return;
6577 }
6578 try {
6579 phone.carrierActionSetMeteredApnsEnabled(enabled);
6580 } catch (Exception e) {
6581 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006582 } finally {
6583 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006584 }
6585 }
6586
6587 /**
6588 * Action set from carrier signalling broadcast receivers to enable/disable radio
6589 * @param subId the subscription ID that this action applies to.
6590 * @param enabled control enable or disable radio.
6591 * {@hide}
6592 */
6593 @Override
6594 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6595 enforceModifyPermission();
6596 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006597
6598 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006599 if (phone == null) {
6600 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6601 return;
6602 }
6603 try {
6604 phone.carrierActionSetRadioEnabled(enabled);
6605 } catch (Exception e) {
6606 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006607 } finally {
6608 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006609 }
6610 }
6611
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006612 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006613 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6614 * network status based on which carrier apps could apply actions accordingly,
6615 * enable/disable default url handler for example.
6616 *
6617 * @param subId the subscription ID that this action applies to.
6618 * @param report control start/stop reporting the default network status.
6619 * {@hide}
6620 */
6621 @Override
6622 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6623 enforceModifyPermission();
6624 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006625
6626 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006627 if (phone == null) {
6628 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6629 return;
6630 }
6631 try {
6632 phone.carrierActionReportDefaultNetworkStatus(report);
6633 } catch (Exception e) {
6634 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006635 } finally {
6636 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006637 }
6638 }
6639
6640 /**
fionaxud9622282017-07-17 17:51:30 -07006641 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6642 * @param subId the subscription ID that this action applies to.
6643 * {@hide}
6644 */
6645 @Override
6646 public void carrierActionResetAll(int subId) {
6647 enforceModifyPermission();
6648 final Phone phone = getPhone(subId);
6649 if (phone == null) {
6650 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6651 return;
6652 }
6653 try {
6654 phone.carrierActionResetAll();
6655 } catch (Exception e) {
6656 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6657 }
6658 }
6659
6660 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006661 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6662 * bug report is being generated.
6663 */
6664 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006665 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006666 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6667 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006668 writer.println("Permission Denial: can't dump Phone from pid="
6669 + Binder.getCallingPid()
6670 + ", uid=" + Binder.getCallingUid()
6671 + "without permission "
6672 + android.Manifest.permission.DUMP);
6673 return;
6674 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006675 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006676 }
Jack Yueb89b242016-06-22 13:27:47 -07006677
Brad Ebingerdac2f002018-04-03 15:17:52 -07006678 @Override
6679 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6680 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6681 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006682 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6683 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006684 }
6685
Jack Yueb89b242016-06-22 13:27:47 -07006686 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006687 * Get aggregated video call data usage since boot.
6688 *
6689 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6690 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006691 * {@hide}
6692 */
6693 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006694 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006695 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6696 null);
6697
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006698 final long identity = Binder.clearCallingIdentity();
6699 try {
6700 // NetworkStatsService keeps tracking the active network interface and identity. It
6701 // records the delta with the corresponding network identity.
6702 // We just return the total video call data usage snapshot since boot.
6703 Phone phone = getPhone(subId);
6704 if (phone != null) {
6705 return phone.getVtDataUsage(perUidStats);
6706 }
6707 return null;
6708 } finally {
6709 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006710 }
Jack Yueb89b242016-06-22 13:27:47 -07006711 }
Jack Yu75ab2952016-07-08 14:29:33 -07006712
6713 /**
6714 * Policy control of data connection. Usually used when data limit is passed.
6715 * @param enabled True if enabling the data, otherwise disabling.
6716 * @param subId Subscription index
6717 * {@hide}
6718 */
6719 @Override
6720 public void setPolicyDataEnabled(boolean enabled, int subId) {
6721 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006722
6723 final long identity = Binder.clearCallingIdentity();
6724 try {
6725 Phone phone = getPhone(subId);
6726 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006727 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006728 }
6729 } finally {
6730 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006731 }
6732 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006733
6734 /**
6735 * Get Client request stats
6736 * @return List of Client Request Stats
6737 * @hide
6738 */
6739 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006740 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6741 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006742 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006743 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006744 return null;
6745 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006746 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006747
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006748 final long identity = Binder.clearCallingIdentity();
6749 try {
6750 if (phone != null) {
6751 return phone.getClientRequestStats();
6752 }
6753
6754 return null;
6755 } finally {
6756 Binder.restoreCallingIdentity(identity);
6757 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006758 }
6759
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006760 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006761 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006762 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006763 }
Jack Yueb4124c2017-02-16 15:32:43 -08006764
6765 /**
Grace Chen70990072017-03-24 17:21:30 -07006766 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006767 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006768 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006769 * @param state State of SIM (power down, power up, pass through)
6770 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6771 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6772 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006773 *
6774 **/
6775 @Override
Grace Chen70990072017-03-24 17:21:30 -07006776 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006777 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006778 Phone phone = PhoneFactory.getPhone(slotIndex);
6779
vagdeviaf9a5b92018-08-15 16:01:53 -07006780 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6781
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006782 final long identity = Binder.clearCallingIdentity();
6783 try {
6784 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006785 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006786 }
6787 } finally {
6788 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006789 }
6790 }
Shuo Qiandd210312017-04-12 22:11:33 +00006791
Tyler Gunn65d45c22017-06-05 11:22:26 -07006792 private boolean isUssdApiAllowed(int subId) {
6793 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006794 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006795 if (configManager == null) {
6796 return false;
6797 }
6798 PersistableBundle pb = configManager.getConfigForSubId(subId);
6799 if (pb == null) {
6800 return false;
6801 }
6802 return pb.getBoolean(
6803 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6804 }
6805
Shuo Qiandd210312017-04-12 22:11:33 +00006806 /**
6807 * Check if phone is in emergency callback mode
6808 * @return true if phone is in emergency callback mode
6809 * @param subId sub id
6810 */
goneil9c5f4872017-12-05 14:07:56 -08006811 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006812 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006813 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006814 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006815
6816 final long identity = Binder.clearCallingIdentity();
6817 try {
6818 if (phone != null) {
6819 return phone.isInEcm();
6820 } else {
6821 return false;
6822 }
6823 } finally {
6824 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006825 }
6826 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006827
6828 /**
6829 * Get the current signal strength information for the given subscription.
6830 * Because this information is not updated when the device is in a low power state
6831 * it should not be relied-upon to be current.
6832 * @param subId Subscription index
6833 * @return the most recent cached signal strength info from the modem
6834 */
6835 @Override
6836 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006837 final long identity = Binder.clearCallingIdentity();
6838 try {
6839 Phone p = getPhone(subId);
6840 if (p == null) {
6841 return null;
6842 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006843
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006844 return p.getSignalStrength();
6845 } finally {
6846 Binder.restoreCallingIdentity(identity);
6847 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006848 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006849
Pengquan Meng77b7f132018-08-22 14:49:57 -07006850 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006851 * Get the current modem radio state for the given slot.
6852 * @param slotIndex slot index.
6853 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006854 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00006855 * @return the current radio power state from the modem
6856 */
6857 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006858 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00006859 Phone phone = PhoneFactory.getPhone(slotIndex);
6860 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006861 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
6862 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00006863 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6864 }
6865
6866 final long identity = Binder.clearCallingIdentity();
6867 try {
6868 return phone.getRadioPowerState();
6869 } finally {
6870 Binder.restoreCallingIdentity(identity);
6871 }
6872 }
6873 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6874 }
6875
6876 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006877 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6878 *
6879 * <p>Requires one of the following permissions:
6880 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6881 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6882 * privileges.
6883 *
6884 * @param subId subscription id
6885 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6886 * {@code false}.
6887 */
6888 @Override
6889 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006890 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6891 null /* message */);
6892
Pengquan Menga1bb6272018-09-06 09:59:22 -07006893 boolean isEnabled = false;
6894 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006895 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006896 Phone phone = getPhone(subId);
6897 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006898 } catch (Exception e) {
6899 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6900 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006901 } finally {
6902 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006903 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006904 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006905 }
6906
6907
6908 /**
6909 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6910 *
6911 * <p> Requires permission:
6912 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6913 * privileges.
6914 *
6915 * @param subId subscription id
6916 * @param isEnabled {@code true} means enable, {@code false} means disable.
6917 */
6918 @Override
6919 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006920 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6921 mApp, subId, "setDataRoamingEnabled");
6922
Pengquan Menga1bb6272018-09-06 09:59:22 -07006923 final long identity = Binder.clearCallingIdentity();
6924 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006925 Phone phone = getPhone(subId);
6926 if (phone != null) {
6927 phone.setDataRoamingEnabled(isEnabled);
6928 }
6929 } finally {
6930 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006931 }
6932 }
6933
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006934 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006935 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08006936 TelephonyPermissions
6937 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07006938 mApp, subId, "isManualNetworkSelectionAllowed");
6939
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006940 boolean isAllowed = true;
6941 final long identity = Binder.clearCallingIdentity();
6942 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006943 Phone phone = getPhone(subId);
6944 if (phone != null) {
6945 isAllowed = phone.isCspPlmnEnabled();
6946 }
6947 } finally {
6948 Binder.restoreCallingIdentity(identity);
6949 }
6950 return isAllowed;
6951 }
6952
6953 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006954 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006955 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006956 try {
6957 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006958 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006959 } catch (SecurityException e) {
6960 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6961 // has carrier privileges on an active UICC
6962 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6963 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006964 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006965 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006966 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006967
6968 final long identity = Binder.clearCallingIdentity();
6969 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006970 UiccController uiccController = UiccController.getInstance();
6971 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006972 if (hasReadPermission) {
6973 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006974 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006975
6976 // Remove private info if the caller doesn't have access
6977 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6978 for (UiccCardInfo cardInfo : cardInfos) {
6979 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6980 // is available
6981 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6982 if (card == null || card.getUiccProfile() == null) {
6983 // assume no access if the card or profile is unavailable
6984 filteredInfos.add(cardInfo.getUnprivileged());
6985 continue;
6986 }
6987 UiccProfile profile = card.getUiccProfile();
6988 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6989 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6990 filteredInfos.add(cardInfo);
6991 } else {
6992 filteredInfos.add(cardInfo.getUnprivileged());
6993 }
6994 }
6995 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006996 } finally {
6997 Binder.restoreCallingIdentity(identity);
6998 }
6999 }
7000
7001 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007002 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007003 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007004
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007005 final long identity = Binder.clearCallingIdentity();
7006 try {
7007 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7008 if (slots == null) {
7009 Rlog.i(LOG_TAG, "slots is null.");
7010 return null;
7011 }
7012
7013 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7014 for (int i = 0; i < slots.length; i++) {
7015 UiccSlot slot = slots[i];
7016 if (slot == null) {
7017 continue;
7018 }
7019
Jordan Liu7be7e652019-05-06 18:55:02 +00007020 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007021 UiccCard card = slot.getUiccCard();
7022 if (card != null) {
7023 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007024 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007025 cardId = slot.getEid();
7026 if (TextUtils.isEmpty(cardId)) {
7027 cardId = slot.getIccId();
7028 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007029 }
7030
Jordan Liu857451f2019-05-09 16:35:35 -07007031 if (cardId != null) {
7032 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7033 // if cardId is an EID, it's all digits so this is fine
7034 cardId = IccUtils.stripTrailingFs(cardId);
7035 }
7036
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007037 int cardState = 0;
7038 switch (slot.getCardState()) {
7039 case CARDSTATE_ABSENT:
7040 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7041 break;
7042 case CARDSTATE_PRESENT:
7043 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7044 break;
7045 case CARDSTATE_ERROR:
7046 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7047 break;
7048 case CARDSTATE_RESTRICTED:
7049 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7050 break;
7051 default:
7052 break;
7053
7054 }
7055
7056 infos[i] = new UiccSlotInfo(
7057 slot.isActive(),
7058 slot.isEuicc(),
7059 cardId,
7060 cardState,
7061 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007062 slot.isExtendedApduSupported(),
7063 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007064 }
7065 return infos;
7066 } finally {
7067 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007068 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007069 }
7070
7071 @Override
7072 public boolean switchSlots(int[] physicalSlots) {
7073 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007074
7075 final long identity = Binder.clearCallingIdentity();
7076 try {
7077 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7078 } finally {
7079 Binder.restoreCallingIdentity(identity);
7080 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007081 }
Jack Yu4c988042018-02-27 15:30:01 -08007082
7083 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007084 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007085 final long identity = Binder.clearCallingIdentity();
7086 try {
7087 return UiccController.getInstance().getCardIdForDefaultEuicc();
7088 } finally {
7089 Binder.restoreCallingIdentity(identity);
7090 }
7091 }
7092
7093 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007094 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7095 enforceModifyPermission();
7096 final Phone phone = getPhone(subId);
7097 if (phone == null) {
7098 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7099 return;
7100 }
7101
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007102 final long identity = Binder.clearCallingIdentity();
7103 try {
7104 phone.setRadioIndicationUpdateMode(filters, mode);
7105 } finally {
7106 Binder.restoreCallingIdentity(identity);
7107 }
Jack Yu4c988042018-02-27 15:30:01 -08007108 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007109
7110 /**
goneil47ffb6e2018-04-06 15:40:58 -07007111 * A test API to reload the UICC profile.
7112 *
7113 * <p>Requires that the calling app has permission
7114 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7115 * @hide
7116 */
7117 @Override
7118 public void refreshUiccProfile(int subId) {
7119 enforceModifyPermission();
7120
7121 final long identity = Binder.clearCallingIdentity();
7122 try {
7123 Phone phone = getPhone(subId);
7124 if (phone == null) {
7125 return;
7126 }
7127 UiccCard uiccCard = phone.getUiccCard();
7128 if (uiccCard == null) {
7129 return;
7130 }
7131 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7132 if (uiccProfile == null) {
7133 return;
7134 }
7135 uiccProfile.refresh();
7136 } finally {
7137 Binder.restoreCallingIdentity(identity);
7138 }
7139 }
7140
7141 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007142 * Returns false if the mobile data is disabled by default, otherwise return true.
7143 */
7144 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007145 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007146 }
7147
7148 /**
7149 * Returns true if the data roaming is enabled by default, i.e the system property
7150 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7151 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7152 */
7153 private boolean getDefaultDataRoamingEnabled(int subId) {
7154 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007155 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007156 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007157 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7158 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7159 return isDataRoamingEnabled;
7160 }
7161
7162 /**
7163 * Returns the default network type for the given {@code subId}, if the default network type is
7164 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7165 */
7166 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007167 List<Integer> list = TelephonyProperties.default_network();
7168 int phoneId = mSubscriptionController.getPhoneId(subId);
7169 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7170 return list.get(phoneId);
7171 }
7172 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007173 }
fionaxua13278b2018-03-21 00:08:13 -07007174
7175 @Override
7176 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007177 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007178 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007179
7180 final long identity = Binder.clearCallingIdentity();
7181 try {
7182 final Phone phone = getPhone(subId);
7183 if (phone == null) {
7184 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7185 return;
7186 }
chen xueaba88a2019-03-15 13:15:10 -07007187 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7188 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007189 } finally {
7190 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007191 }
fionaxua13278b2018-03-21 00:08:13 -07007192 }
7193
7194 @Override
7195 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007196 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007197
7198 final long identity = Binder.clearCallingIdentity();
7199 try {
7200 final Phone phone = getPhone(subId);
7201 if (phone == null) {
7202 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7203 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7204 }
7205 return phone.getCarrierIdListVersion();
7206 } finally {
7207 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007208 }
fionaxua13278b2018-03-21 00:08:13 -07007209 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007210
7211 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007212 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7213 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007214 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007215 mApp, subId, callingPackage, callingFeatureId,
7216 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007217 return -1;
7218 }
7219
7220 final long identity = Binder.clearCallingIdentity();
7221 try {
7222 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7223 } finally {
7224 Binder.restoreCallingIdentity(identity);
7225 }
7226 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007227
7228 @Override
7229 public int getCdmaRoamingMode(int subId) {
7230 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7231 mApp, subId, "getCdmaRoamingMode");
7232
7233 final long identity = Binder.clearCallingIdentity();
7234 try {
7235 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7236 } finally {
7237 Binder.restoreCallingIdentity(identity);
7238 }
7239 }
7240
7241 @Override
7242 public boolean setCdmaRoamingMode(int subId, int mode) {
7243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7244 mApp, subId, "setCdmaRoamingMode");
7245
7246 final long identity = Binder.clearCallingIdentity();
7247 try {
7248 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7249 } finally {
7250 Binder.restoreCallingIdentity(identity);
7251 }
7252 }
7253
7254 @Override
7255 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7256 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7257 mApp, subId, "setCdmaSubscriptionMode");
7258
7259 final long identity = Binder.clearCallingIdentity();
7260 try {
7261 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7262 } finally {
7263 Binder.restoreCallingIdentity(identity);
7264 }
7265 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007266
sqianc5eccab2018-10-19 18:46:41 -07007267 @Override
sqian8c685422019-02-22 15:55:18 -08007268 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007269 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007270 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007271 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7272 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007273 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7274 }
7275 final long identity = Binder.clearCallingIdentity();
7276 try {
sqian854d44b2018-12-12 16:48:18 -08007277 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7278 for (Phone phone: PhoneFactory.getPhones()) {
7279 if (phone.getEmergencyNumberTracker() != null
7280 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7281 emergencyNumberListInternal.put(
7282 phone.getSubId(),
7283 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7284 }
sqian11b7a0e2018-12-05 18:48:28 -08007285 }
sqian854d44b2018-12-12 16:48:18 -08007286 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007287 } finally {
7288 Binder.restoreCallingIdentity(identity);
7289 }
sqianc5eccab2018-10-19 18:46:41 -07007290 }
7291
7292 @Override
sqian8c685422019-02-22 15:55:18 -08007293 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007294 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007295 if (!exactMatch) {
7296 TelephonyPermissions
7297 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007298 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007299 }
7300 final long identity = Binder.clearCallingIdentity();
7301 try {
sqian854d44b2018-12-12 16:48:18 -08007302 for (Phone phone: PhoneFactory.getPhones()) {
7303 if (phone.getEmergencyNumberTracker() != null
7304 && phone.getEmergencyNumberTracker() != null) {
7305 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7306 number, exactMatch)) {
7307 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007308 }
7309 }
sqian11b7a0e2018-12-05 18:48:28 -08007310 }
7311 return false;
7312 } finally {
7313 Binder.restoreCallingIdentity(identity);
7314 }
7315 }
7316
sqianf4ca7ed2019-01-15 18:32:07 -08007317 /**
7318 * Update emergency number list for test mode.
7319 */
7320 @Override
7321 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7322 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7323 "updateEmergencyNumberListTestMode");
7324
7325 final long identity = Binder.clearCallingIdentity();
7326 try {
7327 for (Phone phone: PhoneFactory.getPhones()) {
7328 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7329 if (tracker != null) {
7330 tracker.executeEmergencyNumberTestModeCommand(action, num);
7331 }
7332 }
7333 } finally {
7334 Binder.restoreCallingIdentity(identity);
7335 }
7336 }
7337
7338 /**
7339 * Get the full emergency number list for test mode.
7340 */
7341 @Override
7342 public List<String> getEmergencyNumberListTestMode() {
7343 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7344 "getEmergencyNumberListTestMode");
7345
7346 final long identity = Binder.clearCallingIdentity();
7347 try {
7348 Set<String> emergencyNumbers = new HashSet<>();
7349 for (Phone phone: PhoneFactory.getPhones()) {
7350 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7351 if (tracker != null) {
7352 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7353 emergencyNumbers.add(num.getNumber());
7354 }
7355 }
7356 }
7357 return new ArrayList<>(emergencyNumbers);
7358 } finally {
7359 Binder.restoreCallingIdentity(identity);
7360 }
7361 }
7362
chen xud6b45bd2018-10-30 22:27:10 -07007363 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007364 public int getEmergencyNumberDbVersion(int subId) {
7365 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7366
7367 final long identity = Binder.clearCallingIdentity();
7368 try {
7369 final Phone phone = getPhone(subId);
7370 if (phone == null) {
7371 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7372 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7373 }
7374 return phone.getEmergencyNumberDbVersion();
7375 } finally {
7376 Binder.restoreCallingIdentity(identity);
7377 }
7378 }
7379
7380 @Override
7381 public void notifyOtaEmergencyNumberDbInstalled() {
7382 enforceModifyPermission();
7383
7384 final long identity = Binder.clearCallingIdentity();
7385 try {
7386 for (Phone phone: PhoneFactory.getPhones()) {
7387 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7388 if (tracker != null) {
7389 tracker.updateOtaEmergencyNumberDatabase();
7390 }
7391 }
7392 } finally {
7393 Binder.restoreCallingIdentity(identity);
7394 }
7395 }
7396
7397 @Override
7398 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7399 enforceActiveEmergencySessionPermission();
7400
7401 final long identity = Binder.clearCallingIdentity();
7402 try {
7403 for (Phone phone: PhoneFactory.getPhones()) {
7404 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7405 if (tracker != null) {
7406 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7407 }
7408 }
7409 } finally {
7410 Binder.restoreCallingIdentity(identity);
7411 }
7412 }
7413
7414 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007415 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7416 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7417 Phone phone = getPhone(subId);
7418 if (phone == null) {
7419 return null;
7420 }
7421 final long identity = Binder.clearCallingIdentity();
7422 try {
7423 UiccProfile profile = UiccController.getInstance()
7424 .getUiccProfileForPhone(phone.getPhoneId());
7425 if (profile != null) {
7426 return profile.getCertsFromCarrierPrivilegeAccessRules();
7427 }
7428 } finally {
7429 Binder.restoreCallingIdentity(identity);
7430 }
7431 return null;
7432 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007433
7434 /**
7435 * Enable or disable a modem stack.
7436 */
7437 @Override
7438 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7439 enforceModifyPermission();
7440
7441 final long identity = Binder.clearCallingIdentity();
7442 try {
7443 Phone phone = PhoneFactory.getPhone(slotIndex);
7444 if (phone == null) {
7445 return false;
7446 } else {
7447 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7448 }
7449 } finally {
7450 Binder.restoreCallingIdentity(identity);
7451 }
7452 }
Michelecea4cf22018-12-21 15:00:11 -08007453
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007454 /**
7455 * Whether a modem stack is enabled or not.
7456 */
7457 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007458 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7459 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007460 Phone phone = PhoneFactory.getPhone(slotIndex);
7461 if (phone == null) return false;
7462
7463 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007464 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7465 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007466 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7467 }
7468
7469 final long identity = Binder.clearCallingIdentity();
7470 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007471 try {
7472 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7473 } catch (NoSuchElementException ex) {
7474 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7475 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007476 } finally {
7477 Binder.restoreCallingIdentity(identity);
7478 }
7479 }
7480
Michelecea4cf22018-12-21 15:00:11 -08007481 @Override
Michele0ea7d782019-03-19 14:58:42 -07007482 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007483 enforceModifyPermission();
7484
7485 final long identity = Binder.clearCallingIdentity();
7486 try {
7487 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007488 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007489 .commit();
7490 } finally {
7491 Binder.restoreCallingIdentity(identity);
7492 }
7493 }
7494
7495 @Override
Michele0ea7d782019-03-19 14:58:42 -07007496 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007497 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007498 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007499 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7500 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007501 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007502 }
Michelecea4cf22018-12-21 15:00:11 -08007503
7504 final long identity = Binder.clearCallingIdentity();
7505 try {
Michele0ea7d782019-03-19 14:58:42 -07007506 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007507 } finally {
7508 Binder.restoreCallingIdentity(identity);
7509 }
7510 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007511
Michele0ea7d782019-03-19 14:58:42 -07007512 @TelephonyManager.IsMultiSimSupportedResult
7513 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007514 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7515 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7516 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007517 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7518 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007519 }
7520 // Check if the hardware supports multisim functionality. If usage of multisim is not
7521 // supported by the modem, indicate that it is restricted.
7522 PhoneCapability staticCapability =
7523 mPhoneConfigurationManager.getStaticPhoneCapability();
7524 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007525 loge("isMultiSimSupportedInternal: no static configuration available");
7526 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007527 }
7528 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007529 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7530 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007531 }
7532 // Check if support of multiple SIMs is restricted by carrier
7533 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007534 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007535 }
7536
Michele0ea7d782019-03-19 14:58:42 -07007537 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007538 }
7539
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007540 /**
7541 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007542 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7543 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7544 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007545 * @param numOfSims number of active sims we want to switch to
7546 */
7547 @Override
7548 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007549 if (numOfSims == 1) {
7550 enforceModifyPermission();
7551 } else {
7552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7553 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7554 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007555 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007556
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007557 try {
Michele30b57b22019-03-01 12:01:14 -08007558 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007559 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007560 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7561 return;
7562 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007563 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7564 } finally {
7565 Binder.restoreCallingIdentity(identity);
7566 }
7567 }
7568
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007569 @Override
7570 public boolean isApplicationOnUicc(int subId, int appType) {
7571 enforceReadPrivilegedPermission("isApplicationOnUicc");
7572 Phone phone = getPhone(subId);
7573 if (phone == null) {
7574 return false;
7575 }
7576 final long identity = Binder.clearCallingIdentity();
7577 try {
7578 UiccCard uiccCard = phone.getUiccCard();
7579 if (uiccCard == null) {
7580 return false;
7581 }
7582 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7583 if (uiccProfile == null) {
7584 return false;
7585 }
7586 if (TelephonyManager.APPTYPE_SIM <= appType
7587 && appType <= TelephonyManager.APPTYPE_ISIM) {
7588 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7589 }
7590 return false;
7591 } finally {
7592 Binder.restoreCallingIdentity(identity);
7593 }
7594 }
7595
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007596 /**
chen xub4baa772019-04-03 10:23:41 -07007597 * Get whether making changes to modem configurations will trigger reboot.
7598 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007599 */
7600 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007601 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7602 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007603 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007604 mApp, subId, callingPackage, callingFeatureId,
7605 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007606 return false;
7607 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007608 final long identity = Binder.clearCallingIdentity();
7609 try {
7610 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7611 } finally {
7612 Binder.restoreCallingIdentity(identity);
7613 }
7614 }
7615
Nathan Harold29f5f052019-02-15 13:41:57 -08007616 private void updateModemStateMetrics() {
7617 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7618 // TODO: check the state for each modem if the api is ready.
7619 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7620 }
7621
Pengquan Meng3889a572019-01-23 11:16:29 -08007622 @Override
7623 public int[] getSlotsMapping() {
7624 enforceReadPrivilegedPermission("getSlotsMapping");
7625
7626 final long identity = Binder.clearCallingIdentity();
7627 try {
7628 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7629 // All logical slots should have a mapping to a physical slot.
7630 int[] logicalSlotsMapping = new int[phoneCount];
7631 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7632 for (int i = 0; i < slotInfos.length; i++) {
7633 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7634 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7635 }
7636 }
7637 return logicalSlotsMapping;
7638 } finally {
7639 Binder.restoreCallingIdentity(identity);
7640 }
7641 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007642
7643 /**
7644 * Get the IRadio HAL Version
7645 */
7646 @Override
7647 public int getRadioHalVersion() {
7648 Phone phone = getDefaultPhone();
7649 if (phone == null) return -1;
7650 HalVersion hv = phone.getHalVersion();
7651 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7652 return hv.major * 100 + hv.minor;
7653 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007654
7655 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007656 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7657 * corresponding network requests on a subId.
7658 *
7659 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007660 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007661 * 2) APN is un-metered for this subscription, or
7662 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7663 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7664 *
7665 * @return whether data is allowed for a apn type.
7666 *
7667 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007668 */
7669 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007670 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07007671 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7672 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007673
7674 // Now that all security checks passes, perform the operation as ourselves.
7675 final long identity = Binder.clearCallingIdentity();
7676 try {
7677 Phone phone = getPhone(subId);
7678 if (phone == null) return false;
7679
Jack Yu41407ee2019-05-13 16:54:09 -07007680 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007681 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7682 } finally {
7683 Binder.restoreCallingIdentity(identity);
7684 }
7685 }
7686
7687 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007688 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007689 enforceReadPrivilegedPermission("isApnMetered");
7690
7691 // Now that all security checks passes, perform the operation as ourselves.
7692 final long identity = Binder.clearCallingIdentity();
7693 try {
7694 Phone phone = getPhone(subId);
7695 if (phone == null) return true; // By default return true.
7696
Jack Yu41407ee2019-05-13 16:54:09 -07007697 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007698 } finally {
7699 Binder.restoreCallingIdentity(identity);
7700 }
7701 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007702
7703 @Override
changbetty363e8ac2019-12-06 18:16:37 +08007704 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
7705 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
7706 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
7707 if (iccRecords == null) {
7708 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
7709 return false;
7710 }
7711 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
7712 }
7713
7714 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07007715 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7716 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7717 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7718 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7719 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7720 }
7721 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7722 Intent intent = new Intent();
7723 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7724 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7725 // Bring up choose default SMS subscription dialog right now
7726 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7727 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7728 mApp.startActivity(intent);
7729 }
chen xud5ca2d52019-05-28 15:20:57 -07007730
7731 @Override
7732 public String getMmsUAProfUrl(int subId) {
7733 //TODO investigate if this API should require proper permission check in R b/133791609
7734 final long identity = Binder.clearCallingIdentity();
7735 try {
7736 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7737 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7738 } finally {
7739 Binder.restoreCallingIdentity(identity);
7740 }
7741 }
7742
7743 @Override
7744 public String getMmsUserAgent(int subId) {
7745 //TODO investigate if this API should require proper permission check in R b/133791609
7746 final long identity = Binder.clearCallingIdentity();
7747 try {
7748 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7749 .getString(com.android.internal.R.string.config_mms_user_agent);
7750 } finally {
7751 Binder.restoreCallingIdentity(identity);
7752 }
7753 }
Jack Yub07d4972019-05-28 16:12:25 -07007754
7755 @Override
7756 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7757 enforceModifyPermission();
7758
7759 // Now that all security checks passes, perform the operation as ourselves.
7760 final long identity = Binder.clearCallingIdentity();
7761 try {
7762 Phone phone = getPhone(subId);
7763 if (phone == null) return false;
7764
7765 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7766 } finally {
7767 Binder.restoreCallingIdentity(identity);
7768 }
7769 }
7770
7771 @Override
7772 public boolean isDataAllowedInVoiceCall(int subId) {
7773 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7774
7775 // Now that all security checks passes, perform the operation as ourselves.
7776 final long identity = Binder.clearCallingIdentity();
7777 try {
7778 Phone phone = getPhone(subId);
7779 if (phone == null) return false;
7780
7781 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7782 } finally {
7783 Binder.restoreCallingIdentity(identity);
7784 }
7785 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007786
7787 /**
7788 * Updates whether conference event pacakge handling is enabled.
7789 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7790 * otherwise.
7791 */
7792 @Override
7793 public void setCepEnabled(boolean isCepEnabled) {
7794 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7795
7796 final long identity = Binder.clearCallingIdentity();
7797 try {
7798 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7799 for (Phone phone : PhoneFactory.getPhones()) {
7800 Phone defaultPhone = phone.getImsPhone();
7801 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7802 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7803 ImsPhoneCallTracker imsPhoneCallTracker =
7804 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7805 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7806 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7807 + imsPhone.getMsisdn());
7808 }
7809 }
7810 } finally {
7811 Binder.restoreCallingIdentity(identity);
7812 }
7813 }
allenwtsu46dcc572020-01-08 18:24:03 +08007814
7815 /**
7816 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
7817 *
7818 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
7819 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
7820 * before being read.
7821 */
7822 @Override
7823 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
7824 isCompressed) {
7825 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7826 mApp, subId, "notifyRcsAutoConfigurationReceived");
7827 try {
7828 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
7829 if (configBinder == null) {
7830 Rlog.e(LOG_TAG, "null result for getImsConfig");
7831 } else {
7832 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
7833 }
7834 } catch (RemoteException e) {
7835 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
7836 }
7837 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007838}